(t *testing.T)
| 382 | } |
| 383 | |
| 384 | func TestWriteEventError(t *testing.T) { |
| 385 | type entry struct { |
| 386 | timesToSendError int |
| 387 | attemptsWanted int |
| 388 | err error |
| 389 | } |
| 390 | table := map[string]*entry{ |
| 391 | "giveUp1": { |
| 392 | timesToSendError: 1000, |
| 393 | attemptsWanted: 1, |
| 394 | err: &restclient.RequestConstructionError{}, |
| 395 | }, |
| 396 | "giveUp2": { |
| 397 | timesToSendError: 1000, |
| 398 | attemptsWanted: 1, |
| 399 | err: &errors.StatusError{}, |
| 400 | }, |
| 401 | "retry1": { |
| 402 | timesToSendError: 1000, |
| 403 | attemptsWanted: 12, |
| 404 | err: &errors.UnexpectedObjectError{}, |
| 405 | }, |
| 406 | "retry2": { |
| 407 | timesToSendError: 1000, |
| 408 | attemptsWanted: 12, |
| 409 | err: fmt.Errorf("A weird error"), |
| 410 | }, |
| 411 | "succeedEventually": { |
| 412 | timesToSendError: 2, |
| 413 | attemptsWanted: 2, |
| 414 | err: fmt.Errorf("A weird error"), |
| 415 | }, |
| 416 | } |
| 417 | |
| 418 | clock := clock.IntervalClock{Time: time.Now(), Duration: time.Second} |
| 419 | eventCorrelator := NewEventCorrelator(&clock) |
| 420 | randGen := rand.New(rand.NewSource(time.Now().UnixNano())) |
| 421 | |
| 422 | for caseName, ent := range table { |
| 423 | attempts := 0 |
| 424 | sink := &testEventSink{ |
| 425 | OnCreate: func(event *v1.Event) (*v1.Event, error) { |
| 426 | attempts++ |
| 427 | if attempts < ent.timesToSendError { |
| 428 | return nil, ent.err |
| 429 | } |
| 430 | return event, nil |
| 431 | }, |
| 432 | } |
| 433 | ev := &v1.Event{} |
| 434 | recordToSink(sink, ev, eventCorrelator, randGen, 0) |
| 435 | if attempts != ent.attemptsWanted { |
| 436 | t.Errorf("case %v: wanted %d, got %d attempts", caseName, ent.attemptsWanted, attempts) |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | func TestUpdateExpiredEvent(t *testing.T) { |
nothing calls this directly
no test coverage detected