ソースを参照

Fix tests after Hash() behavior change

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 8 年 前
コミット
d5b15f0d3e
2 ファイル変更9 行追加15 行削除
  1. 2 0
      builder/remotecontext/lazycontext.go
  2. 7 15
      builder/remotecontext/tarsum_test.go

+ 2 - 0
builder/remotecontext/lazycontext.go

@@ -47,6 +47,8 @@ func (c *lazySource) Hash(path string) (string, error) {
 
 
 	fi, err := os.Lstat(fullPath)
 	fi, err := os.Lstat(fullPath)
 	if err != nil {
 	if err != nil {
+		// Backwards compatibility: a missing file returns a path as hash.
+		// This is reached in the case of a broken symlink.
 		return relPath, nil
 		return relPath, nil
 	}
 	}
 
 

+ 7 - 15
builder/remotecontext/tarsum_test.go

@@ -104,17 +104,6 @@ func TestHashSubdir(t *testing.T) {
 	}
 	}
 }
 }
 
 
-func TestStatNotExisting(t *testing.T) {
-	contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
-	defer cleanup()
-
-	src := makeTestArchiveContext(t, contextDir)
-	_, err := src.Hash("not-existing")
-	if !os.IsNotExist(errors.Cause(err)) {
-		t.Fatalf("This file should not exist: %s", err)
-	}
-}
-
 func TestRemoveDirectory(t *testing.T) {
 func TestRemoveDirectory(t *testing.T) {
 	contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
 	contextDir, cleanup := createTestTempDir(t, "", "builder-tarsum-test")
 	defer cleanup()
 	defer cleanup()
@@ -129,17 +118,20 @@ func TestRemoveDirectory(t *testing.T) {
 
 
 	src := makeTestArchiveContext(t, contextDir)
 	src := makeTestArchiveContext(t, contextDir)
 
 
-	tarSum := src.(modifiableContext)
+	_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
+	if err != nil {
+		t.Fatalf("Statting %s shouldn't fail: %+v", relativePath, err)
+	}
 
 
+	tarSum := src.(modifiableContext)
 	err = tarSum.Remove(relativePath)
 	err = tarSum.Remove(relativePath)
 	if err != nil {
 	if err != nil {
 		t.Fatalf("Error when executing Remove: %s", err)
 		t.Fatalf("Error when executing Remove: %s", err)
 	}
 	}
 
 
-	_, err = src.Hash(contextSubdir)
-
+	_, err = src.Root().Stat(src.Root().Join(src.Root().Path(), relativePath))
 	if !os.IsNotExist(errors.Cause(err)) {
 	if !os.IsNotExist(errors.Cause(err)) {
-		t.Fatal("Directory should not exist at this point")
+		t.Fatalf("Directory should not exist at this point: %+v ", err)
 	}
 	}
 }
 }