(ctx context.Context, imageRef string, data *godog.DocString)
| 250 | } |
| 251 | |
| 252 | func assertImageContent(ctx context.Context, imageRef string, data *godog.DocString) error { |
| 253 | state := testenv.FetchState[registryState](ctx) |
| 254 | |
| 255 | ref, err := name.ParseReference(fmt.Sprintf("%s/%s", state.HostAndPort, imageRef)) |
| 256 | if err != nil { |
| 257 | return err |
| 258 | } |
| 259 | |
| 260 | img, err := remote.Image(ref) |
| 261 | if err != nil { |
| 262 | return err |
| 263 | } |
| 264 | |
| 265 | layers, err := img.Layers() |
| 266 | if err != nil { |
| 267 | return err |
| 268 | } |
| 269 | |
| 270 | if len(layers) != 1 { |
| 271 | return fmt.Errorf("unexpected number of layers: %d, expecting only one", len(layers)) |
| 272 | } |
| 273 | |
| 274 | in, err := layers[0].Uncompressed() |
| 275 | if err != nil { |
| 276 | return err |
| 277 | } |
| 278 | defer in.Close() |
| 279 | |
| 280 | content, err := io.ReadAll(in) |
| 281 | if err != nil { |
| 282 | return err |
| 283 | } |
| 284 | |
| 285 | vals := map[string]string{ |
| 286 | "REGISTRY": state.HostAndPort, |
| 287 | "TODAY_PLUS_30_DAYS": time.Now().Round(time.Hour*24).UTC().AddDate(0, 0, 30).Format(time.RFC3339), |
| 288 | } |
| 289 | |
| 290 | expected := os.Expand(data.Content, func(key string) string { |
| 291 | return vals[key] |
| 292 | }) |
| 293 | |
| 294 | got := string(content) |
| 295 | |
| 296 | if expected == got { |
| 297 | return nil |
| 298 | } |
| 299 | |
| 300 | var b bytes.Buffer |
| 301 | err = diff.Text("layer", "expected", got, expected, &b) |
| 302 | if err != nil { |
| 303 | return err |
| 304 | } |
| 305 | |
| 306 | return fmt.Errorf("expected image layer and actual image layer differ:\n%s", b.String()) |
| 307 | } |
| 308 | |
| 309 | func Register(ctx context.Context, hostAndPort string) (context.Context, error) { |
nothing calls this directly
no test coverage detected