Make tests independent of host state
This commit is contained in:
@@ -47,18 +47,16 @@ func TestPlanDestination(t *testing.T) {
|
||||
assertDestinationErrorKind(t, workingDirectory, string(os.PathSeparator), false, DestinationFilesystemRoot)
|
||||
assertDestinationErrorKind(t, workingDirectory, "relative", false, DestinationInvalidPath)
|
||||
|
||||
link := filepath.Join(workingDirectory, "link")
|
||||
if err := os.Symlink(empty, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertDestinationErrorKind(t, workingDirectory, link, false, DestinationSymlink)
|
||||
t.Run("symbolic links", func(t *testing.T) {
|
||||
link := filepath.Join(workingDirectory, "link")
|
||||
requireSymlink(t, empty, link)
|
||||
assertDestinationErrorKind(t, workingDirectory, link, false, DestinationSymlink)
|
||||
|
||||
dangling := filepath.Join(workingDirectory, "dangling")
|
||||
if err := os.Symlink(filepath.Join(workingDirectory, "missing"), dangling); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertDestinationErrorKind(t, workingDirectory, dangling, false, DestinationSymlink)
|
||||
assertDestinationErrorKind(t, workingDirectory, filepath.Join(dangling, "child"), false, DestinationInspection)
|
||||
dangling := filepath.Join(workingDirectory, "dangling")
|
||||
requireSymlink(t, filepath.Join(workingDirectory, "missing"), dangling)
|
||||
assertDestinationErrorKind(t, workingDirectory, dangling, false, DestinationSymlink)
|
||||
assertDestinationErrorKind(t, workingDirectory, filepath.Join(dangling, "child"), false, DestinationInspection)
|
||||
})
|
||||
|
||||
nonempty := filepath.Join(workingDirectory, "nonempty")
|
||||
if err := os.Mkdir(nonempty, 0o755); err != nil {
|
||||
@@ -116,9 +114,7 @@ func TestRecognizeBundleRejectsUnsafeAndMalformedContents(t *testing.T) {
|
||||
if err := os.Remove(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(filepath.Join(directory, DataPackageFilename), path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
requireSymlink(t, filepath.Join(directory, DataPackageFilename), path)
|
||||
}},
|
||||
{name: "digest mismatch", mutate: func(t *testing.T, directory string) {
|
||||
t.Helper()
|
||||
@@ -298,9 +294,7 @@ func TestPublishReauthorizesMovedDestination(t *testing.T) {
|
||||
},
|
||||
mutate: func(t *testing.T, target string) {
|
||||
t.Helper()
|
||||
if err := os.Symlink("unrelated-target", target); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
requireSymlink(t, "unrelated-target", target)
|
||||
},
|
||||
verify: func(t *testing.T, target string) {
|
||||
t.Helper()
|
||||
@@ -365,6 +359,13 @@ func TestPublishReauthorizesMovedDestination(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func requireSymlink(t *testing.T, target string, link string) {
|
||||
t.Helper()
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
t.Skipf("symlink support is unavailable: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishRetainsUnauthorizedMovedDestinationWhenRestoreFails(t *testing.T) {
|
||||
workingDirectory := t.TempDir()
|
||||
target := filepath.Join(workingDirectory, "comparison-daily")
|
||||
|
||||
Reference in New Issue
Block a user