github.com/unionj-cloud/go-doudou@v1.3.8-0.20221011095552-0088008e5b31/cmd/internal/svc/codegen/doc_test.go (about) 1 package codegen 2 3 import ( 4 . "github.com/smartystreets/goconvey/convey" 5 "github.com/unionj-cloud/go-doudou/cmd/internal/astutils" 6 v3helper "github.com/unionj-cloud/go-doudou/cmd/internal/openapi/v3" 7 "github.com/unionj-cloud/go-doudou/toolkit/pathutils" 8 "os" 9 "path/filepath" 10 "testing" 11 ) 12 13 var testDir string 14 15 func init() { 16 testDir = pathutils.Abs("testdata") 17 } 18 19 func TestGenDoc(t *testing.T) { 20 dir := testDir + "doc1" 21 InitSvc(dir) 22 defer os.RemoveAll(dir) 23 type args struct { 24 dir string 25 ic astutils.InterfaceCollector 26 } 27 svcfile := filepath.Join(dir, "svc.go") 28 ic := astutils.BuildInterfaceCollector(svcfile, ExprStringP) 29 30 tests := []struct { 31 name string 32 args args 33 }{ 34 { 35 name: "1", 36 args: args{ 37 dir, 38 ic, 39 }, 40 }, 41 } 42 for _, tt := range tests { 43 t.Run(tt.name, func(t *testing.T) { 44 GenDoc(tt.args.dir, tt.args.ic, 1) 45 }) 46 } 47 } 48 49 func TestGenDocUploadFile(t *testing.T) { 50 type args struct { 51 dir string 52 ic astutils.InterfaceCollector 53 } 54 svcfile := filepath.Join(testDir, "svc.go") 55 ic := astutils.BuildInterfaceCollector(svcfile, ExprStringP) 56 57 tests := []struct { 58 name string 59 args args 60 }{ 61 { 62 name: "1", 63 args: args{ 64 testDir, 65 ic, 66 }, 67 }, 68 } 69 for _, tt := range tests { 70 t.Run(tt.name, func(t *testing.T) { 71 GenDoc(tt.args.dir, tt.args.ic, 1) 72 }) 73 } 74 } 75 76 func Test_schemasOf(t *testing.T) { 77 type args struct { 78 vofile string 79 } 80 tests := []struct { 81 name string 82 args args 83 want int 84 }{ 85 { 86 name: "", 87 args: args{ 88 vofile: pathutils.Abs("testdata") + "/vo/vo.go", 89 }, 90 want: 6, 91 }, 92 { 93 name: "", 94 args: args{ 95 vofile: pathutils.Abs("testdata") + "/vo/vo1.go", 96 }, 97 want: 2, 98 }, 99 } 100 for _, tt := range tests { 101 t.Run(tt.name, func(t *testing.T) { 102 v3helper.SchemaNames = getSchemaNames(tt.args.vofile) 103 if got := schemasOf(tt.args.vofile); len(got) != tt.want { 104 t.Errorf("schemasOf() = %v, want %v", len(got), tt.want) 105 } 106 }) 107 } 108 } 109 110 func TestParseVo(t *testing.T) { 111 Convey("Test ParseVo", t, func() { 112 So(func() { 113 ParseVo(testDir) 114 }, ShouldNotPanic) 115 So(len(v3helper.Schemas), ShouldNotBeZeroValue) 116 }) 117 }