fix: default image source name to user input (#1979)

* 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>
This commit is contained in:
Keith Zantow 2023-07-31 13:29:18 -04:00 committed by GitHub
parent f14742b3f3
commit e2f7befbfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -109,8 +109,6 @@ func (s StereoscopeImageSource) Describe() Description {
} else { } else {
if ref, ok := ref.(reference.Named); ok { if ref, ok := ref.(reference.Named); ok {
nameIfUnset(ref.Name()) nameIfUnset(ref.Name())
} else {
nameIfUnset(s.metadata.UserInput)
} }
if ref, ok := ref.(reference.NamedTagged); ok { if ref, ok := ref.(reference.NamedTagged); ok {
@ -122,6 +120,7 @@ func (s StereoscopeImageSource) Describe() Description {
} }
} }
nameIfUnset(s.metadata.UserInput)
versionIfUnset(s.metadata.ManifestDigest) versionIfUnset(s.metadata.ManifestDigest)
return Description{ return Description{

View File

@ -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)
}
}