code review comments

This commit is contained in:
Priya Wadhwa
2018-09-07 16:03:56 -07:00
parent 13accbaf32
commit 80a449f541
3 changed files with 15 additions and 10 deletions
+5 -4
View File
@@ -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)
}
+6 -5
View File
@@ -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)
}
})
}
+4 -1
View File
@@ -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
}