summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-05 00:12:12 +0300
committerPaul Buetow <paul@buetow.org>2026-07-05 00:12:12 +0300
commita1250c11b04b8ad0a713d801942aa3208b6a43de (patch)
treedcf3ae6d0074052efe21e3461911b768a91e25c8 /internal
parent8228ba742f6b23a93e6a00006feba29225ea89c7 (diff)
add aliases
Diffstat (limited to 'internal')
-rw-r--r--internal/resource/dir/dir.go5
-rw-r--r--internal/resource/dir/dir_test.go22
-rw-r--r--internal/resource/file/file.go5
-rw-r--r--internal/resource/file/file_test.go19
-rw-r--r--internal/resource/link/link.go5
-rw-r--r--internal/resource/link/link_test.go23
6 files changed, 79 insertions, 0 deletions
diff --git a/internal/resource/dir/dir.go b/internal/resource/dir/dir.go
index 0024c6c..9c34486 100644
--- a/internal/resource/dir/dir.go
+++ b/internal/resource/dir/dir.go
@@ -222,3 +222,8 @@ func Have(path string, opts ...Option) resource.Resource {
return res
}
+
+func Absent(path string, opts ...Option) resource.Resource {
+ opts = append(opts, IsAbsent())
+ return Have(path, opts...)
+}
diff --git a/internal/resource/dir/dir_test.go b/internal/resource/dir/dir_test.go
index b93564a..ca01535 100644
--- a/internal/resource/dir/dir_test.go
+++ b/internal/resource/dir/dir_test.go
@@ -99,6 +99,28 @@ func TestHaveAbsentPruneDirectoryRecursive(t *testing.T) {
}
}
+func TestAbsentPruneDirectoryRecursive(t *testing.T) {
+ tmp := t.TempDir()
+ target := filepath.Join(tmp, "d")
+ if err := os.MkdirAll(filepath.Join(target, "sub", "deep"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(target, "sub", "f.txt"), []byte("x"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ Absent(target, WithPrune())
+ if _, err := os.Stat(target); !os.IsNotExist(err) {
+ t.Errorf("expected %s to be removed recursively", target)
+ }
+
+ // Idempotent: removing a missing tree is not an error.
+ d := &Dir{path: target, absent: true, prune: true}
+ if err := ensureAbsent(d); err != nil {
+ t.Fatalf("prune on missing tree: %v", err)
+ }
+}
+
func TestHaveDirectoryWithSource(t *testing.T) {
t.Run("recursive copy", func(t *testing.T) {
tmp := t.TempDir()
diff --git a/internal/resource/file/file.go b/internal/resource/file/file.go
index b3c1e44..257c407 100644
--- a/internal/resource/file/file.go
+++ b/internal/resource/file/file.go
@@ -244,3 +244,8 @@ func Have(path string, opts ...Option) resource.Resource {
return res
}
+
+func Absent(path string, opts ...Option) resource.Resource {
+ opts = append(opts, IsAbsent())
+ return Have(path, opts...)
+}
diff --git a/internal/resource/file/file_test.go b/internal/resource/file/file_test.go
index 662aee7..b3b7711 100644
--- a/internal/resource/file/file_test.go
+++ b/internal/resource/file/file_test.go
@@ -182,6 +182,25 @@ func TestHaveAbsent(t *testing.T) {
}
}
+func TestAbsent(t *testing.T) {
+ dir := t.TempDir()
+ path := filepath.Join(dir, "gone.txt")
+ if err := os.WriteFile(path, []byte("bye"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ Absent(path)
+ if _, err := os.Stat(path); !os.IsNotExist(err) {
+ t.Errorf("expected %s to be removed", path)
+ }
+
+ // Idempotent: removing a missing file is not an error (direct call to
+ // avoid duplicate registration in the one-per-process registry).
+ if err := ensureAbsent(path); err != nil {
+ t.Fatalf("absent on missing file: %v", err)
+ }
+}
+
func TestResolveStripsTmplSuffixWhenSourceHasTmplSuffix(t *testing.T) {
dir := t.TempDir()
sourcePath := filepath.Join(dir, "foo.conf.tmpl")
diff --git a/internal/resource/link/link.go b/internal/resource/link/link.go
index 0a6b8e6..3133514 100644
--- a/internal/resource/link/link.go
+++ b/internal/resource/link/link.go
@@ -102,6 +102,11 @@ func Have(path string, opts ...Option) resource.Resource {
return res
}
+func Absent(path string, opts ...Option) resource.Resource {
+ opts = append(opts, IsAbsent())
+ return Have(path, opts...)
+}
+
func ensureAbsent(path string) error {
log.Printf("ensuring link absent: %s", path)
diff --git a/internal/resource/link/link_test.go b/internal/resource/link/link_test.go
index 8da674b..6f1b1bc 100644
--- a/internal/resource/link/link_test.go
+++ b/internal/resource/link/link_test.go
@@ -170,6 +170,29 @@ func TestHaveAbsentSymlink(t *testing.T) {
}
}
+func TestAbsentSymlink(t *testing.T) {
+ dir := t.TempDir()
+ target := filepath.Join(dir, "target.txt")
+ link := filepath.Join(dir, "link.txt")
+ if err := os.WriteFile(target, []byte("t"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(target, link); err != nil {
+ t.Fatal(err)
+ }
+
+ Absent(link)
+ if _, err := os.Lstat(link); !os.IsNotExist(err) {
+ t.Errorf("expected %s to be removed", link)
+ }
+
+ // Idempotent: removing a missing link is not an error (direct call to
+ // avoid duplicate registration in the one-per-process registry).
+ if err := ensureAbsent(link); err != nil {
+ t.Fatalf("absent on missing link: %v", err)
+ }
+}
+
func TestHaveAbsentWithoutKindRegistersGenericLink(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "whatever")