MCPcopy
hub / github.com/ContainerSSH/ContainerSSH / TestPullImageAuthenticated

Function TestPullImageAuthenticated

internal/docker/docker_impl_test.go:18–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func 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 = &registry.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}

Callers

nothing calls this directly

Calls 14

getMethod · 0.95
RegistryFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
DefaultsFunction · 0.92
NewTestLoggerFunction · 0.92
FatalMethod · 0.80
FatalfMethod · 0.80
MustCreateCounterMethod · 0.65
RunMethod · 0.65
PortMethod · 0.65
pullImageMethod · 0.65

Tested by

no test coverage detected