Browse code

Fix tests after Hash() behavior change

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2017/07/27 08:23:31
Showing 2 changed files
... ...
@@ -47,6 +47,8 @@ func (c *lazySource) Hash(path string) (string, error) {
47 47
 
48 48
 	fi, err := os.Lstat(fullPath)
49 49
 	if err != nil {
50
+		// Backwards compatibility: a missing file returns a path as hash.
51
+		// This is reached in the case of a broken symlink.
50 52
 		return relPath, nil
51 53
 	}
52 54
 
... ...
@@ -104,17 +104,6 @@ func TestHashSubdir(t *testing.T) {
104 104
 	}
105 105
 }
106 106
 
107
-func TestStatNotExisting(t *testing.T) {
108
-	contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
109
-	defer cleanup()
110
-
111
-	src := makeTestArchiveContext(t, contextDir)
112
-	_, err := src.Hash("not-existing")
113
-	if !os.IsNotExist(errors.Cause(err)) {
114
-		t.Fatalf("This file should not exist: %s", err)
115
-	}
116
-}
117
-
118 107
 func TestRemoveDirectory(t *testing.T) {
119 108
 	contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
120 109
 	defer cleanup()
... ...
@@ -129,17 +118,20 @@ func TestRemoveDirectory(t *testing.T) {
129 129
 
130 130
 	src := makeTestArchiveContext(t, contextDir)
131 131
 
132
-	tarSum := src.(modifiableContext)
132
+	_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
133
+	if err != nil {
134
+		t.Fatalf("Statting %s shouldn't fail: %+v", relativePath, err)
135
+	}
133 136
 
137
+	tarSum := src.(modifiableContext)
134 138
 	err = tarSum.Remove(relativePath)
135 139
 	if err != nil {
136 140
 		t.Fatalf("Error when executing Remove: %s", err)
137 141
 	}
138 142
 
139
-	_, err = src.Hash(contextSubdir)
140
-
143
+	_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
141 144
 	if !os.IsNotExist(errors.Cause(err)) {
142
-		t.Fatal("Directory should not exist at this point")
145
+		t.Fatalf("Directory should not exist at this point: %+v ", err)
143 146
 	}
144 147
 }
145 148