Skip to content

Commit

Permalink
fix: default image source name to user input (#1979)
Browse files Browse the repository at this point in the history
* fix: default image source name to user input

Signed-off-by: Keith Zantow <kzantow@gmail.com>

* chore: add test

Signed-off-by: Keith Zantow <kzantow@gmail.com>

---------

Signed-off-by: Keith Zantow <kzantow@gmail.com>
  • Loading branch information
kzantow committed Jul 31, 2023
1 parent f14742b commit e2f7bef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions syft/source/stereoscope_image_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ func (s StereoscopeImageSource) Describe() Description {
} else {
if ref, ok := ref.(reference.Named); ok {
nameIfUnset(ref.Name())
} else {
nameIfUnset(s.metadata.UserInput)
}

if ref, ok := ref.(reference.NamedTagged); ok {
Expand All @@ -122,6 +120,7 @@ func (s StereoscopeImageSource) Describe() Description {
}
}

nameIfUnset(s.metadata.UserInput)
versionIfUnset(s.metadata.ManifestDigest)

return Description{
Expand Down
28 changes: 28 additions & 0 deletions syft/source/stereoscope_image_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,31 @@ func Test_StereoscopeImageSource_ID(t *testing.T) {
})
}
}

func Test_Describe(t *testing.T) {
tests := []struct {
name string
source StereoscopeImageSource
expected Description
}{
{
name: "name from user input",
source: StereoscopeImageSource{
id: "some-id",
metadata: StereoscopeImageSourceMetadata{
UserInput: "user input",
},
},
expected: Description{
ID: "some-id",
Name: "user input",
},
},
}

for _, test := range tests {
got := test.source.Describe()
got.Metadata = nil // might want to test this, but do not to determine if the user input is userd
require.Equal(t, test.expected, got)
}
}

0 comments on commit e2f7bef

Please sign in to comment.