Created
February 5, 2016 13:29
-
-
Save jen20/bc90fd7642bb02abc900 to your computer and use it in GitHub Desktop.
Example using Seq for partial object equality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ 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