summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-04 23:47:32 +0300
committerPaul Buetow <paul@buetow.org>2026-07-04 23:47:32 +0300
commit8228ba742f6b23a93e6a00006feba29225ea89c7 (patch)
tree0147bbb82f99a6056f43492b661ede7fea7e8bea /examples
parent6a2796f31444b21488ab9d383292841613a1d9c7 (diff)
refactor
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.go40
1 files changed, 36 insertions, 4 deletions
diff --git a/examples/examples.go b/examples/examples.go
index 8fe0f0d..3fe2d50 100644
--- a/examples/examples.go
+++ b/examples/examples.go
@@ -1,7 +1,11 @@
package examples
import (
- "codeberg.org/snonux/gonf/internal/file"
+ "os"
+
+ "codeberg.org/snonux/gonf/internal/resource/dir"
+ "codeberg.org/snonux/gonf/internal/resource/file"
+ "codeberg.org/snonux/gonf/internal/resource/link"
)
func Run() error {
@@ -19,16 +23,44 @@ func Run() error {
)
// 4. A directory
- file.Have("/tmp/gonf_dir", file.IsDirectory(), file.WithMode(0o755))
+ dir.Have("/tmp/gonf_dir", dir.WithMode(0o755))
// 5. A symlink
- file.Have("/tmp/gonf_link", file.IsSymlink("/tmp/gonf_hello.txt"))
+ link.Have("/tmp/gonf_link", link.IsSymlink("/tmp/gonf_hello.txt"))
// 6. A hardlink
- file.Have("/tmp/gonf_hardlink", file.IsHardlink("/tmp/gonf_hello.txt"))
+ link.Have("/tmp/gonf_hardlink", link.IsHardlink("/tmp/gonf_hello.txt"))
// 7. Ensuring something is absent
file.Have("/tmp/gonf_old.txt", file.IsAbsent())
+ // 8. A directory tree copied from source, reconciled, with a distinct
+ // file mode from the directory's own mode
+ dir.Have(
+ "/tmp/gonf_dir_from_source",
+ dir.WithSource("assets/testfiles"),
+ dir.WithPrune(),
+ dir.WithFileMode(0o644),
+ )
+
+ // 9. Recursively removing a directory tree. Each resource path can only
+ // be declared once per run, so this pre-populates its own scratch tree
+ // (rather than reusing #8's path) to give WithPrune's recursive removal
+ // something real to demonstrate.
+ _ = os.MkdirAll("/tmp/gonf_stale_dir/nested", 0o755)
+ dir.Have("/tmp/gonf_stale_dir", dir.IsAbsent(), dir.WithPrune())
+
+ // 10. Non-recursively removing an empty directory
+ _ = os.Mkdir("/tmp/gonf_stale_empty_dir", 0o755)
+ dir.Have("/tmp/gonf_stale_empty_dir", dir.IsAbsent())
+
+ // 11. Ensuring a symlink is absent
+ _ = os.Symlink("/tmp/gonf_hello.txt", "/tmp/gonf_stale_link")
+ link.Have("/tmp/gonf_stale_link", link.IsAbsent())
+
+ // 12. Ensuring a hardlink is absent
+ _ = os.Link("/tmp/gonf_hello.txt", "/tmp/gonf_stale_hardlink")
+ link.Have("/tmp/gonf_stale_hardlink", link.IsAbsent())
+
return nil
}