mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix incorrect info and format of error in image
Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
This commit is contained in:
parent
e9076c0f00
commit
b2ec509a3f
5 changed files with 36 additions and 36 deletions
|
@ -75,7 +75,7 @@ func (s *fs) Walk(f DigestWalkFunc) error {
|
||||||
for _, v := range dir {
|
for _, v := range dir {
|
||||||
dgst := digest.NewDigestFromHex(string(digest.Canonical), v.Name())
|
dgst := digest.NewDigestFromHex(string(digest.Canonical), v.Name())
|
||||||
if err := dgst.Validate(); err != nil {
|
if err := dgst.Validate(); err != nil {
|
||||||
logrus.Debugf("Skipping invalid digest %s: %s", dgst, err)
|
logrus.Debugf("skipping invalid digest %s: %s", dgst, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := f(dgst); err != nil {
|
if err := f(dgst); err != nil {
|
||||||
|
@ -113,7 +113,7 @@ func (s *fs) Set(data []byte) (digest.Digest, error) {
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return "", fmt.Errorf("Invalid empty data")
|
return "", fmt.Errorf("invalid empty data")
|
||||||
}
|
}
|
||||||
|
|
||||||
dgst := digest.FromBytes(data)
|
dgst := digest.FromBytes(data)
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestFSGetInvalidData(t *testing.T) {
|
||||||
|
|
||||||
_, err = fs.Get(id)
|
_, err = fs.Get(id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected get to fail after data modification.")
|
t.Fatal("expected get to fail after data modification.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ func TestFSInvalidSet(t *testing.T) {
|
||||||
|
|
||||||
_, err = fs.Set([]byte("foobar"))
|
_, err = fs.Set([]byte("foobar"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expecting error from invalid filesystem data.")
|
t.Fatal("expected error from invalid filesystem data.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ func TestFSInvalidRoot(t *testing.T) {
|
||||||
|
|
||||||
_, err = NewFSStoreBackend(root)
|
_, err = NewFSStoreBackend(root)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected error from root %q and invlid file %q", tc.root, tc.invalidFile)
|
t.Fatalf("expected error from root %q and invalid file %q", tc.root, tc.invalidFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.RemoveAll(root)
|
os.RemoveAll(root)
|
||||||
|
@ -154,18 +154,18 @@ func testMetadataGetSet(t *testing.T, store StoreBackend) {
|
||||||
|
|
||||||
_, err = store.GetMetadata(id2, "tkey2")
|
_, err = store.GetMetadata(id2, "tkey2")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error for getting metadata for unknown key")
|
t.Fatal("expected error for getting metadata for unknown key")
|
||||||
}
|
}
|
||||||
|
|
||||||
id3 := digest.FromBytes([]byte("baz"))
|
id3 := digest.FromBytes([]byte("baz"))
|
||||||
err = store.SetMetadata(id3, "tkey", []byte("tval"))
|
err = store.SetMetadata(id3, "tkey", []byte("tval"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error for setting metadata for unknown ID.")
|
t.Fatal("expected error for setting metadata for unknown ID.")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = store.GetMetadata(id3, "tkey")
|
_, err = store.GetMetadata(id3, "tkey")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error for getting metadata for unknown ID.")
|
t.Fatal("expected error for getting metadata for unknown ID.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,16 +234,16 @@ func TestFSInvalidWalker(t *testing.T) {
|
||||||
n := 0
|
n := 0
|
||||||
err = fs.Walk(func(id digest.Digest) error {
|
err = fs.Walk(func(id digest.Digest) error {
|
||||||
if id != fooID {
|
if id != fooID {
|
||||||
t.Fatalf("Invalid walker ID %q, expected %q", id, fooID)
|
t.Fatalf("invalid walker ID %q, expected %q", id, fooID)
|
||||||
}
|
}
|
||||||
n++
|
n++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Invalid data should not have caused walker error, got %v", err)
|
t.Fatalf("invalid data should not have caused walker error, got %v", err)
|
||||||
}
|
}
|
||||||
if n != 1 {
|
if n != 1 {
|
||||||
t.Fatalf("Expected 1 walk initialization, got %d", n)
|
t.Fatalf("expected 1 walk initialization, got %d", n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ func testGetSet(t *testing.T, store StoreBackend) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// skipping use of digest pkg because its used by the implementation
|
// skipping use of digest pkg because it is used by the implementation
|
||||||
h := sha256.New()
|
h := sha256.New()
|
||||||
_, err = h.Write(randomInput)
|
_, err = h.Write(randomInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -278,14 +278,14 @@ func testGetSet(t *testing.T, store StoreBackend) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if id != tc.expected {
|
if id != tc.expected {
|
||||||
t.Fatalf("Expected ID %q, got %q", tc.expected, id)
|
t.Fatalf("expected ID %q, got %q", tc.expected, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, emptyData := range [][]byte{nil, {}} {
|
for _, emptyData := range [][]byte{nil, {}} {
|
||||||
_, err := store.Set(emptyData)
|
_, err := store.Set(emptyData)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected error for nil input.")
|
t.Fatal("expected error for nil input.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,14 +295,14 @@ func testGetSet(t *testing.T, store StoreBackend) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if bytes.Compare(data, tc.input) != 0 {
|
if bytes.Compare(data, tc.input) != 0 {
|
||||||
t.Fatalf("Expected data %q, got %q", tc.input, data)
|
t.Fatalf("expected data %q, got %q", tc.input, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
|
for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
|
||||||
_, err := store.Get(key)
|
_, err := store.Get(key)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected error for ID %q.", key)
|
t.Fatalf("expected error for ID %q.", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ func testDelete(t *testing.T, store StoreBackend) {
|
||||||
|
|
||||||
_, err = store.Get(id)
|
_, err = store.Get(id)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected getting deleted item %q to fail", id)
|
t.Fatalf("expected getting deleted item %q to fail", id)
|
||||||
}
|
}
|
||||||
_, err = store.Get(id2)
|
_, err = store.Get(id2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -338,7 +338,7 @@ func testDelete(t *testing.T, store StoreBackend) {
|
||||||
}
|
}
|
||||||
_, err = store.Get(id2)
|
_, err = store.Get(id2)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected getting deleted item %q to fail", id2)
|
t.Fatalf("expected getting deleted item %q to fail", id2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,10 +366,10 @@ func testWalker(t *testing.T, store StoreBackend) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if n != 2 {
|
if n != 2 {
|
||||||
t.Fatalf("Expected 2 walk initializations, got %d", n)
|
t.Fatalf("expected 2 walk initializations, got %d", n)
|
||||||
}
|
}
|
||||||
if len(tcases) != 0 {
|
if len(tcases) != 0 {
|
||||||
t.Fatalf("Expected empty unwalked set, got %+v", tcases)
|
t.Fatalf("expected empty unwalked set, got %+v", tcases)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop on error
|
// stop on error
|
||||||
|
@ -379,6 +379,6 @@ func testWalker(t *testing.T, store StoreBackend) {
|
||||||
return errors.New("")
|
return errors.New("")
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Exected error from walker.")
|
t.Fatalf("expected error from walker.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,21 +29,21 @@ func IDFromDigest(digest digest.Digest) ID {
|
||||||
|
|
||||||
// V1Image stores the V1 image configuration.
|
// V1Image stores the V1 image configuration.
|
||||||
type V1Image struct {
|
type V1Image struct {
|
||||||
// ID a unique 64 character identifier of the image
|
// ID is a unique 64 character identifier of the image
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
// Parent id of the image
|
// Parent is the ID of the parent image
|
||||||
Parent string `json:"parent,omitempty"`
|
Parent string `json:"parent,omitempty"`
|
||||||
// Comment user added comment
|
// Comment is the commit message that was set when committing the image
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
// Created timestamp when image was created
|
// Created is the timestamp at which the image was created
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
// Container is the id of the container used to commit
|
// Container is the id of the container used to commit
|
||||||
Container string `json:"container,omitempty"`
|
Container string `json:"container,omitempty"`
|
||||||
// ContainerConfig is the configuration of the container that is committed into the image
|
// ContainerConfig is the configuration of the container that is committed into the image
|
||||||
ContainerConfig container.Config `json:"container_config,omitempty"`
|
ContainerConfig container.Config `json:"container_config,omitempty"`
|
||||||
// DockerVersion specifies version on which image is built
|
// DockerVersion specifies the version of Docker that was used to build the image
|
||||||
DockerVersion string `json:"docker_version,omitempty"`
|
DockerVersion string `json:"docker_version,omitempty"`
|
||||||
// Author of the image
|
// Author is the name of the author that was specified when committing the image
|
||||||
Author string `json:"author,omitempty"`
|
Author string `json:"author,omitempty"`
|
||||||
// Config is the configuration of the container received from the client
|
// Config is the configuration of the container received from the client
|
||||||
Config *container.Config `json:"config,omitempty"`
|
Config *container.Config `json:"config,omitempty"`
|
||||||
|
@ -112,13 +112,13 @@ func (img *Image) MarshalJSON() ([]byte, error) {
|
||||||
|
|
||||||
// History stores build commands that were used to create an image
|
// History stores build commands that were used to create an image
|
||||||
type History struct {
|
type History struct {
|
||||||
// Created timestamp for build point
|
// Created is the timestamp at which the image was created
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
// Author of the build point
|
// Author is the name of the author that was specified when committing the image
|
||||||
Author string `json:"author,omitempty"`
|
Author string `json:"author,omitempty"`
|
||||||
// CreatedBy keeps the Dockerfile command used while building image.
|
// CreatedBy keeps the Dockerfile command used while building the image
|
||||||
CreatedBy string `json:"created_by,omitempty"`
|
CreatedBy string `json:"created_by,omitempty"`
|
||||||
// Comment is custom message set by the user when creating the image.
|
// Comment is the commit message that was set when committing the image
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
// EmptyLayer is set to true if this history item did not generate a
|
// EmptyLayer is set to true if this history item did not generate a
|
||||||
// layer. Otherwise, the history item is associated with the next
|
// layer. Otherwise, the history item is associated with the next
|
||||||
|
@ -126,7 +126,7 @@ type History struct {
|
||||||
EmptyLayer bool `json:"empty_layer,omitempty"`
|
EmptyLayer bool `json:"empty_layer,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exporter provides interface for exporting and importing images
|
// Exporter provides interface for loading and saving images
|
||||||
type Exporter interface {
|
type Exporter interface {
|
||||||
Load(io.ReadCloser, io.Writer, bool) error
|
Load(io.ReadCloser, io.Writer, bool) error
|
||||||
// TODO: Load(net.Context, io.ReadCloser, <- chan StatusMessage) error
|
// TODO: Load(net.Context, io.ReadCloser, <- chan StatusMessage) error
|
||||||
|
@ -141,7 +141,7 @@ func NewFromJSON(src []byte) (*Image, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if img.RootFS == nil {
|
if img.RootFS == nil {
|
||||||
return nil, errors.New("Invalid image JSON, no RootFS key.")
|
return nil, errors.New("invalid image JSON, no RootFS key")
|
||||||
}
|
}
|
||||||
|
|
||||||
img.rawJSON = src
|
img.rawJSON = src
|
||||||
|
|
|
@ -24,14 +24,14 @@ func TestJSON(t *testing.T) {
|
||||||
}
|
}
|
||||||
rawJSON := img.RawJSON()
|
rawJSON := img.RawJSON()
|
||||||
if string(rawJSON) != sampleImageJSON {
|
if string(rawJSON) != sampleImageJSON {
|
||||||
t.Fatalf("Raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON)
|
t.Fatalf("raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidJSON(t *testing.T) {
|
func TestInvalidJSON(t *testing.T) {
|
||||||
_, err := NewFromJSON([]byte("{}"))
|
_, err := NewFromJSON([]byte("{}"))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected JSON parse error")
|
t.Fatal("expected JSON parse error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ type LogImageEvent interface {
|
||||||
LogImageEvent(imageID, refName, action string)
|
LogImageEvent(imageID, refName, action string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTarExporter returns new ImageExporter for tar packages
|
// NewTarExporter returns new Exporter for tar packages
|
||||||
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, loggerImgEvent LogImageEvent) image.Exporter {
|
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, loggerImgEvent LogImageEvent) image.Exporter {
|
||||||
return &tarexporter{
|
return &tarexporter{
|
||||||
is: is,
|
is: is,
|
||||||
|
|
Loading…
Add table
Reference in a new issue