github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/desc/util_test.go (about)

     1  package desc_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"reflect"
     6  
     7  	"github.com/clubpay/ronykit/kit/desc"
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  type customStruct struct {
    13  	Param1      string          `json:"param1"`
    14  	Param2      int64           `json:"param2"`
    15  	Obj1        customSubStruct `json:"obj1"`
    16  	Obj2        customInterface `json:"obj2"`
    17  	PtrParam3   *string         `json:"ptrParam3"`
    18  	PtrSubParam *customStruct   `json:"prtSubParam"`
    19  	RawJSON     json.RawMessage `json:"rawJSON"`
    20  }
    21  
    22  type customSubStruct struct {
    23  	SubParam1   string                      `json:"subParam1"`
    24  	SubParam2   int                         `json:"subParam2"`
    25  	MapParam    map[string]anotherSubStruct `json:"mapParam"`
    26  	MapPtrParam map[int]*anotherSubStruct   `json:"mapPtr"`
    27  }
    28  
    29  type anotherSubStruct struct {
    30  	Keys       []string         `json:"keys"`
    31  	Values     map[int64]string `json:"values"`
    32  	Interfaces map[string]any   `json:"interfaces"`
    33  }
    34  
    35  type customInterface interface {
    36  	Method1() string
    37  	Method2() customStruct
    38  }
    39  
    40  var _ = Describe("Check Type", func() {
    41  	It("should detect types correctly", func() {
    42  		Expect(desc.TypeOf("", reflect.TypeOf(customStruct{}))).To(Equal("customStruct"))
    43  		Expect(desc.TypeOf("", reflect.TypeOf(new(customInterface)))).To(Equal("*customInterface"))
    44  		Expect(desc.TypeOf("", reflect.TypeOf(int64(0)))).To(Equal("int64"))
    45  		Expect(desc.TypeOf("", reflect.TypeOf([]int64{}))).To(Equal("[]int64"))
    46  		Expect(desc.TypeOf("", reflect.TypeOf([18]int64{}))).To(Equal("[18]int64"))
    47  		Expect(desc.TypeOf("", reflect.TypeOf(map[string]*customStruct{}))).To(Equal("map[string]*customStruct"))
    48  		Expect(desc.TypeOf("", reflect.TypeOf(map[string]any{}))).To(Equal("map[string]any"))
    49  	})
    50  })