From f7498c9ae626b9ab654fe6eb736e19c62cf5d38d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 6 Jul 2026 10:14:39 +0300 Subject: refactor --- internal/resource/file/file.go | 6 +++--- internal/resource/file/file_test.go | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'internal/resource/file') 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) } -- cgit v1.2.3