func TestEmptyTarSumDigest(t *testing.T) {
	// An empty tar archive is exactly 1024 zero bytes.
	zeroBlock := make([]byte, 1024)

	ts, err := NewDigest(Version1)
	if err != nil {
		t.Fatal(err)
	}

	n, err := io.Copy(ts, bytes.NewReader(zeroBlock))
	if err != nil {
		t.Fatal(err)
	}
	if n != int64(len(zeroBlock)) {
		t.Fatalf("tarSum did not write the correct number of zeroed bytes: %d", n)
	}

	expectedSum := sha256.New().Sum(nil)
	resultSum := ts.Sum(nil)

	if !bytes.Equal(resultSum, expectedSum) {
		t.Fatalf("expected [%x] but got [%x]", expectedSum, resultSum)
	}

	// Ensure that we finished.
	if !ts.Finished() {
		t.Error("tarSum digest is not finished when it shoud be!")
	}

	// Test without ever actually writing anything.
	ts, err = NewDigest(Version1)
	if err != nil {
		t.Fatal(err)
	}

	resultSum = ts.Sum(nil)

	if !bytes.Equal(resultSum, expectedSum) {
		t.Fatalf("expected [%s] but got [%s]", expectedSum, resultSum)
	}
}
// TestEmptyTarSumDigest tests that tarsum digest does not fail to read
// an empty tar and correctly returns the hex digest of an empty hash.
TestEmptyTarSumDigest tests that tarsum digest does not fail to read
an empty tar and correctly returns the hex digest of an empty hash.
// TestEmptyTarSumDigest tests that tarsum digest does not fail to read // an empty tar and correctly returns the hex digest of an empty hash .
func TestEmptyTarSumDigest(t *testing.T) {
	zeroBlock := make([]byte, 1024)
	ts, err := NewDigest(Version1)
	if err != nil {
		t.Fatal(err)
	}
	n, err := io.Copy(ts, bytes.NewReader(zeroBlock))
	if err != nil {
		t.Fatal(err)
	}
	if n != int64(len(zeroBlock)) {
		t.Fatalf("tarSum did not write the correct number of zeroed bytes: %d", n)
	}
	expectedSum := sha256.New().Sum(nil)
	resultSum := ts.Sum(nil)
	if !bytes.Equal(resultSum, expectedSum) {
		t.Fatalf("expected [%x] but got [%x]", expectedSum, resultSum)
	}
	if !ts.Finished() {
		t.Error("tarSum digest is not finished when it shoud be!")
	}
	ts, err = NewDigest(Version1)
	if err != nil {
		t.Fatal(err)
	}
	resultSum = ts.Sum(nil)
	if !bytes.Equal(resultSum, expectedSum) {
		t.Fatalf("expected [%s] but got [%s]", expectedSum, resultSum)
	}
}
func TestEmptyTarSumDigest ( t * testing . T ) { zeroBlock := make ( [ ] byte , 1024 ) ts , err := NewDigest ( Version1 ) if err != nil { t . Fatal ( err ) } n , err := io . Copy ( ts , bytes . NewReader ( zeroBlock ) ) if err != nil { t . Fatal ( err ) } if n != int64 ( len ( zeroBlock ) ) { t . Fatalf ( " " , n ) } expectedSum := sha256 . New ( ) . Sum ( nil ) resultSum := ts . Sum ( nil ) if ! bytes . Equal ( resultSum , expectedSum ) { t . Fatalf ( " " , expectedSum , resultSum ) } if ! ts . Finished ( ) { t . Error ( " " ) } ts , err = NewDigest ( Version1 ) if err != nil { t . Fatal ( err ) } resultSum = ts . Sum ( nil ) if ! bytes . Equal ( resultSum , expectedSum ) { t . Fatalf ( " " , expectedSum , resultSum ) } }
TestEmptyTarSumDigest tests that tarsum digest does not fail to read
an empty tar and correctly returns the hex digest of an empty hash.
TestEmptyTarSumDigest tests that tarsum digest does not fail to read an empty tar and correctly returns the hex digest of an empty hash .
// An empty tar archive is exactly 1024 zero bytes. // Ensure that we finished. // Test without ever actually writing anything.