(t *testing.T)
| 16 | ) |
| 17 | |
| 18 | func TestPullImageAuthenticated(t *testing.T) { |
| 19 | testRegistry := test.Registry(t, true) |
| 20 | metricsCollector := metrics.New(dummy.New()) |
| 21 | clientFactory := &dockerV20ClientFactory{ |
| 22 | backendFailuresMetric: metricsCollector.MustCreateCounter("backend-failures", "requests", ""), |
| 23 | backendRequestsMetric: metricsCollector.MustCreateCounter("backend-failures", "requests", ""), |
| 24 | } |
| 25 | ctx := context.Background() |
| 26 | |
| 27 | t.Run("unauthenticated", func(t *testing.T) { |
| 28 | cfg := config.DockerConfig{} |
| 29 | structutils.Defaults(&cfg) |
| 30 | cfg.Execution.ContainerConfig.Image = fmt.Sprintf("localhost:%d/containerssh/guest-image", testRegistry.Port()) |
| 31 | |
| 32 | logger := log.NewTestLogger(t) |
| 33 | client, err := clientFactory.get(ctx, cfg, logger) |
| 34 | if err != nil { |
| 35 | t.Fatal(err) |
| 36 | } |
| 37 | |
| 38 | pullCtx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| 39 | defer cancel() |
| 40 | if err := client.pullImage(pullCtx); err == nil { |
| 41 | t.Fatalf("Pulling without credentials didn't fail.") |
| 42 | } |
| 43 | }) |
| 44 | t.Run("authenticated", func(t *testing.T) { |
| 45 | cfg := config.DockerConfig{} |
| 46 | structutils.Defaults(&cfg) |
| 47 | cfg.Execution.ContainerConfig.Image = fmt.Sprintf("localhost:%d/containerssh/agent", testRegistry.Port()) |
| 48 | cfg.Execution.Auth = ®istry.AuthConfig{ |
| 49 | Username: *testRegistry.Username(), |
| 50 | Password: *testRegistry.Password(), |
| 51 | Email: "noreply@containerssh.io", |
| 52 | ServerAddress: fmt.Sprintf("localhost:%d", testRegistry.Port()), |
| 53 | } |
| 54 | |
| 55 | logger := log.NewTestLogger(t) |
| 56 | client, err := clientFactory.get(ctx, cfg, logger) |
| 57 | if err != nil { |
| 58 | t.Fatal(err) |
| 59 | } |
| 60 | |
| 61 | pullCtx, cancel := context.WithTimeout(context.Background(), time.Minute) |
| 62 | defer cancel() |
| 63 | if err := client.pullImage(pullCtx); err != nil { |
| 64 | t.Fatalf("Pulling with credentials failed (%v).", err) |
| 65 | } |
| 66 | }) |
| 67 | } |
nothing calls this directly
no test coverage detected