(t *testing.T)
| 554 | } |
| 555 | |
| 556 | func TestOneShot(t *testing.T) { |
| 557 | ctx := t.Context() |
| 558 | |
| 559 | log.Info("Test 'TestOneShot'") |
| 560 | |
| 561 | tests := []struct { |
| 562 | dsn string |
| 563 | expectedErr string |
| 564 | expectedOutput string |
| 565 | expectedLines int |
| 566 | logType string |
| 567 | }{ |
| 568 | { |
| 569 | dsn: "docker://non_exist_docker", |
| 570 | expectedErr: "no container found named: non_exist_docker, can't run one shot acquisition", |
| 571 | expectedOutput: "", |
| 572 | expectedLines: 0, |
| 573 | logType: "test", |
| 574 | }, |
| 575 | { |
| 576 | dsn: "docker://" + testContainerName, |
| 577 | expectedErr: "", |
| 578 | expectedOutput: "", |
| 579 | expectedLines: 3, |
| 580 | logType: "test", |
| 581 | }, |
| 582 | } |
| 583 | |
| 584 | for _, ts := range tests { |
| 585 | t.Run(ts.dsn, func(t *testing.T) { |
| 586 | subLogger := log.WithField("type", ModuleName) |
| 587 | |
| 588 | dockerClient := &Source{} |
| 589 | labels := make(map[string]string) |
| 590 | labels["type"] = ts.logType |
| 591 | |
| 592 | err := dockerClient.ConfigureByDSN(ctx, ts.dsn, labels, subLogger, "") |
| 593 | require.NoError(t, err) |
| 594 | |
| 595 | dockerClient.Client = &mockDockerCli{} |
| 596 | out := make(chan pipeline.Event, 100) |
| 597 | |
| 598 | tomb := tomb.Tomb{} |
| 599 | |
| 600 | err = dockerClient.OneShotAcquisition(ctx, out, &tomb) |
| 601 | cstest.AssertErrorContains(t, err, ts.expectedErr) |
| 602 | |
| 603 | // else we do the check before actualLines is incremented ... |
| 604 | if ts.expectedLines != 0 { |
| 605 | assert.Len(t, out, ts.expectedLines) |
| 606 | } |
| 607 | }) |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | func TestParseLabels(t *testing.T) { |
| 612 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…