Merge pull request #41701 from jimlinntu/reuse

replace json.Unmarshal with NewFromJSON in Create
This commit is contained in:
Sebastiaan van Stijn 2021-01-13 00:10:59 +01:00 committed by GitHub
commit 5799d1c89c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -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
}

View file

@ -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()