diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-05 00:12:12 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-05 00:12:12 +0300 |
| commit | a1250c11b04b8ad0a713d801942aa3208b6a43de (patch) | |
| tree | dcf3ae6d0074052efe21e3461911b768a91e25c8 /internal/resource/file | |
| parent | 8228ba742f6b23a93e6a00006feba29225ea89c7 (diff) | |
add aliases
Diffstat (limited to 'internal/resource/file')
| -rw-r--r-- | internal/resource/file/file.go | 5 | ||||
| -rw-r--r-- | internal/resource/file/file_test.go | 19 |
2 files changed, 24 insertions, 0 deletions
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") |
