MCPcopy Create free account
hub / github.com/goadesign/goa / TestServerInterceptor

Function TestServerInterceptor

dsl/interceptor_test.go:164–228  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestServerInterceptor(t *testing.T) {
165 cases := map[string]struct {
166 DSL func()
167 Assert func(*testing.T, *expr.ServiceExpr, error)
168 }{
169 "valid-reference": {
170 func() {
171 var testInterceptor = Interceptor("test", func() {})
172 Service("Service", func() {
173 ServerInterceptor(testInterceptor)
174 })
175 },
176 func(t *testing.T, svc *expr.ServiceExpr, err error) {
177 require.NoError(t, err)
178 require.NotNil(t, svc)
179 require.Len(t, svc.ServerInterceptors, 1, "should have 1 server interceptor")
180 assert.Equal(t, "test", svc.ServerInterceptors[0].Name)
181 },
182 },
183 "valid-by-name": {
184 func() {
185 Interceptor("test", func() {})
186 Service("Service", func() {
187 ServerInterceptor("test")
188 })
189 },
190 func(t *testing.T, svc *expr.ServiceExpr, err error) {
191 require.NoError(t, err)
192 require.NotNil(t, svc)
193 require.Len(t, svc.ServerInterceptors, 1, "should have 1 server interceptor")
194 assert.Equal(t, "test", svc.ServerInterceptors[0].Name)
195 },
196 },
197 "invalid-reference": {
198 func() {
199 Service("Service", func() {
200 ServerInterceptor(42) // Invalid type
201 })
202 },
203 func(t *testing.T, _ *expr.ServiceExpr, err error) {
204 require.Error(t, err)
205 },
206 },
207 "invalid-name": {
208 func() {
209 Service("Service", func() {
210 ServerInterceptor("invalid")
211 })
212 },
213 func(t *testing.T, _ *expr.ServiceExpr, err error) {
214 require.Error(t, err)
215 },
216 },
217 }
218
219 for name, tc := range cases {
220 t.Run(name, func(t *testing.T) {
221 eval.Context = &eval.DSLContext{}

Callers

nothing calls this directly

Calls 7

InterceptorFunction · 0.85
ServerInterceptorFunction · 0.85
ServiceFunction · 0.70
runDSLFunction · 0.70
DSLMethod · 0.65
ErrorMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected