| 36 | ) |
| 37 | |
| 38 | func WithTestImageConfig(ctx context.Context, url string) context.Context { |
| 39 | ref, err := name.NewDigest(url) |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | |
| 44 | // Setup parent/base image mock |
| 45 | parentURL := utils.WithDigest("registry.local/base-image") |
| 46 | parentRef, err := name.ParseReference(parentURL) |
| 47 | if err != nil { |
| 48 | panic(err) |
| 49 | } |
| 50 | parentImage, err := mutate.Config(empty.Image, v1.Config{ |
| 51 | Labels: map[string]string{ |
| 52 | "io.k8s.display-name": "Base Image", |
| 53 | }, |
| 54 | }) |
| 55 | if err != nil { |
| 56 | panic(err) |
| 57 | } |
| 58 | |
| 59 | // Setup child image mock |
| 60 | image := mutate.Annotations(empty.Image, map[string]string{ |
| 61 | oci.BaseImageNameAnnotation: parentURL, |
| 62 | }).(v1.Image) |
| 63 | image, err = mutate.Config(image, v1.Config{ |
| 64 | Labels: map[string]string{ |
| 65 | "io.k8s.display-name": "Test Image", |
| 66 | }, |
| 67 | }) |
| 68 | if err != nil { |
| 69 | panic(err) |
| 70 | } |
| 71 | |
| 72 | // Setup client |
| 73 | client := &FakeClient{} |
| 74 | client.On("Image", ref, mock.Anything).Return(image, nil) |
| 75 | client.On("Image", parentRef, mock.Anything).Return(parentImage, nil) |
| 76 | |
| 77 | return oci.WithClient(ctx, client) |
| 78 | } |
| 79 | |
| 80 | var _ oci.Client = &FakeClient{} |
| 81 | |