diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-06 10:14:39 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-06 10:14:39 +0300 |
| commit | f7498c9ae626b9ab654fe6eb736e19c62cf5d38d (patch) | |
| tree | 65e79446bd327633af779b3a1796e0da269a1530 /internal/resource/file | |
| parent | 72cf1553e87bef43a4d988896d98034ddfbc018c (diff) | |
refactor
Diffstat (limited to 'internal/resource/file')
| -rw-r--r-- | internal/resource/file/file.go | 6 | ||||
| -rw-r--r-- | internal/resource/file/file_test.go | 22 |
2 files changed, 14 insertions, 14 deletions
diff --git a/internal/resource/file/file.go b/internal/resource/file/file.go index 402b348..9879e27 100644 --- a/internal/resource/file/file.go +++ b/internal/resource/file/file.go @@ -10,8 +10,8 @@ import ( "strings" "text/template" - "codeberg.org/snonux/gonf/internal/resource" opt "codeberg.org/snonux/gonf/api/option" + "codeberg.org/snonux/gonf/internal/resource" ) type File struct { @@ -218,7 +218,7 @@ func Ensure(path string, opts ...opt.Option) error { return f.apply() } -func Have(path string, opts ...opt.Option) resource.Resource { +func Present(path string, opts ...opt.Option) resource.Resource { f, err := build(path, opts...) if err != nil { log.Fatalf("failed to apply file resource %s: %v", path, err) @@ -232,5 +232,5 @@ func Have(path string, opts ...opt.Option) resource.Resource { func Absent(path string, opts ...opt.Option) resource.Resource { opts = append(opts, opt.IsAbsent()) - return Have(path, opts...) + return Present(path, opts...) } diff --git a/internal/resource/file/file_test.go b/internal/resource/file/file_test.go index e84ab13..7f9fedd 100644 --- a/internal/resource/file/file_test.go +++ b/internal/resource/file/file_test.go @@ -6,8 +6,8 @@ import ( "strings" "testing" - "codeberg.org/snonux/gonf/internal/resource" . "codeberg.org/snonux/gonf/api/option" + "codeberg.org/snonux/gonf/internal/resource" ) func TestGetChecksum(t *testing.T) { @@ -104,12 +104,12 @@ func TestUpdateFromTmpChecksumUnchanged(t *testing.T) { } } -func TestHaveStringCreateNewFile(t *testing.T) { +func TestPresentStringCreateNewFile(t *testing.T) { resource.ResetRepository() dir := t.TempDir() path := filepath.Join(dir, "new.txt") - Have(path, WithContent("hello world")) + Present(path, WithContent("hello world")) if err := resource.Apply(); err != nil { t.Fatalf("Apply failed: %v", err) } @@ -123,13 +123,13 @@ func TestHaveStringCreateNewFile(t *testing.T) { } } -func TestHaveMode(t *testing.T) { +func TestPresentMode(t *testing.T) { resource.ResetRepository() dir := t.TempDir() path := filepath.Join(dir, "mode.txt") mode := os.FileMode(0o600) - Have(path, WithContent("mode test"), WithMode(mode)) + Present(path, WithContent("mode test"), WithMode(mode)) if err := resource.Apply(); err != nil { t.Fatalf("Apply failed: %v", err) } @@ -143,13 +143,13 @@ func TestHaveMode(t *testing.T) { } } -func TestHaveSourceFile(t *testing.T) { +func TestPresentSourceFile(t *testing.T) { resource.ResetRepository() dir := t.TempDir() sourcePath := filepath.Join("..", "..", "..", "assets", "testfiles", "test.txt") targetPath := filepath.Join(dir, "target.txt") - Have(targetPath, WithSource(sourcePath)) + Present(targetPath, WithSource(sourcePath)) if err := resource.Apply(); err != nil { t.Fatalf("Apply failed: %v", err) } @@ -164,13 +164,13 @@ func TestHaveSourceFile(t *testing.T) { } } -func TestHaveTemplateFile(t *testing.T) { +func TestPresentTemplateFile(t *testing.T) { resource.ResetRepository() dir := t.TempDir() sourcePath := filepath.Join("..", "..", "..", "assets", "testfiles", "test.tmpl") targetPath := filepath.Join(dir, "target.conf") - Have(targetPath, WithSource(sourcePath)) + Present(targetPath, WithSource(sourcePath)) if err := resource.Apply(); err != nil { t.Fatalf("Apply failed: %v", err) } @@ -186,7 +186,7 @@ func TestHaveTemplateFile(t *testing.T) { } } -func TestHaveAbsent(t *testing.T) { +func TestPresentAbsent(t *testing.T) { resource.ResetRepository() dir := t.TempDir() path := filepath.Join(dir, "gone.txt") @@ -194,7 +194,7 @@ func TestHaveAbsent(t *testing.T) { t.Fatal(err) } - Have(path, IsAbsent()) + Present(path, IsAbsent()) if err := resource.Apply(); err != nil { t.Fatalf("Apply failed: %v", err) } |
