Browse code

Fix TarSum iteration test

I noticed that 3 of the tarsum test cases had expected a tarsum with
a sha256 hash of
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
As I've been working with sha256 quite a bit lately, it struck me that
this is the initial digest value for sha256, which means that no data
was processed. However, these tests *do* process data. It turns out that
there was a bug in the test handling code which did not wait for tarsum
to end completely. This patch corrects these test cases.

I'm unaware of anywhere else in the code base where this would be an issue,
though we definitily need to look out in the future to ensure we are
completing tarsum reads (waiting for EOF).

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)

Josh Hawn authored on 2014/12/03 08:23:49
Showing 1 changed files
... ...
@@ -337,7 +337,7 @@ func TestIteration(t *testing.T) {
337 337
 		data        []byte
338 338
 	}{
339 339
 		{
340
-			"tarsum+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
340
+			"tarsum+sha256:626c4a2e9a467d65c33ae81f7f3dedd4de8ccaee72af73223c4bc4718cbc7bbd",
341 341
 			Version0,
342 342
 			&tar.Header{
343 343
 				Name:     "file.txt",
... ...
@@ -349,7 +349,7 @@ func TestIteration(t *testing.T) {
349 349
 			[]byte(""),
350 350
 		},
351 351
 		{
352
-			"tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
352
+			"tarsum.dev+sha256:6ffd43a1573a9913325b4918e124ee982a99c0f3cba90fc032a65f5e20bdd465",
353 353
 			VersionDev,
354 354
 			&tar.Header{
355 355
 				Name:     "file.txt",
... ...
@@ -361,7 +361,7 @@ func TestIteration(t *testing.T) {
361 361
 			[]byte(""),
362 362
 		},
363 363
 		{
364
-			"tarsum.dev+sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
364
+			"tarsum.dev+sha256:b38166c059e11fb77bef30bf16fba7584446e80fcc156ff46d47e36c5305d8ef",
365 365
 			VersionDev,
366 366
 			&tar.Header{
367 367
 				Name:     "another.txt",
... ...
@@ -463,6 +463,7 @@ func renderSumForHeader(v Version, h *tar.Header, data []byte) (string, error) {
463 463
 	for {
464 464
 		hdr, err := tr.Next()
465 465
 		if hdr == nil || err == io.EOF {
466
+			// Signals the end of the archive.
466 467
 			break
467 468
 		}
468 469
 		if err != nil {
... ...
@@ -471,7 +472,6 @@ func renderSumForHeader(v Version, h *tar.Header, data []byte) (string, error) {
471 471
 		if _, err = io.Copy(ioutil.Discard, tr); err != nil {
472 472
 			return "", err
473 473
 		}
474
-		break // we're just reading one header ...
475 474
 	}
476 475
 	return ts.Sum(nil), nil
477 476
 }