(t *testing.T)
| 161 | } |
| 162 | |
| 163 | func TestImageConfig(t *testing.T) { |
| 164 | t.Parallel() |
| 165 | ctx := context.Background() |
| 166 | regHandler := olareg.New(oConfig.Config{ |
| 167 | Storage: oConfig.ConfigStorage{ |
| 168 | StoreType: oConfig.StoreMem, |
| 169 | RootDir: "./testdata", |
| 170 | }, |
| 171 | }) |
| 172 | ts := httptest.NewServer(regHandler) |
| 173 | t.Cleanup(func() { |
| 174 | ts.Close() |
| 175 | _ = regHandler.Close() |
| 176 | }) |
| 177 | tsURL, _ := url.Parse(ts.URL) |
| 178 | tsHost := tsURL.Host |
| 179 | rcHosts := []config.Host{ |
| 180 | { |
| 181 | Name: tsHost, |
| 182 | Hostname: tsHost, |
| 183 | TLS: config.TLSDisabled, |
| 184 | }, |
| 185 | } |
| 186 | log := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelWarn})) |
| 187 | delayInit, _ := time.ParseDuration("0.05s") |
| 188 | delayMax, _ := time.ParseDuration("0.10s") |
| 189 | rc := New( |
| 190 | WithConfigHost(rcHosts...), |
| 191 | WithSlog(log), |
| 192 | WithRegOpts(reg.WithDelay(delayInit, delayMax)), |
| 193 | ) |
| 194 | tt := []struct { |
| 195 | name string |
| 196 | r string |
| 197 | opts []ImageOpts |
| 198 | expectErr error |
| 199 | expectArch string |
| 200 | expectOS string |
| 201 | }{ |
| 202 | { |
| 203 | name: "ocidir-v1-amd64", |
| 204 | r: "ocidir://testdata/testrepo:v1", |
| 205 | opts: []ImageOpts{ImageWithPlatform("linux/amd64")}, |
| 206 | expectArch: "amd64", |
| 207 | expectOS: "linux", |
| 208 | }, |
| 209 | { |
| 210 | name: "ocidir-not-found", |
| 211 | r: "ocidir://testdata/testrepo:missing", |
| 212 | expectErr: errs.ErrNotFound, |
| 213 | }, |
| 214 | { |
| 215 | name: "ocidir-a1", |
| 216 | r: "ocidir://testdata/testrepo:a1", |
| 217 | opts: []ImageOpts{}, |
| 218 | expectErr: errs.ErrUnsupportedMediaType, |
| 219 | }, |
| 220 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…