Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default image source name to user input #1979

Merged
merged 2 commits into from
Jul 31, 2023
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
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)
}
}
Loading