Skip to content

Instantly share code, notes, and snippets.

@jen20
Created February 5, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jen20/bc90fd7642bb02abc900 to your computer and use it in GitHub Desktop.
Save jen20/bc90fd7642bb02abc900 to your computer and use it in GitHub Desktop.
Example using Seq for partial object equality.
// $ go run main.go
// Differences:
// Expected 'PointerToNumber' to be '5' but got '4'
// Expected 'Endpoint.Blob' to be 'Test24343' but got 'Test1'
// Expected 'String' to be 'John Smith' but got 'John'
package main
import (
"fmt"
"github.com/abdullin/seq"
)
type Thing struct {
Number int
PointerToNumber *int
String string
Endpoint struct {
Blob string
Queue string
}
}
func Int(val int) *int {
return &val
}
func main() {
actual := &Thing{
Number: 3,
PointerToNumber: Int(4),
String: "John",
Endpoint: struct {
Blob string
Queue string
}{
Blob: "Test1",
Queue: "Test2",
},
}
expect := seq.Map{
"Number": 3,
"PointerToNumber": 5,
"String": "John Smith",
"Endpoint.Blob": "Test24343",
}
result := expect.Test(actual)
if !result.Ok() {
fmt.Println("Differences:")
for _, v := range result.Issues {
fmt.Println(v.String())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment