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>
This commit is contained in:
parent
42b68a3ed7
commit
e4dd8b1898
|
@ -124,6 +124,9 @@ func (s *ContextStore) List() ([]Metadata, error) {
|
||||||
|
|
||||||
// Names return Metadata names for a Lister
|
// Names return Metadata names for a Lister
|
||||||
func Names(s Lister) ([]string, error) {
|
func Names(s Lister) ([]string, error) {
|
||||||
|
if s == nil {
|
||||||
|
return nil, errors.New("nil lister")
|
||||||
|
}
|
||||||
list, err := s.List()
|
list, err := s.List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -260,3 +260,9 @@ func TestCorruptMetadata(t *testing.T) {
|
||||||
_, err = s.GetMetadata("source")
|
_, err = s.GetMetadata("source")
|
||||||
assert.ErrorContains(t, err, fmt.Sprintf("parsing %s: unexpected end of JSON input", contextFile))
|
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