Skip to content

Commit

Permalink
Merge pull request #41976 from thaJeztah/20.10_backport_reuse
Browse files Browse the repository at this point in the history
[20.10 backport] replace json.Unmarshal with NewFromJSON in Create
  • Loading branch information
tiborvass authored Feb 18, 2021
2 parents b81e649 + 34446d0 commit b55d9e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions image/store.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package image // import "github.com/docker/docker/image"

import (
"encoding/json"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions image/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b55d9e1

Please sign in to comment.