From 34446d0343339689832add03f1034c04cc3e529b Mon Sep 17 00:00:00 2001 From: Jim Lin Date: Mon, 11 Jan 2021 22:59:35 +0800 Subject: [PATCH] replace json.Unmarshal with NewFromJSON in Create Signed-off-by: Jim Lin (cherry picked from commit c9ec21e17a3353872d486f2e732ae7f53de37c41) Signed-off-by: Sebastiaan van Stijn --- image/store.go | 5 ++--- image/store_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/image/store.go b/image/store.go index 0ad87f5c61..20a6d49257 100644 --- a/image/store.go +++ b/image/store.go @@ -1,7 +1,6 @@ package image // import "github.com/docker/docker/image" import ( - "encoding/json" "fmt" "sync" "time" @@ -118,8 +117,8 @@ func (is *store) restore() error { } func (is *store) Create(config []byte) (ID, error) { - var img Image - err := json.Unmarshal(config, &img) + var img *Image + img, err := NewFromJSON(config) if err != nil { return "", err } diff --git a/image/store_test.go b/image/store_test.go index f159cb3830..970b8d8ab6 100644 --- a/image/store_test.go +++ b/image/store_test.go @@ -10,6 +10,14 @@ import ( "gotest.tools/v3/assert/cmp" ) +func TestCreate(t *testing.T) { + is, cleanup := defaultImageStore(t) + defer cleanup() + + _, err := is.Create([]byte(`{}`)) + assert.Check(t, cmp.Error(err, "invalid image JSON, no RootFS key")) +} + func TestRestore(t *testing.T) { fs, cleanup := defaultFSStoreBackend(t) defer cleanup()