github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/desc/stub_test.go (about) 1 package desc_test 2 3 import ( 4 "reflect" 5 6 "github.com/clubpay/ronykit/kit/desc" 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Desc", func() { 12 It("should detect all DTOs", func() { 13 d := desc.NewStub("json") 14 15 Expect(d.AddDTO(reflect.TypeOf(&customStruct{}), false)).To(Succeed()) 16 Expect(d.DTOs).To(HaveLen(3)) 17 Expect(d.DTOs["customSubStruct"].Fields).To(HaveLen(4)) 18 Expect(d.DTOs["customSubStruct"].Fields[0].Name).To(Equal("SubParam1")) 19 Expect(d.DTOs["customSubStruct"].Fields[0].Tags).To(HaveLen(1)) 20 Expect(d.DTOs["customSubStruct"].Fields[0].IsDTO).To(BeFalse()) 21 Expect(d.DTOs["customSubStruct"].Fields[1].Name).To(Equal("SubParam2")) 22 Expect(d.DTOs["customSubStruct"].Fields[1].Tags).To(HaveLen(1)) 23 Expect(d.DTOs["customSubStruct"].Fields[1].IsDTO).To(BeFalse()) 24 Expect(d.DTOs["customSubStruct"].Fields[2].Name).To(Equal("MapParam")) 25 Expect(d.DTOs["customSubStruct"].Fields[2].SubType1).To(Equal("string")) 26 Expect(d.DTOs["customSubStruct"].Fields[2].SubType2).To(Equal("anotherSubStruct")) 27 Expect(d.DTOs["customSubStruct"].Fields[2].IsDTO).To(BeFalse()) 28 Expect(d.DTOs["customSubStruct"].Fields[2].Tags).To(HaveLen(1)) 29 Expect(d.DTOs["customSubStruct"].Fields[3].Name).To(Equal("MapPtrParam")) 30 Expect(d.DTOs["customSubStruct"].Fields[3].SubType1).To(Equal("int")) 31 Expect(d.DTOs["customSubStruct"].Fields[3].SubType2).To(Equal("*anotherSubStruct")) 32 Expect(d.DTOs["customSubStruct"].Fields[3].Tags).To(HaveLen(1)) 33 Expect(d.DTOs["customSubStruct"].Fields[3].IsDTO).To(BeFalse()) 34 35 Expect(d.DTOs["customStruct"].Fields).To(HaveLen(6)) 36 Expect(d.DTOs["customStruct"].Fields[0].Name).To(Equal("Param1")) 37 Expect(d.DTOs["customStruct"].Fields[0].Tags).To(HaveLen(1)) 38 Expect(d.DTOs["customStruct"].Fields[0].Type).To(Equal("string")) 39 Expect(d.DTOs["customStruct"].Fields[1].Name).To(Equal("Param2")) 40 Expect(d.DTOs["customStruct"].Fields[1].Tags).To(HaveLen(1)) 41 Expect(d.DTOs["customStruct"].Fields[1].Type).To(Equal("int64")) 42 Expect(d.DTOs["customStruct"].Fields[2].Name).To(Equal("Obj1")) 43 Expect(d.DTOs["customStruct"].Fields[2].Tags).To(HaveLen(1)) 44 Expect(d.DTOs["customStruct"].Fields[2].Type).To(Equal("customSubStruct")) 45 Expect(d.DTOs["customStruct"].Fields[3].Name).To(Equal("PtrParam3")) 46 Expect(d.DTOs["customStruct"].Fields[3].Tags).To(HaveLen(1)) 47 Expect(d.DTOs["customStruct"].Fields[3].Type).To(Equal("*string")) 48 Expect(d.DTOs["customStruct"].Fields[4].Name).To(Equal("PtrSubParam")) 49 Expect(d.DTOs["customStruct"].Fields[4].Tags).To(HaveLen(1)) 50 Expect(d.DTOs["customStruct"].Fields[4].Type).To(Equal("*customStruct")) 51 Expect(d.DTOs["customStruct"].Fields[5].Name).To(Equal("RawJSON")) 52 Expect(d.DTOs["customStruct"].Fields[5].Tags).To(HaveLen(1)) 53 Expect(d.DTOs["customStruct"].Fields[5].Type).To(Equal("kit.JSONMessage")) 54 }) 55 })