Skip to content

Commit 256446a

Browse files
committed
Linting + handlind json null values
Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
1 parent 81323f7 commit 256446a

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

cli/command/cli_test.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
cliconfig "github.com/docker/cli/cli/config"
1111
"github.com/docker/cli/cli/config/configfile"
12-
"github.com/docker/cli/cli/context/store"
1312
"github.com/docker/cli/cli/flags"
1413
"github.com/docker/docker/api"
1514
"github.com/docker/docker/api/types"
@@ -248,38 +247,3 @@ func TestGetClientWithPassword(t *testing.T) {
248247
})
249248
}
250249
}
251-
252-
type emptyContextStore struct {
253-
}
254-
255-
func (emptyContextStore) ListContexts() (map[string]store.ContextMetadata, error) {
256-
return nil, nil
257-
}
258-
259-
func (emptyContextStore) CreateOrUpdateContext(name string, meta store.ContextMetadata) error {
260-
return nil
261-
}
262-
263-
func (emptyContextStore) RemoveContext(name string) error {
264-
return nil
265-
}
266-
267-
func (emptyContextStore) GetContextMetadata(name string) (store.ContextMetadata, error) {
268-
return store.ContextMetadata{}, nil
269-
}
270-
271-
func (emptyContextStore) ResetContextTLSMaterial(name string, data *store.ContextTLSData) error {
272-
return nil
273-
}
274-
275-
func (emptyContextStore) ResetContextEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error {
276-
return nil
277-
}
278-
279-
func (emptyContextStore) ListContextTLSFiles(name string) (map[string]store.EndpointFiles, error) {
280-
return nil, nil
281-
}
282-
283-
func (emptyContextStore) GetContextTLSData(contextName, endpointName, fileName string) ([]byte, error) {
284-
return nil, nil
285-
}

cli/context/store/metadatastore.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (s *metadataStore) createOrUpdate(name string, meta ContextMetadata) error
3636
}
3737

3838
func parseTypedOrMap(payload []byte, getter TypeGetter) (interface{}, error) {
39-
if len(payload) == 0 {
39+
if len(payload) == 0 || string(payload) == "null" {
4040
return nil, nil
4141
}
4242
if getter == nil {
@@ -63,7 +63,9 @@ func (s *metadataStore) get(name string) (ContextMetadata, error) {
6363
r := ContextMetadata{
6464
Endpoints: make(map[string]interface{}),
6565
}
66-
err = json.Unmarshal(bytes, &untyped)
66+
if err := json.Unmarshal(bytes, &untyped); err != nil {
67+
return ContextMetadata{}, err
68+
}
6769
if r.Metadata, err = parseTypedOrMap(untyped.Metadata, s.config.contextType); err != nil {
6870
return ContextMetadata{}, err
6971
}

0 commit comments

Comments
 (0)