From 80a449f5419cf1d83e2d1d5cc1a17f78374af53d Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Fri, 7 Sep 2018 16:03:56 -0700 Subject: [PATCH] code review comments --- pkg/snapshot/layered_map.go | 9 +++++---- pkg/snapshot/layered_map_test.go | 11 ++++++----- pkg/util/util.go | 5 ++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/snapshot/layered_map.go b/pkg/snapshot/layered_map.go index c922bbafc..9a356b0e2 100644 --- a/pkg/snapshot/layered_map.go +++ b/pkg/snapshot/layered_map.go @@ -27,10 +27,11 @@ import ( ) type LayeredMap struct { - layers []map[string]string - whiteouts []map[string]string - added []map[string]string - hasher func(string) (string, error) + layers []map[string]string + whiteouts []map[string]string + added []map[string]string + hasher func(string) (string, error) + // cacheHasher doesn't include mtime in it's hash so that filesystem cache keys are stable cacheHasher func(string) (string, error) } diff --git a/pkg/snapshot/layered_map_test.go b/pkg/snapshot/layered_map_test.go index e5ea64f02..6bfff81b3 100644 --- a/pkg/snapshot/layered_map_test.go +++ b/pkg/snapshot/layered_map_test.go @@ -32,11 +32,15 @@ func Test_CacheKey(t *testing.T) { "a": "apple", "b": "bat", "c": "cat", + "d": "dog", + "e": "egg", }, map2: map[string]string{ "c": "cat", + "d": "dog", "b": "bat", "a": "apple", + "e": "egg", }, equal: true, }, @@ -67,11 +71,8 @@ func Test_CacheKey(t *testing.T) { if err != nil { t.Fatalf("error getting key for map 2: %v", err) } - if test.equal && k1 != k2 { - t.Fatalf("keys differ.\nExpected\n%+v\nActual\n%+v", k1, k2) - } - if !test.equal && k1 == k2 { - t.Fatal("keys are the same, expected different keys") + if test.equal != (k1 == k2) { + t.Fatalf("unexpected result: \nExpected\n%s\nActual\n%s\n", k1, k2) } }) } diff --git a/pkg/util/util.go b/pkg/util/util.go index bc09a7c27..873cbae20 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -122,5 +122,8 @@ func MtimeHasher() func(string) (string, error) { func SHA256(r io.Reader) (string, error) { hasher := sha256.New() _, err := io.Copy(hasher, r) - return hex.EncodeToString(hasher.Sum(make([]byte, 0, hasher.Size()))), err + if err != nil { + return "", err + } + return hex.EncodeToString(hasher.Sum(make([]byte, 0, hasher.Size()))), nil }