From 3e658d29a667dee19e4e35e578fd0274a7df221b Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Tue, 10 Mar 2015 14:40:58 -0700 Subject: [PATCH] digest: Minor refactoring Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) --- docs/handlers/api_test.go | 5 ++++- docs/storage/filereader_test.go | 6 +++++- docs/storage/filewriter_test.go | 18 +++++++++++++++--- docs/storage/layerupload.go | 5 ++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/handlers/api_test.go b/docs/handlers/api_test.go index 22f2d9ca..ab8187c1 100644 --- a/docs/handlers/api_test.go +++ b/docs/handlers/api_test.go @@ -236,7 +236,10 @@ func TestLayerAPI(t *testing.T) { }) // Verify the body - verifier := digest.NewDigestVerifier(layerDigest) + verifier, err := digest.NewDigestVerifier(layerDigest) + if err != nil { + t.Fatalf("unexpected error getting digest verifier: %s", err) + } io.Copy(verifier, resp.Body) if !verifier.Verified() { diff --git a/docs/storage/filereader_test.go b/docs/storage/filereader_test.go index 7c554e8b..8a077603 100644 --- a/docs/storage/filereader_test.go +++ b/docs/storage/filereader_test.go @@ -41,7 +41,11 @@ func TestSimpleRead(t *testing.T) { t.Fatalf("error allocating file reader: %v", err) } - verifier := digest.NewDigestVerifier(dgst) + verifier, err := digest.NewDigestVerifier(dgst) + if err != nil { + t.Fatalf("error getting digest verifier: %s", err) + } + io.Copy(verifier, fr) if !verifier.Verified() { diff --git a/docs/storage/filewriter_test.go b/docs/storage/filewriter_test.go index 06db31f3..a8ea6241 100644 --- a/docs/storage/filewriter_test.go +++ b/docs/storage/filewriter_test.go @@ -55,7 +55,11 @@ func TestSimpleWrite(t *testing.T) { } defer fr.Close() - verifier := digest.NewDigestVerifier(dgst) + verifier, err := digest.NewDigestVerifier(dgst) + if err != nil { + t.Fatalf("unexpected error getting digest verifier: %s", err) + } + io.Copy(verifier, fr) if !verifier.Verified() { @@ -94,7 +98,11 @@ func TestSimpleWrite(t *testing.T) { } defer fr.Close() - verifier = digest.NewDigestVerifier(doubledgst) + verifier, err = digest.NewDigestVerifier(doubledgst) + if err != nil { + t.Fatalf("unexpected error getting digest verifier: %s", err) + } + io.Copy(verifier, fr) if !verifier.Verified() { @@ -141,7 +149,11 @@ func TestSimpleWrite(t *testing.T) { } defer fr.Close() - verifier = digest.NewDigestVerifier(doubledgst) + verifier, err = digest.NewDigestVerifier(doubledgst) + if err != nil { + t.Fatalf("unexpected error getting digest verifier: %s", err) + } + io.Copy(verifier, fr) if !verifier.Verified() { diff --git a/docs/storage/layerupload.go b/docs/storage/layerupload.go index 69b547f5..fdb00e93 100644 --- a/docs/storage/layerupload.go +++ b/docs/storage/layerupload.go @@ -85,7 +85,10 @@ func (luc *layerUploadController) Cancel() error { // validateLayer checks the layer data against the digest, returning an error // if it does not match. The canonical digest is returned. func (luc *layerUploadController) validateLayer(dgst digest.Digest) (digest.Digest, error) { - digestVerifier := digest.NewDigestVerifier(dgst) + digestVerifier, err := digest.NewDigestVerifier(dgst) + if err != nil { + return "", err + } // TODO(stevvooe): Store resumable hash calculations in upload directory // in driver. Something like a file at path /resumablehash/