Skip to content

Commit

Permalink
cli/context/store: Names(): fix panic when called with nil-interface
Browse files Browse the repository at this point in the history
Before this, it would panic when a nil-interface was passed.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jul 5, 2024
1 parent 8666f6e commit 66730c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/context/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func (s *ContextStore) List() ([]Metadata, error) {

// Names return Metadata names for a Lister
func Names(s Lister) ([]string, error) {
if s == nil {
return nil, errors.New("nil lister")
}
list, err := s.List()
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions cli/context/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ func TestCorruptMetadata(t *testing.T) {
_, err = s.GetMetadata("source")
assert.ErrorContains(t, err, fmt.Sprintf("parsing %s: unexpected end of JSON input", contextFile))
}

func TestNames(t *testing.T) {
names, err := Names(nil)
assert.Check(t, is.Error(err, "nil lister"))
assert.Check(t, is.Len(names, 0))
}

0 comments on commit 66730c9

Please sign in to comment.