blob: 7224a40825b03ef4f6138f119d0af7cf45dff69b [file] [log] [blame]
Mohammed Naser4c8e0cb2024-02-21 11:51:34 -05001package defaults
2
3import (
4 "context"
5 "fmt"
6 "slices"
7 "strings"
8 "testing"
9
10 "github.com/containers/image/v5/docker"
11 "github.com/stretchr/testify/require"
12)
13
14func TestImageExist(t *testing.T) {
15 images, err := GetImages()
16 require.NoError(t, err)
17
18 var uniqueImages []string
19 for _, image := range images {
20 if slices.Contains(uniqueImages, image) {
21 continue
22 }
23
24 uniqueImages = append(uniqueImages, image)
25 }
26
27 for _, image := range uniqueImages {
28 // NOTE(mnaser): ParseReference does not allow both tag & digest,
29 // so we strip the tags from the image name.
Mohammed Naser91e2fa02024-02-23 01:46:39 -050030 nameWithTagSplit := strings.Split(image, "@")
31 require.Len(t, nameWithTagSplit, 2)
32 nameWithTag := nameWithTagSplit[0]
Mohammed Naser4c8e0cb2024-02-21 11:51:34 -050033 name := strings.Split(nameWithTag, ":")[0]
34 digest := strings.Split(image, "@")[1]
35 image := fmt.Sprintf("%s@%s", name, digest)
36
37 t.Run(image, func(t *testing.T) {
38 t.Parallel()
39
40 ref, err := docker.ParseReference(fmt.Sprintf("//%s", image))
41 require.NoError(t, err)
42
43 ctx := context.Background()
44 img, err := ref.NewImage(ctx, nil)
45 require.NoError(t, err)
46 defer img.Close()
47
48 _, _, err = img.Manifest(ctx)
49 require.NoError(t, err)
50 })
51 }
52}