MCPcopy Create free account
hub / github.com/containers/image / TestSignatureStorageBaseURL

Function TestSignatureStorageBaseURL

docker/registries_d_test.go:24–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22}
23
24func TestSignatureStorageBaseURL(t *testing.T) {
25 emptyDir := t.TempDir()
26 for _, c := range []struct {
27 dir, ref string
28 expected string // Or "" to expect failure
29 }{
30 { // Error reading configuration directory (/dev/null is not a directory)
31 "/dev/null", "//busybox",
32 "",
33 },
34 { // No match found: expect default user storage base
35 emptyDir, "//this/is/not/in/the:configuration",
36 "file://" + filepath.Join(os.Getenv("HOME"), defaultUserDockerDir, "//this/is/not/in/the"),
37 },
38 { // Invalid URL
39 "fixtures/registries.d", "//localhost/invalid/url/test",
40 "",
41 },
42 // URLs without a scheme: This will be rejected by consumers, so we don't really care about
43 // the returned value, but it should not crash at the very least.
44 { // Absolute path
45 "fixtures/registries.d", "//localhost/file/path/test",
46 "/no/scheme/just/a/path/file/path/test",
47 },
48 { // Relative path
49 "fixtures/registries.d", "//localhost/relative/path/test",
50 "no/scheme/relative/path/relative/path/test",
51 },
52 { // Success
53 "fixtures/registries.d", "//example.com/my/project",
54 "https://lookaside.example.com/my/project",
55 },
56 } {
57 base, err := SignatureStorageBaseURL(&types.SystemContext{RegistriesDirPath: c.dir},
58 dockerRefFromString(t, c.ref), false)
59 if c.expected != "" {
60 require.NoError(t, err, c.ref)
61 require.NotNil(t, base, c.ref)
62 assert.Equal(t, c.expected, base.String(), c.ref)
63 } else {
64 assert.Error(t, err, c.ref)
65 }
66 }
67}
68
69func TestRegistriesDirPath(t *testing.T) {
70 const nondefaultPath = "/this/is/not/the/default/registries.d"

Callers

nothing calls this directly

Calls 4

SignatureStorageBaseURLFunction · 0.85
dockerRefFromStringFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…