summaryrefslogtreecommitdiff
path: root/internal/resource/resource_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-04 21:00:42 +0300
committerPaul Buetow <paul@buetow.org>2026-07-04 21:00:42 +0300
commit1f6334b0e6748b2bbdecc3ffb56b0f7a26290001 (patch)
tree8e079a7a5db2c27190a263c7dcde85f1860c1c87 /internal/resource/resource_test.go
parent6a3cae2f434e84d926eee88db0e9ab26767380e7 (diff)
register file resource automatically
Diffstat (limited to 'internal/resource/resource_test.go')
-rw-r--r--internal/resource/resource_test.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/internal/resource/resource_test.go b/internal/resource/resource_test.go
index 6f0665a..947f0ac 100644
--- a/internal/resource/resource_test.go
+++ b/internal/resource/resource_test.go
@@ -5,7 +5,8 @@ import (
)
func TestResourceID(t *testing.T) {
- res := New("File", "/tmp/foo.txt")
+ resetRepository()
+ res := Register("File", "/tmp/foo.txt")
expected := "File[/tmp/foo.txt]"
if res.ID() != expected {
t.Errorf("expected ID %s, got %s", expected, res.ID())
@@ -13,7 +14,8 @@ func TestResourceID(t *testing.T) {
}
func TestResourceString(t *testing.T) {
- res := New("File", "/tmp/foo.txt")
+ resetRepository()
+ res := Register("File", "/tmp/foo.txt")
expected := "File[/tmp/foo.txt]"
if res.String() != expected {
t.Errorf("expected String %s, got %s", expected, res.String())
@@ -21,9 +23,10 @@ func TestResourceString(t *testing.T) {
}
func TestNew(t *testing.T) {
+ resetRepository()
type_ := "File"
name := "/tmp/foo.txt"
- res := New(type_, name)
+ res := Register(type_, name)
if res.Type != type_ {
t.Errorf("expected type %s, got %s", type_, res.Type)
@@ -37,22 +40,19 @@ func TestNew(t *testing.T) {
}
func TestRepositoryRegister(t *testing.T) {
- repo := newRepository()
- res := New("File", "/tmp/foo.txt")
+ resetRepository()
+ repo := getRepository()
+ res := Register("File", "/tmp/foo.txt")
- // First registration should succeed
- if err := repo.register(res); err != nil {
- t.Fatalf("expected successful registration, got error: %v", err)
- }
-
- // Second registration of the same resource should fail
+ // First registration already happened in New()
+ // But we can try to register again via the repository directly
if err := repo.register(res); err == nil {
t.Error("expected error when registering the same resource twice, got nil")
}
// Registration of a different resource should succeed
- res2 := New("File", "/tmp/bar.txt")
- if err := repo.register(res2); err != nil {
- t.Fatalf("expected successful registration of different resource, got error: %v", err)
+ res2 := Register("File", "/tmp/bar.txt")
+ if err := repo.register(res2); err == nil {
+ t.Error("expected error when registering the same resource twice, got nil")
}
}