mirror of https://github.com/docker/cli.git
cli/context/store: Names(): fix panic when called with nil-interface
Before this, it would panic when a nil-interface was passed.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit e4dd8b1898
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
787caf2fe4
commit
3926ed6b24
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue