Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/chartverifier/checks/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func getImageReferences(chartURI string, vals map[string]interface{}, serverKube
// getImagesFromContent evaluates generated templates from
// helm and extracts images which are returned in a slice
func getImagesFromContent(content string) ([]string, error) {
re, err := regexp.Compile(`\s+image\:\s+(?P<image>.*)\n`)
re, err := regexp.Compile(`(?m)\s+image\:[ \t]+(?P<image>\S.*)\s*$`)
if err != nil {
return nil, fmt.Errorf("error getting images; %v", err)
}
Expand Down
57 changes: 35 additions & 22 deletions internal/chartverifier/checks/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,39 +191,52 @@ func TestLongLineTemplate(t *testing.T) {
}

func TestGetImagesFromContent(t *testing.T) {
test := struct {
testCases := []struct {
name string
content string
want []string
}{
name: "find images in yaml",
content: `
{
name: "find images in yaml",
content: `
image: "registry.access.redhat.com/rhscl/postgresql-10-rhel7:1-161"
image: 'busybox'
image: " "
image: registry.redhat.io/cpopen/ibmcloud-object-storage-driver@sha256:fc17bb3e89d00b3eb0f50b3ea83aa75c52e43d8e56cf2e0f17475e934eeeeb5f
`,
want: []string{
"registry.access.redhat.com/rhscl/postgresql-10-rhel7:1-161",
"busybox",
"",
"registry.redhat.io/cpopen/ibmcloud-object-storage-driver@sha256:fc17bb3e89d00b3eb0f50b3ea83aa75c52e43d8e56cf2e0f17475e934eeeeb5f",
want: []string{
"registry.access.redhat.com/rhscl/postgresql-10-rhel7:1-161",
"busybox",
"",
"registry.redhat.io/cpopen/ibmcloud-object-storage-driver@sha256:fc17bb3e89d00b3eb0f50b3ea83aa75c52e43d8e56cf2e0f17475e934eeeeb5f",
},
},
{
name: "do not match against mappings",
content: `
image:
repository: "registry.access.redhat.com/rhscl/postgresql-10-rhel7:1-161"
`,
want: []string{},
},
}

t.Run(test.name, func(t *testing.T) {
got, err := getImagesFromContent(test.content)
require.Nil(t, err)
if testing.Verbose() {
t.Logf("got %d images", len(got))
}
if len(got) != len(test.want) {
t.Errorf("got %d images but, want %d", len(got), len(test.want))
}
for _, image := range got {
if strings.TrimSpace(image) == "" {
t.Logf("Found empty image")
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got, err := getImagesFromContent(tc.content)
require.Nil(t, err)
if testing.Verbose() {
t.Logf("got %d images", len(got))
t.Logf("got: %s", got)
}
}
})
if len(got) != len(tc.want) {
t.Errorf("got %d images but, want %d", len(got), len(tc.want))
}
for _, image := range got {
if strings.TrimSpace(image) == "" {
t.Logf("Found empty image")
}
}
})
}
}