1- package fosite
1+ package fosite_test
22
3- import "testing"
3+ import (
4+ "testing"
5+ "github.com/oleiade/reflections"
6+ "github.com/stretchr/testify/assert"
7+ "github.com/stretchr/testify/require"
8+ )
49
510func TestAssertObjectsAreEqualByKeys (t * testing.T ) {
611 type foo struct {
@@ -15,3 +20,46 @@ func TestAssertObjectsAreEqualByKeys(t *testing.T) {
1520 AssertObjectKeysNotEqual (t , a , b , "Name" )
1621 AssertObjectKeysNotEqual (t , a , c , "Name" , "Body" )
1722}
23+
24+ func AssertObjectKeysEqual (t * testing.T , a , b interface {}, keys ... string ) {
25+ assert .True (t , len (keys ) > 0 , "No keys provided." )
26+ for _ , k := range keys {
27+ c , err := reflections .GetField (a , k )
28+ assert .Nil (t , err )
29+ d , err := reflections .GetField (b , k )
30+ assert .Nil (t , err )
31+ assert .Equal (t , c , d , "%s" , k )
32+ }
33+ }
34+
35+ func AssertObjectKeysNotEqual (t * testing.T , a , b interface {}, keys ... string ) {
36+ assert .True (t , len (keys ) > 0 , "No keys provided." )
37+ for _ , k := range keys {
38+ c , err := reflections .GetField (a , k )
39+ assert .Nil (t , err )
40+ d , err := reflections .GetField (b , k )
41+ assert .Nil (t , err )
42+ assert .NotEqual (t , c , d , "%s" , k )
43+ }
44+ }
45+
46+ func RequireObjectKeysEqual (t * testing.T , a , b interface {}, keys ... string ) {
47+ assert .True (t , len (keys ) > 0 , "No keys provided." )
48+ for _ , k := range keys {
49+ c , err := reflections .GetField (a , k )
50+ assert .Nil (t , err )
51+ d , err := reflections .GetField (b , k )
52+ assert .Nil (t , err )
53+ require .Equal (t , c , d , "%s" , k )
54+ }
55+ }
56+ func RequireObjectKeysNotEqual (t * testing.T , a , b interface {}, keys ... string ) {
57+ assert .True (t , len (keys ) > 0 , "No keys provided." )
58+ for _ , k := range keys {
59+ c , err := reflections .GetField (a , k )
60+ assert .Nil (t , err )
61+ d , err := reflections .GetField (b , k )
62+ assert .Nil (t , err )
63+ require .NotEqual (t , c , d , "%s" , k )
64+ }
65+ }
0 commit comments