(t *testing.T)
| 228 | } |
| 229 | |
| 230 | func TestClientInterceptor(t *testing.T) { |
| 231 | cases := map[string]struct { |
| 232 | DSL func() |
| 233 | Assert func(*testing.T, *expr.ServiceExpr, error) |
| 234 | }{ |
| 235 | "valid-reference": { |
| 236 | func() { |
| 237 | var testInterceptor = Interceptor("test", func() {}) |
| 238 | Service("Service", func() { |
| 239 | ClientInterceptor(testInterceptor) |
| 240 | }) |
| 241 | }, |
| 242 | func(t *testing.T, svc *expr.ServiceExpr, err error) { |
| 243 | require.NoError(t, err) |
| 244 | require.NotNil(t, svc) |
| 245 | require.Len(t, svc.ClientInterceptors, 1, "should have 1 client interceptor") |
| 246 | }, |
| 247 | }, |
| 248 | "valid-by-name": { |
| 249 | func() { |
| 250 | Interceptor("test", func() {}) |
| 251 | Service("Service", func() { |
| 252 | ClientInterceptor("test") |
| 253 | }) |
| 254 | }, |
| 255 | func(t *testing.T, svc *expr.ServiceExpr, err error) { |
| 256 | require.NoError(t, err) |
| 257 | require.NotNil(t, svc) |
| 258 | require.Len(t, svc.ClientInterceptors, 1, "should have 1 client interceptor") |
| 259 | }, |
| 260 | }, |
| 261 | "invalid-reference": { |
| 262 | func() { |
| 263 | Service("Service", func() { |
| 264 | ClientInterceptor(42) // Invalid type |
| 265 | }) |
| 266 | }, |
| 267 | func(t *testing.T, _ *expr.ServiceExpr, err error) { |
| 268 | require.Error(t, err) |
| 269 | }, |
| 270 | }, |
| 271 | "invalid-name": { |
| 272 | func() { |
| 273 | Service("Service", func() { |
| 274 | ClientInterceptor("invalid") |
| 275 | }) |
| 276 | }, |
| 277 | func(t *testing.T, _ *expr.ServiceExpr, err error) { |
| 278 | require.Error(t, err) |
| 279 | }, |
| 280 | }, |
| 281 | } |
| 282 | |
| 283 | for name, tc := range cases { |
| 284 | t.Run(name, func(t *testing.T) { |
| 285 | eval.Context = &eval.DSLContext{} |
| 286 | expr.Root = new(expr.RootExpr) |
| 287 | tc.DSL() |
nothing calls this directly
no test coverage detected