test(quality): cover sqlite redis and overlay edge branches

This commit is contained in:
phamnazage-jpg
2026-05-30 18:28:03 +08:00
parent 51472e9951
commit f895eb9035
6 changed files with 357 additions and 0 deletions

View File

@@ -243,9 +243,41 @@ func TestApplyRejectsExistingOutputDir(t *testing.T) {
}
}
func TestApplyRejectsSourceFile(t *testing.T) {
sourceDir := filepath.Join(t.TempDir(), "source.txt")
if err := os.WriteFile(sourceDir, []byte("not a dir"), 0o644); err != nil {
t.Fatalf("WriteFile() error = %v", err)
}
_, err := Apply(context.Background(), ApplyRequest{
PackDir: t.TempDir(),
SourceDir: sourceDir,
Overlays: []pack.HostOverlay{{OverlayID: "sample", PatchPath: "overlays/sample.patch"}},
})
if err == nil || !strings.Contains(err.Error(), "must be a directory") {
t.Fatalf("Apply() error = %v, want source dir 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")
}
}
func TestCopyFileRejectsTargetParentThatIsAFile(t *testing.T) {
parentFile := filepath.Join(t.TempDir(), "parent-file")
if err := os.WriteFile(parentFile, []byte("block mkdir"), 0o644); err != nil {
t.Fatalf("WriteFile(parentFile) error = %v", err)
}
sourcePath := filepath.Join(t.TempDir(), "source.txt")
if err := os.WriteFile(sourcePath, []byte("hello"), 0o644); err != nil {
t.Fatalf("WriteFile(sourcePath) error = %v", err)
}
err := copyFile(sourcePath, filepath.Join(parentFile, "nested", "target.txt"), 0o644)
if err == nil {
t.Fatal("copyFile() error = nil, want parent path mkdir failure")
}
}