test(quality): cover routing sqlite overlay hotspots
This commit is contained in:
@@ -151,6 +151,19 @@ func TestApplyPatchFileRejectsMissingPatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyPatchFileRejectsInvalidPatch(t *testing.T) {
|
||||
outputDir := t.TempDir()
|
||||
patchPath := filepath.Join(t.TempDir(), "invalid.patch")
|
||||
if err := os.WriteFile(patchPath, []byte("not a patch\n"), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile() error = %v", err)
|
||||
}
|
||||
|
||||
err := applyPatchFile(context.Background(), outputDir, patchPath)
|
||||
if err == nil {
|
||||
t.Fatal("applyPatchFile() error = nil, want invalid patch failure")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteMetadataIncludesSourceDirAndOverlays(t *testing.T) {
|
||||
metadataPath := filepath.Join(t.TempDir(), metadataFileName)
|
||||
overlays := []pack.HostOverlay{{OverlayID: "sample", PatchPath: "overlays/sample.patch"}}
|
||||
@@ -208,3 +221,31 @@ func TestCopyTreeSkipsGitAndPreservesSymlink(t *testing.T) {
|
||||
t.Fatalf("symlink target = %q, want backend/hello.txt", target)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyRejectsExistingOutputDir(t *testing.T) {
|
||||
sourceDir := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(sourceDir, "backend"), 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll() error = %v", err)
|
||||
}
|
||||
outputDir := filepath.Join(t.TempDir(), "existing-output")
|
||||
if err := os.MkdirAll(outputDir, 0o755); err != nil {
|
||||
t.Fatalf("MkdirAll(outputDir) error = %v", err)
|
||||
}
|
||||
|
||||
_, err := Apply(context.Background(), ApplyRequest{
|
||||
PackDir: t.TempDir(),
|
||||
SourceDir: sourceDir,
|
||||
OutputDir: outputDir,
|
||||
Overlays: []pack.HostOverlay{{OverlayID: "sample", PatchPath: "overlays/sample.patch"}},
|
||||
})
|
||||
if err == nil || !strings.Contains(err.Error(), "already exists") {
|
||||
t.Fatalf("Apply() error = %v, want existing output rejection", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyFileRejectsMissingSource(t *testing.T) {
|
||||
err := copyFile(filepath.Join(t.TempDir(), "missing.txt"), filepath.Join(t.TempDir(), "target.txt"), 0o644)
|
||||
if err == nil {
|
||||
t.Fatal("copyFile() error = nil, want missing source failure")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user