MCPcopy Create free account
hub / github.com/coder/envbox / TestWriteCertsForRegistry

Function TestWriteCertsForRegistry

dockerutil/registry_test.go:18–100  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16)
17
18func TestWriteCertsForRegistry(t *testing.T) {
19 t.Parallel()
20
21 t.Run("SingleCertFile", func(t *testing.T) {
22 t.Parallel()
23 // Test setup
24 fs := xunixfake.NewMemFS()
25 ctx := xunix.WithFS(context.Background(), fs)
26
27 // Create a test certificate file
28 certContent := []byte("test certificate content")
29 err := afero.WriteFile(fs, "/certs/ca.crt", certContent, 0o644)
30 require.NoError(t, err)
31
32 // Run the function
33 err = dockerutil.WriteCertsForRegistry(ctx, "test.registry.com", "/certs/ca.crt")
34 require.NoError(t, err)
35
36 // Check the result
37 copiedContent, err := afero.ReadFile(fs, "/etc/docker/certs.d/test.registry.com/ca.crt")
38 require.NoError(t, err)
39 assert.Equal(t, certContent, copiedContent)
40 })
41
42 t.Run("MultipleCertFiles", func(t *testing.T) {
43 t.Parallel()
44 // Test setup
45 fs := xunixfake.NewMemFS()
46 ctx := xunix.WithFS(context.Background(), fs)
47
48 // Create test certificate files
49 certFiles := []string{"ca.crt", "client.cert", "client.key"}
50 for _, file := range certFiles {
51 err := afero.WriteFile(fs, filepath.Join("/certs", file), []byte("content of "+file), 0o644)
52 require.NoError(t, err)
53 }
54
55 // Run the function
56 err := dockerutil.WriteCertsForRegistry(ctx, "test.registry.com", "/certs")
57 require.NoError(t, err)
58
59 // Check the results
60 for _, file := range certFiles {
61 copiedContent, err := afero.ReadFile(fs, filepath.Join("/etc/docker/certs.d/test.registry.com", file))
62 require.NoError(t, err)
63 assert.Equal(t, []byte("content of "+file), copiedContent)
64 }
65 })
66 t.Run("ExistingRegistryCertsDir", func(t *testing.T) {
67 t.Parallel()
68 // Test setup
69 fs := xunixfake.NewMemFS()
70 ctx := xunix.WithFS(context.Background(), fs)
71
72 // Create an existing registry certs directory
73 registryCertsDir := "/etc/docker/certs.d/test.registry.com"
74 err := fs.MkdirAll(registryCertsDir, 0o755)
75 require.NoError(t, err)

Callers

nothing calls this directly

Calls 4

NewMemFSFunction · 0.92
WithFSFunction · 0.92
WriteCertsForRegistryFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected