MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / TestGenerateDefaultOperationID

Function TestGenerateDefaultOperationID

pkg/codegen/operations_test.go:89–149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

87}
88
89func TestGenerateDefaultOperationID(t *testing.T) {
90 type test struct {
91 op string
92 path string
93 want string
94 wantErr bool
95 }
96
97 suite := []test{
98 {
99 op: http.MethodGet,
100 path: "/v1/foo/bar",
101 want: "GetV1FooBar",
102 wantErr: false,
103 },
104 {
105 op: http.MethodGet,
106 path: "/v1/foo/bar/",
107 want: "GetV1FooBar",
108 wantErr: false,
109 },
110 {
111 op: http.MethodPost,
112 path: "/v1",
113 want: "PostV1",
114 wantErr: false,
115 },
116 {
117 op: http.MethodPost,
118 path: "v1",
119 want: "PostV1",
120 wantErr: false,
121 },
122 {
123 path: "v1",
124 want: "",
125 wantErr: true,
126 },
127 {
128 path: "",
129 want: "PostV1",
130 wantErr: true,
131 },
132 }
133
134 for _, test := range suite {
135 got, err := generateDefaultOperationID(test.op, test.path)
136 if err != nil {
137 if !test.wantErr {
138 t.Fatalf("did not expected error but got %v", err)
139 }
140 }
141
142 if test.wantErr {
143 return
144 }
145 if got != test.want {
146 t.Fatalf("Operation ID generation error. Want [%v] Got [%v]", test.want, got)

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected