gitlab.com/evatix-go/core@v1.3.55/tests/integratedtests/coredynamictests/ReflectSetFromTo_ValidCases_test.go (about) 1 package coredynamictests 2 3 import ( 4 "testing" 5 6 . "github.com/smartystreets/goconvey/convey" 7 "gitlab.com/evatix-go/core/coredata/coredynamic" 8 "gitlab.com/evatix-go/core/coretests" 9 "gitlab.com/evatix-go/core/tests/testwrappers/coredynamictestwrappers" 10 ) 11 12 // Test_ReflectSetFromTo_ValidCases 13 // 14 // Valid Inputs: 15 // - From, To: (null, null) -- do nothing 16 // - From, To: (sameTypePointer, sameTypePointer) -- try reflection 17 // - From, To: (sameTypeNonPointer, sameTypePointer) -- try reflection 18 // - From, To: ([]byte or *[]byte, otherType) -- try unmarshal, reflect 19 // - From, To: (otherType, *[]byte) -- try marshal, reflect 20 func Test_ReflectSetFromTo_ValidCases(t *testing.T) { 21 for _, testCase := range coredynamictestwrappers.ReflectSetFromToValidTestCases { 22 // Act 23 err := coredynamic.ReflectSetFromTo( 24 testCase.From, 25 testCase.To) 26 27 typeStatus := coredynamic.TypeSameStatus( 28 testCase.To, 29 testCase.ExpectedValue) 30 testCase.SetActual(testCase.To) 31 32 // Assert 33 Convey(testCase.CaseTitle(), t, func() { 34 So(err, ShouldBeNil) 35 typeStatus.MustBeSame() 36 switch convertedFrom := testCase.From.(type) { 37 case *coretests.DraftType: 38 toField := testCase.ToFieldToDraftType() 39 expectedField := testCase.ExpectedFieldToDraftType() 40 toFieldEqualErr := toField. 41 VerifyNotEqualExcludingInnerFieldsErr( 42 expectedField) 43 fromFieldEqualErr := convertedFrom. 44 VerifyNotEqualExcludingInnerFieldsErr(expectedField) 45 46 So(toFieldEqualErr, ShouldBeNil) 47 So(fromFieldEqualErr, ShouldBeNil) 48 49 case coretests.DraftType: 50 toField := testCase.ToFieldToDraftType() 51 expectedField := testCase.ExpectedFieldToDraftType() 52 toFieldEqualErr := toField. 53 VerifyNotEqualExcludingInnerFieldsErr( 54 expectedField) 55 fromFieldEqualErr := convertedFrom. 56 VerifyNotEqualExcludingInnerFieldsErr(expectedField) 57 58 So(toFieldEqualErr, ShouldBeNil) 59 So(fromFieldEqualErr, ShouldBeNil) 60 61 case []byte, *[]byte: 62 // expecting unmarshalling to type 63 // From, To: ([]byte or *[]byte, otherType) -- try unmarshal, reflect 64 // To, Expected should be same 65 toField := testCase.ToFieldToDraftType() 66 toFieldEqualErr := toField. 67 VerifyNotEqualExcludingInnerFieldsErr( 68 testCase.ExpectedFieldToDraftType()) 69 So(toFieldEqualErr, ShouldBeNil) 70 } 71 }) 72 } 73 }