github.com/unionj-cloud/go-doudou@v1.3.8-0.20221011095552-0088008e5b31/cmd/internal/svc/codegen/httphandler_test.go (about) 1 package codegen 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func Test_pattern(t *testing.T) { 9 type args struct { 10 method string 11 } 12 tests := []struct { 13 name string 14 args args 15 want string 16 }{ 17 { 18 name: "1", 19 args: args{ 20 method: "GetBooks", 21 }, 22 want: "books", 23 }, 24 { 25 name: "2", 26 args: args{ 27 method: "PageUsers", 28 }, 29 want: "page/users", 30 }, 31 { 32 name: "3", 33 args: args{ 34 method: "PostSelect_Books", 35 }, 36 want: "select.books", 37 }, 38 } 39 for _, tt := range tests { 40 t.Run(tt.name, func(t *testing.T) { 41 if got := pattern(tt.args.method); got != tt.want { 42 t.Errorf("pattern() = %v, want %v", got, tt.want) 43 } 44 }) 45 } 46 } 47 48 func Test_pattern1(t *testing.T) { 49 type args struct { 50 method string 51 } 52 tests := []struct { 53 name string 54 args args 55 want string 56 }{ 57 { 58 name: "", 59 args: args{ 60 method: "GetHome_Html", 61 }, 62 want: "home.html", 63 }, 64 { 65 name: "", 66 args: args{ 67 method: "GetHome_html", 68 }, 69 want: "home.html", 70 }, 71 { 72 name: "", 73 args: args{ 74 method: "Get", 75 }, 76 want: "", 77 }, 78 } 79 for _, tt := range tests { 80 t.Run(tt.name, func(t *testing.T) { 81 assert.Equalf(t, tt.want, pattern(tt.args.method), "pattern(%v)", tt.args.method) 82 }) 83 } 84 }