(t *testing.T)
| 344 | } |
| 345 | |
| 346 | func TestConsumerGroupErrors(t *testing.T) { |
| 347 | var left []string |
| 348 | var lock sync.Mutex |
| 349 | mc := mockCoordinator{ |
| 350 | leaveGroupFunc: func(req leaveGroupRequestV0) (leaveGroupResponseV0, error) { |
| 351 | lock.Lock() |
| 352 | left = append(left, req.MemberID) |
| 353 | lock.Unlock() |
| 354 | return leaveGroupResponseV0{}, nil |
| 355 | }, |
| 356 | } |
| 357 | assertLeftGroup := func(t *testing.T, memberID string) { |
| 358 | lock.Lock() |
| 359 | if !reflect.DeepEqual(left, []string{memberID}) { |
| 360 | t.Errorf("expected abc to have left group once, members left: %v", left) |
| 361 | } |
| 362 | left = left[0:0] |
| 363 | lock.Unlock() |
| 364 | } |
| 365 | |
| 366 | // NOTE : the mocked behavior is accumulated across the tests, so they are |
| 367 | // NOT run in parallel. this simplifies test setup so that each test |
| 368 | // can specify only the error behavior required and leverage setup |
| 369 | // from previous steps. |
| 370 | tests := []struct { |
| 371 | scenario string |
| 372 | prepare func(*mockCoordinator) |
| 373 | function func(*testing.T, context.Context, *ConsumerGroup) |
| 374 | }{ |
| 375 | { |
| 376 | scenario: "fails to find coordinator (general error)", |
| 377 | prepare: func(mc *mockCoordinator) { |
| 378 | mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) { |
| 379 | return findCoordinatorResponseV0{}, errors.New("dial error") |
| 380 | } |
| 381 | }, |
| 382 | function: func(t *testing.T, ctx context.Context, group *ConsumerGroup) { |
| 383 | gen, err := group.Next(ctx) |
| 384 | if err == nil { |
| 385 | t.Errorf("expected an error") |
| 386 | } else if err.Error() != "dial error" { |
| 387 | t.Errorf("got wrong error: %+v", err) |
| 388 | } |
| 389 | if gen != nil { |
| 390 | t.Error("expected a nil consumer group generation") |
| 391 | } |
| 392 | }, |
| 393 | }, |
| 394 | |
| 395 | { |
| 396 | scenario: "fails to find coordinator (error code in response)", |
| 397 | prepare: func(mc *mockCoordinator) { |
| 398 | mc.findCoordinatorFunc = func(findCoordinatorRequestV0) (findCoordinatorResponseV0, error) { |
| 399 | return findCoordinatorResponseV0{ |
| 400 | ErrorCode: int16(NotCoordinatorForGroup), |
| 401 | }, nil |
| 402 | } |
| 403 | }, |
nothing calls this directly
no test coverage detected