Make tests independent of host state
This commit is contained in:
@@ -508,6 +508,7 @@ func TestNewValidatesConfiguration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalBackendAndMissingCredentialBehavior(t *testing.T) {
|
func TestLocalBackendAndMissingCredentialBehavior(t *testing.T) {
|
||||||
|
t.Setenv("WEATHERREPORTER_TEST_MISSING_KEY", "")
|
||||||
profiles := testProfileDirectory(t, `id: local-profile
|
profiles := testProfileDirectory(t, `id: local-profile
|
||||||
backend: local
|
backend: local
|
||||||
model: local-model
|
model: local-model
|
||||||
|
|||||||
@@ -510,9 +510,7 @@ func TestGenerateDetailedDoesNotReplaceSymbolicLinkOutput(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
outputPath := filepath.Join(dir, "daily.md")
|
outputPath := filepath.Join(dir, "daily.md")
|
||||||
if err := os.Symlink(backing, outputPath); err != nil {
|
requireSymlink(t, backing, outputPath)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
bundle := generationBundle(t)
|
bundle := generationBundle(t)
|
||||||
collector := &generationCollector{bundle: &bundle}
|
collector := &generationCollector{bundle: &bundle}
|
||||||
executor := &generationExecutor{}
|
executor := &generationExecutor{}
|
||||||
|
|||||||
@@ -46,9 +46,7 @@ func TestResolveComparisonOutputDirectory(t *testing.T) {
|
|||||||
func TestResolveOutputDirRejectsDanglingSymlinkComponents(t *testing.T) {
|
func TestResolveOutputDirRejectsDanglingSymlinkComponents(t *testing.T) {
|
||||||
workingDir := t.TempDir()
|
workingDir := t.TempDir()
|
||||||
dangling := filepath.Join(workingDir, "dangling")
|
dangling := filepath.Join(workingDir, "dangling")
|
||||||
if err := os.Symlink(filepath.Join(workingDir, "missing"), dangling); err != nil {
|
requireSymlink(t, filepath.Join(workingDir, "missing"), dangling)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, directory := range []string{dangling, filepath.Join(dangling, "reports")} {
|
for _, directory := range []string{dangling, filepath.Join(dangling, "reports")} {
|
||||||
t.Run(filepath.Base(directory), func(t *testing.T) {
|
t.Run(filepath.Base(directory), func(t *testing.T) {
|
||||||
@@ -63,9 +61,7 @@ func TestResolveOutputDirAllowsMissingDirectoryBelowValidSymlink(t *testing.T) {
|
|||||||
workingDir := t.TempDir()
|
workingDir := t.TempDir()
|
||||||
target := t.TempDir()
|
target := t.TempDir()
|
||||||
link := filepath.Join(workingDir, "linked")
|
link := filepath.Join(workingDir, "linked")
|
||||||
if err := os.Symlink(target, link); err != nil {
|
requireSymlink(t, target, link)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
directory := filepath.Join(link, "reports")
|
directory := filepath.Join(link, "reports")
|
||||||
got, err := resolveOutputDir(workingDir, directory)
|
got, err := resolveOutputDir(workingDir, directory)
|
||||||
@@ -73,3 +69,10 @@ func TestResolveOutputDirAllowsMissingDirectoryBelowValidSymlink(t *testing.T) {
|
|||||||
t.Fatalf("resolveOutputDir() = %q, %v, want %q, nil", got, err, directory)
|
t.Fatalf("resolveOutputDir() = %q, %v, want %q, nil", got, err, directory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,18 +47,16 @@ func TestPlanDestination(t *testing.T) {
|
|||||||
assertDestinationErrorKind(t, workingDirectory, string(os.PathSeparator), false, DestinationFilesystemRoot)
|
assertDestinationErrorKind(t, workingDirectory, string(os.PathSeparator), false, DestinationFilesystemRoot)
|
||||||
assertDestinationErrorKind(t, workingDirectory, "relative", false, DestinationInvalidPath)
|
assertDestinationErrorKind(t, workingDirectory, "relative", false, DestinationInvalidPath)
|
||||||
|
|
||||||
link := filepath.Join(workingDirectory, "link")
|
t.Run("symbolic links", func(t *testing.T) {
|
||||||
if err := os.Symlink(empty, link); err != nil {
|
link := filepath.Join(workingDirectory, "link")
|
||||||
t.Fatal(err)
|
requireSymlink(t, empty, link)
|
||||||
}
|
assertDestinationErrorKind(t, workingDirectory, link, false, DestinationSymlink)
|
||||||
assertDestinationErrorKind(t, workingDirectory, link, false, DestinationSymlink)
|
|
||||||
|
|
||||||
dangling := filepath.Join(workingDirectory, "dangling")
|
dangling := filepath.Join(workingDirectory, "dangling")
|
||||||
if err := os.Symlink(filepath.Join(workingDirectory, "missing"), dangling); err != nil {
|
requireSymlink(t, filepath.Join(workingDirectory, "missing"), dangling)
|
||||||
t.Fatal(err)
|
assertDestinationErrorKind(t, workingDirectory, dangling, false, DestinationSymlink)
|
||||||
}
|
assertDestinationErrorKind(t, workingDirectory, filepath.Join(dangling, "child"), false, DestinationInspection)
|
||||||
assertDestinationErrorKind(t, workingDirectory, dangling, false, DestinationSymlink)
|
})
|
||||||
assertDestinationErrorKind(t, workingDirectory, filepath.Join(dangling, "child"), false, DestinationInspection)
|
|
||||||
|
|
||||||
nonempty := filepath.Join(workingDirectory, "nonempty")
|
nonempty := filepath.Join(workingDirectory, "nonempty")
|
||||||
if err := os.Mkdir(nonempty, 0o755); err != nil {
|
if err := os.Mkdir(nonempty, 0o755); err != nil {
|
||||||
@@ -116,9 +114,7 @@ func TestRecognizeBundleRejectsUnsafeAndMalformedContents(t *testing.T) {
|
|||||||
if err := os.Remove(path); err != nil {
|
if err := os.Remove(path); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(filepath.Join(directory, DataPackageFilename), path); err != nil {
|
requireSymlink(t, filepath.Join(directory, DataPackageFilename), path)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
{name: "digest mismatch", mutate: func(t *testing.T, directory string) {
|
{name: "digest mismatch", mutate: func(t *testing.T, directory string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
@@ -298,9 +294,7 @@ func TestPublishReauthorizesMovedDestination(t *testing.T) {
|
|||||||
},
|
},
|
||||||
mutate: func(t *testing.T, target string) {
|
mutate: func(t *testing.T, target string) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if err := os.Symlink("unrelated-target", target); err != nil {
|
requireSymlink(t, "unrelated-target", target)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
verify: func(t *testing.T, target string) {
|
verify: func(t *testing.T, target string) {
|
||||||
t.Helper()
|
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) {
|
func TestPublishRetainsUnauthorizedMovedDestinationWhenRestoreFails(t *testing.T) {
|
||||||
workingDirectory := t.TempDir()
|
workingDirectory := t.TempDir()
|
||||||
target := filepath.Join(workingDirectory, "comparison-daily")
|
target := filepath.Join(workingDirectory, "comparison-daily")
|
||||||
|
|||||||
@@ -253,9 +253,7 @@ func TestPromptDebugWriterKeepsWritesAnchoredToOpenedRoot(t *testing.T) {
|
|||||||
if err := os.Rename(root, anchoredRoot); err != nil {
|
if err := os.Rename(root, anchoredRoot); err != nil {
|
||||||
t.Fatalf("replace opened root: %v", err)
|
t.Fatalf("replace opened root: %v", err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(outside, root); err != nil {
|
requireSymlink(t, outside, root)
|
||||||
t.Skipf("symlink creation is unavailable: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
ref := promptDebugRef()
|
ref := promptDebugRef()
|
||||||
ref.RunID = "run-anchored"
|
ref.RunID = "run-anchored"
|
||||||
@@ -307,9 +305,7 @@ func TestPromptDebugWriterRejectsUnsafeRootsAndReferences(t *testing.T) {
|
|||||||
if err := os.Mkdir(target, debugDirectoryMode); err != nil {
|
if err := os.Mkdir(target, debugDirectoryMode); err != nil {
|
||||||
t.Fatalf("create root symlink target: %v", err)
|
t.Fatalf("create root symlink target: %v", err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(target, link); err != nil {
|
requireSymlink(t, target, link)
|
||||||
t.Fatalf("create root symlink: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := NewPromptDebugWriter(link); err == nil {
|
if _, err := NewPromptDebugWriter(link); err == nil {
|
||||||
t.Fatal("NewPromptDebugWriter(symlink) error = nil")
|
t.Fatal("NewPromptDebugWriter(symlink) error = nil")
|
||||||
}
|
}
|
||||||
@@ -334,15 +330,20 @@ func TestPromptDebugWriterRejectsUnsafeRootsAndReferences(t *testing.T) {
|
|||||||
if err := os.Mkdir(outside, debugDirectoryMode); err != nil {
|
if err := os.Mkdir(outside, debugDirectoryMode); err != nil {
|
||||||
t.Fatalf("create symlink component target: %v", err)
|
t.Fatalf("create symlink component target: %v", err)
|
||||||
}
|
}
|
||||||
if err := os.Symlink(outside, filepath.Join(root, "debug", "daily")); err != nil {
|
requireSymlink(t, outside, filepath.Join(root, "debug", "daily"))
|
||||||
t.Fatalf("create symlink component: %v", err)
|
|
||||||
}
|
|
||||||
if _, err := writer.WritePreparation(promptDebugRef(), promptDebugPreparationFixture(), nil); err == nil {
|
if _, err := writer.WritePreparation(promptDebugRef(), promptDebugPreparationFixture(), nil); err == nil {
|
||||||
t.Fatal("WritePreparation(symlink component) error = nil")
|
t.Fatal("WritePreparation(symlink component) error = nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 promptDebugRef() PromptDebugRef {
|
func promptDebugRef() PromptDebugRef {
|
||||||
return PromptDebugRef{ReportID: report.Daily, ValidDate: "2026-05-29", RunID: "run-123"}
|
return PromptDebugRef{ReportID: report.Daily, ValidDate: "2026-05-29", RunID: "run-123"}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user