(t *testing.T)
| 22 | } |
| 23 | |
| 24 | func 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 | |
| 69 | func TestRegistriesDirPath(t *testing.T) { |
| 70 | const nondefaultPath = "/this/is/not/the/default/registries.d" |
nothing calls this directly
no test coverage detected
searching dependent graphs…