github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/internal/testEnv/pb/msg/msg_test.go (about) 1 package testmsg_test 2 3 import ( 4 "testing" 5 6 testmsg "github.com/ronaksoft/rony/internal/testEnv/pb/msg" 7 . "github.com/smartystreets/goconvey/convey" 8 ) 9 10 func TestMsg(t *testing.T) { 11 Convey("Marshal/Unmarshal JSON", t, func(c C) { 12 Convey("NormalEnvelope", func(c C) { 13 e1 := &testmsg.Envelope1{ 14 E1: "E1Value", 15 Embed1: &testmsg.Embed1{ 16 F1: "Embed1F1Value", 17 }, 18 } 19 jsonData, err := e1.MarshalJSON() 20 c.So(err, ShouldBeNil) 21 c.Println(string(jsonData)) 22 }) 23 Convey("RonyEnvelope", func(c C) { 24 e1 := &testmsg.Envelope1{ 25 E1: "E1Value", 26 Embed1: &testmsg.Embed1{ 27 F1: "Embed1F1Value", 28 }, 29 } 30 e1Bytes, err := e1.Marshal() 31 c.So(err, ShouldBeNil) 32 e2 := &testmsg.Envelope2{ 33 Constructor: testmsg.C_Envelope1, 34 Message: e1Bytes, 35 } 36 37 jsonData, err := e2.MarshalJSON() 38 c.So(err, ShouldBeNil) 39 c.Println(string(jsonData)) 40 41 e22 := &testmsg.Envelope2{} 42 err = e22.UnmarshalJSON(jsonData) 43 c.So(err, ShouldBeNil) 44 c.So(e22.Constructor, ShouldEqual, e2.Constructor) 45 c.So(e22.Message, ShouldResemble, e2.Message) 46 }) 47 }) 48 }