github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/cmd/pxtor/generator_test.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/stretchr/testify/assert"
     5  	"testing"
     6  )
     7  
     8  func TestFutures(t *testing.T) {
     9  	*dir = "./test"
    10  	*receiver = "test.Test"
    11  	*sourceName = "littlerpc/internal/test1"
    12  	*style = SyncStyle
    13  	*generateId = true
    14  	for i := 0; i < 100; i++ {
    15  		genCode()
    16  	}
    17  	*sourceName = "Test"
    18  	genCode()
    19  }
    20  
    21  func TestGenApi(t *testing.T) {
    22  	after, err := genSync(Argument{
    23  		Name: "p",
    24  		Type: "TestProxy",
    25  	}, "Hello", "littlerpc/test/pxtor/internal", []Argument{
    26  		{"s1", "string"}, {"d1", "int"},
    27  	}, []Argument{
    28  		{"", "string"}, {"", "error"},
    29  	})
    30  	assert.NotEqualf(t, after(), "", "result equal empty")
    31  	assert.Nil(t, err)
    32  	_, err = genAsyncApi("Hello", "littlerpc/test/pxtor/internal", "Add",
    33  		[]string{"s1", "d1"}, []string{"string", "int"}, []string{"string", "error"})
    34  	assert.Nil(t, err)
    35  }
    36  
    37  func TestCreateBeforeCode(t *testing.T) {
    38  	defer func() {
    39  		if err := recover(); err != nil {
    40  			t.Fatal(err)
    41  		}
    42  	}()
    43  	createBeforeCode("main", "Hello1", "littlerpc/internal/test1", []string{
    44  		"func(h *Hello1)Mehtod1(ctx context.Context) error",
    45  		"func(h *Hello1)Mehtod2(ctx context.Context) error",
    46  		"func(h *Hello1)Mehtod3(ctx context.Context) error",
    47  	}, nil)
    48  }