github.com/clubpay/ronykit/kit@v0.14.4-0.20240515065620-d0dace45cbc7/stub/stubgen/gen_test.go (about)

     1  package stubgen
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/clubpay/ronykit/kit/desc"
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  func TestStubCodeGenerator(t *testing.T) {
    12  	RegisterFailHandler(Fail)
    13  	RunSpecs(t, "Stub Code Generator")
    14  }
    15  
    16  var _ = Describe("GolangGenerator", func() {
    17  	It("generate dto code in golang (no comment)", func() {
    18  		_, err := GolangStub(
    19  			Input{
    20  				Stub: desc.Stub{
    21  					DTOs: map[string]desc.DTO{
    22  						"Struct1": {
    23  							Name: "Struct1",
    24  							Type: "struct",
    25  							Fields: []desc.DTOField{
    26  								{
    27  									Name: "Param1",
    28  									Type: "string",
    29  									Tags: []desc.DTOFieldTag{
    30  										{
    31  											Name:  "json",
    32  											Value: "param1",
    33  										},
    34  									},
    35  								},
    36  								{
    37  									Name: "Param2",
    38  									Type: "*int",
    39  									Tags: []desc.DTOFieldTag{
    40  										{
    41  											Name:  "json",
    42  											Value: "param2",
    43  										},
    44  									},
    45  								},
    46  							},
    47  						},
    48  					},
    49  					RESTs: nil,
    50  					RPCs:  nil,
    51  				},
    52  			},
    53  		)
    54  		Expect(err).To(BeNil())
    55  	})
    56  	It("generate dto code in golang (with comment)", func() {
    57  		_, err := GolangStub(
    58  			Input{
    59  				Stub: desc.Stub{
    60  					DTOs: map[string]desc.DTO{
    61  						"Struct1": {
    62  							Comments: []string{
    63  								"Something1",
    64  								"Something2",
    65  							},
    66  							Name: "Struct1",
    67  							Type: "struct",
    68  							Fields: []desc.DTOField{
    69  								{
    70  									Name: "Param1",
    71  									Type: "string",
    72  									Tags: []desc.DTOFieldTag{
    73  										{
    74  											Name:  "json",
    75  											Value: "param1",
    76  										},
    77  									},
    78  								},
    79  								{
    80  									Name: "Param2",
    81  									Type: "*int",
    82  									Tags: []desc.DTOFieldTag{
    83  										{
    84  											Name:  "json",
    85  											Value: "param2",
    86  										},
    87  									},
    88  								},
    89  							},
    90  						},
    91  					},
    92  					RESTs: nil,
    93  					RPCs:  nil,
    94  				},
    95  			},
    96  		)
    97  		Expect(err).To(BeNil())
    98  	})
    99  })