Browse code

Fix incorrect info and format of error in image

Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>

yuexiao-wang authored on 2016/12/13 23:15:08
Showing 5 changed files
... ...
@@ -75,7 +75,7 @@ func (s *fs) Walk(f DigestWalkFunc) error {
75 75
 	for _, v := range dir {
76 76
 		dgst := digest.NewDigestFromHex(string(digest.Canonical), v.Name())
77 77
 		if err := dgst.Validate(); err != nil {
78
-			logrus.Debugf("Skipping invalid digest %s: %s", dgst, err)
78
+			logrus.Debugf("skipping invalid digest %s: %s", dgst, err)
79 79
 			continue
80 80
 		}
81 81
 		if err := f(dgst); err != nil {
... ...
@@ -113,7 +113,7 @@ func (s *fs) Set(data []byte) (digest.Digest, error) {
113 113
 	defer s.Unlock()
114 114
 
115 115
 	if len(data) == 0 {
116
-		return "", fmt.Errorf("Invalid empty data")
116
+		return "", fmt.Errorf("invalid empty data")
117 117
 	}
118 118
 
119 119
 	dgst := digest.FromBytes(data)
... ...
@@ -52,7 +52,7 @@ func TestFSGetInvalidData(t *testing.T) {
52 52
 
53 53
 	_, err = fs.Get(id)
54 54
 	if err == nil {
55
-		t.Fatal("Expected get to fail after data modification.")
55
+		t.Fatal("expected get to fail after data modification.")
56 56
 	}
57 57
 }
58 58
 
... ...
@@ -75,7 +75,7 @@ func TestFSInvalidSet(t *testing.T) {
75 75
 
76 76
 	_, err = fs.Set([]byte("foobar"))
77 77
 	if err == nil {
78
-		t.Fatal("Expecting error from invalid filesystem data.")
78
+		t.Fatal("expected error from invalid filesystem data.")
79 79
 	}
80 80
 }
81 81
 
... ...
@@ -109,7 +109,7 @@ func TestFSInvalidRoot(t *testing.T) {
109 109
 
110 110
 		_, err = NewFSStoreBackend(root)
111 111
 		if err == nil {
112
-			t.Fatalf("Expected error from root %q and invlid file %q", tc.root, tc.invalidFile)
112
+			t.Fatalf("expected error from root %q and invalid file %q", tc.root, tc.invalidFile)
113 113
 		}
114 114
 
115 115
 		os.RemoveAll(root)
... ...
@@ -154,18 +154,18 @@ func testMetadataGetSet(t *testing.T, store StoreBackend) {
154 154
 
155 155
 	_, err = store.GetMetadata(id2, "tkey2")
156 156
 	if err == nil {
157
-		t.Fatal("Expected error for getting metadata for unknown key")
157
+		t.Fatal("expected error for getting metadata for unknown key")
158 158
 	}
159 159
 
160 160
 	id3 := digest.FromBytes([]byte("baz"))
161 161
 	err = store.SetMetadata(id3, "tkey", []byte("tval"))
162 162
 	if err == nil {
163
-		t.Fatal("Expected error for setting metadata for unknown ID.")
163
+		t.Fatal("expected error for setting metadata for unknown ID.")
164 164
 	}
165 165
 
166 166
 	_, err = store.GetMetadata(id3, "tkey")
167 167
 	if err == nil {
168
-		t.Fatal("Expected error for getting metadata for unknown ID.")
168
+		t.Fatal("expected error for getting metadata for unknown ID.")
169 169
 	}
170 170
 }
171 171
 
... ...
@@ -234,16 +234,16 @@ func TestFSInvalidWalker(t *testing.T) {
234 234
 	n := 0
235 235
 	err = fs.Walk(func(id digest.Digest) error {
236 236
 		if id != fooID {
237
-			t.Fatalf("Invalid walker ID %q, expected %q", id, fooID)
237
+			t.Fatalf("invalid walker ID %q, expected %q", id, fooID)
238 238
 		}
239 239
 		n++
240 240
 		return nil
241 241
 	})
242 242
 	if err != nil {
243
-		t.Fatalf("Invalid data should not have caused walker error, got %v", err)
243
+		t.Fatalf("invalid data should not have caused walker error, got %v", err)
244 244
 	}
245 245
 	if n != 1 {
246
-		t.Fatalf("Expected 1 walk initialization, got %d", n)
246
+		t.Fatalf("expected 1 walk initialization, got %d", n)
247 247
 	}
248 248
 }
249 249
 
... ...
@@ -261,7 +261,7 @@ func testGetSet(t *testing.T, store StoreBackend) {
261 261
 	if err != nil {
262 262
 		t.Fatal(err)
263 263
 	}
264
-	// skipping use of digest pkg because its used by the implementation
264
+	// skipping use of digest pkg because it is used by the implementation
265 265
 	h := sha256.New()
266 266
 	_, err = h.Write(randomInput)
267 267
 	if err != nil {
... ...
@@ -278,14 +278,14 @@ func testGetSet(t *testing.T, store StoreBackend) {
278 278
 			t.Fatal(err)
279 279
 		}
280 280
 		if id != tc.expected {
281
-			t.Fatalf("Expected ID %q, got %q", tc.expected, id)
281
+			t.Fatalf("expected ID %q, got %q", tc.expected, id)
282 282
 		}
283 283
 	}
284 284
 
285 285
 	for _, emptyData := range [][]byte{nil, {}} {
286 286
 		_, err := store.Set(emptyData)
287 287
 		if err == nil {
288
-			t.Fatal("Expected error for nil input.")
288
+			t.Fatal("expected error for nil input.")
289 289
 		}
290 290
 	}
291 291
 
... ...
@@ -295,14 +295,14 @@ func testGetSet(t *testing.T, store StoreBackend) {
295 295
 			t.Fatal(err)
296 296
 		}
297 297
 		if bytes.Compare(data, tc.input) != 0 {
298
-			t.Fatalf("Expected data %q, got %q", tc.input, data)
298
+			t.Fatalf("expected data %q, got %q", tc.input, data)
299 299
 		}
300 300
 	}
301 301
 
302 302
 	for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} {
303 303
 		_, err := store.Get(key)
304 304
 		if err == nil {
305
-			t.Fatalf("Expected error for ID %q.", key)
305
+			t.Fatalf("expected error for ID %q.", key)
306 306
 		}
307 307
 	}
308 308
 
... ...
@@ -325,7 +325,7 @@ func testDelete(t *testing.T, store StoreBackend) {
325 325
 
326 326
 	_, err = store.Get(id)
327 327
 	if err == nil {
328
-		t.Fatalf("Expected getting deleted item %q to fail", id)
328
+		t.Fatalf("expected getting deleted item %q to fail", id)
329 329
 	}
330 330
 	_, err = store.Get(id2)
331 331
 	if err != nil {
... ...
@@ -338,7 +338,7 @@ func testDelete(t *testing.T, store StoreBackend) {
338 338
 	}
339 339
 	_, err = store.Get(id2)
340 340
 	if err == nil {
341
-		t.Fatalf("Expected getting deleted item %q to fail", id2)
341
+		t.Fatalf("expected getting deleted item %q to fail", id2)
342 342
 	}
343 343
 }
344 344
 
... ...
@@ -366,10 +366,10 @@ func testWalker(t *testing.T, store StoreBackend) {
366 366
 	}
367 367
 
368 368
 	if n != 2 {
369
-		t.Fatalf("Expected 2 walk initializations, got %d", n)
369
+		t.Fatalf("expected 2 walk initializations, got %d", n)
370 370
 	}
371 371
 	if len(tcases) != 0 {
372
-		t.Fatalf("Expected empty unwalked set, got %+v", tcases)
372
+		t.Fatalf("expected empty unwalked set, got %+v", tcases)
373 373
 	}
374 374
 
375 375
 	// stop on error
... ...
@@ -379,6 +379,6 @@ func testWalker(t *testing.T, store StoreBackend) {
379 379
 		return errors.New("")
380 380
 	})
381 381
 	if err == nil {
382
-		t.Fatalf("Exected error from walker.")
382
+		t.Fatalf("expected error from walker.")
383 383
 	}
384 384
 }
... ...
@@ -29,21 +29,21 @@ func IDFromDigest(digest digest.Digest) ID {
29 29
 
30 30
 // V1Image stores the V1 image configuration.
31 31
 type V1Image struct {
32
-	// ID a unique 64 character identifier of the image
32
+	// ID is a unique 64 character identifier of the image
33 33
 	ID string `json:"id,omitempty"`
34
-	// Parent id of the image
34
+	// Parent is the ID of the parent image
35 35
 	Parent string `json:"parent,omitempty"`
36
-	// Comment user added comment
36
+	// Comment is the commit message that was set when committing the image
37 37
 	Comment string `json:"comment,omitempty"`
38
-	// Created timestamp when image was created
38
+	// Created is the timestamp at which the image was created
39 39
 	Created time.Time `json:"created"`
40 40
 	// Container is the id of the container used to commit
41 41
 	Container string `json:"container,omitempty"`
42 42
 	// ContainerConfig is the configuration of the container that is committed into the image
43 43
 	ContainerConfig container.Config `json:"container_config,omitempty"`
44
-	// DockerVersion specifies version on which image is built
44
+	// DockerVersion specifies the version of Docker that was used to build the image
45 45
 	DockerVersion string `json:"docker_version,omitempty"`
46
-	// Author of the image
46
+	// Author is the name of the author that was specified when committing the image
47 47
 	Author string `json:"author,omitempty"`
48 48
 	// Config is the configuration of the container received from the client
49 49
 	Config *container.Config `json:"config,omitempty"`
... ...
@@ -112,13 +112,13 @@ func (img *Image) MarshalJSON() ([]byte, error) {
112 112
 
113 113
 // History stores build commands that were used to create an image
114 114
 type History struct {
115
-	// Created timestamp for build point
115
+	// Created is the timestamp at which the image was created
116 116
 	Created time.Time `json:"created"`
117
-	// Author of the build point
117
+	// Author is the name of the author that was specified when committing the image
118 118
 	Author string `json:"author,omitempty"`
119
-	// CreatedBy keeps the Dockerfile command used while building image.
119
+	// CreatedBy keeps the Dockerfile command used while building the image
120 120
 	CreatedBy string `json:"created_by,omitempty"`
121
-	// Comment is custom message set by the user when creating the image.
121
+	// Comment is the commit message that was set when committing the image
122 122
 	Comment string `json:"comment,omitempty"`
123 123
 	// EmptyLayer is set to true if this history item did not generate a
124 124
 	// layer. Otherwise, the history item is associated with the next
... ...
@@ -126,7 +126,7 @@ type History struct {
126 126
 	EmptyLayer bool `json:"empty_layer,omitempty"`
127 127
 }
128 128
 
129
-// Exporter provides interface for exporting and importing images
129
+// Exporter provides interface for loading and saving images
130 130
 type Exporter interface {
131 131
 	Load(io.ReadCloser, io.Writer, bool) error
132 132
 	// TODO: Load(net.Context, io.ReadCloser, <- chan StatusMessage) error
... ...
@@ -141,7 +141,7 @@ func NewFromJSON(src []byte) (*Image, error) {
141 141
 		return nil, err
142 142
 	}
143 143
 	if img.RootFS == nil {
144
-		return nil, errors.New("Invalid image JSON, no RootFS key.")
144
+		return nil, errors.New("invalid image JSON, no RootFS key")
145 145
 	}
146 146
 
147 147
 	img.rawJSON = src
... ...
@@ -24,14 +24,14 @@ func TestJSON(t *testing.T) {
24 24
 	}
25 25
 	rawJSON := img.RawJSON()
26 26
 	if string(rawJSON) != sampleImageJSON {
27
-		t.Fatalf("Raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON)
27
+		t.Fatalf("raw JSON of config didn't match: expected %+v, got %v", sampleImageJSON, rawJSON)
28 28
 	}
29 29
 }
30 30
 
31 31
 func TestInvalidJSON(t *testing.T) {
32 32
 	_, err := NewFromJSON([]byte("{}"))
33 33
 	if err == nil {
34
-		t.Fatal("Expected JSON parse error")
34
+		t.Fatal("expected JSON parse error")
35 35
 	}
36 36
 }
37 37
 
... ...
@@ -36,7 +36,7 @@ type LogImageEvent interface {
36 36
 	LogImageEvent(imageID, refName, action string)
37 37
 }
38 38
 
39
-// NewTarExporter returns new ImageExporter for tar packages
39
+// NewTarExporter returns new Exporter for tar packages
40 40
 func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, loggerImgEvent LogImageEvent) image.Exporter {
41 41
 	return &tarexporter{
42 42
 		is:             is,