summaryrefslogtreecommitdiff
path: root/internal/resource/multi_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-08 23:17:39 +0300
committerPaul Buetow <paul@buetow.org>2026-07-08 23:17:39 +0300
commit3f8b79f2b1384e3abc2b1bb2fe913688c7ec251c (patch)
tree5cff57875a1f5b63536423c0b7fe7a3788ff15ac /internal/resource/multi_test.go
parent920f2ea88c45e972cd87b56580c90a0277b7130e (diff)
add multi which can return multiple resources
Diffstat (limited to 'internal/resource/multi_test.go')
-rw-r--r--internal/resource/multi_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/internal/resource/multi_test.go b/internal/resource/multi_test.go
new file mode 100644
index 0000000..3443afb
--- /dev/null
+++ b/internal/resource/multi_test.go
@@ -0,0 +1,81 @@
+package resource
+
+import (
+ "errors"
+ "testing"
+)
+
+func TestMultiString(t *testing.T) {
+ m := Multi{
+ Resource{Type: "File", Name: "/tmp/a"},
+ Resource{Type: "File", Name: "/tmp/b"},
+ }
+
+ want := "File[/tmp/a], File[/tmp/b]"
+ if got := m.String(); got != want {
+ t.Errorf("Multi.String() = %q, want %q", got, want)
+ }
+}
+
+func TestMultiID(t *testing.T) {
+ m := Multi{
+ Resource{Type: "File", Name: "/tmp/a"},
+ Resource{Type: "File", Name: "/tmp/b"},
+ }
+
+ want := "File[/tmp/a]+File[/tmp/b]"
+ if got := m.ID(); got != want {
+ t.Errorf("Multi.ID() = %q, want %q", got, want)
+ }
+}
+
+func TestMultiApply(t *testing.T) {
+ tests := []struct {
+ name string
+ appliers []Applier
+ wantErr bool
+ }{
+ {
+ name: "all success",
+ appliers: []Applier{
+ ApplierFunc(func() error { return nil }),
+ ApplierFunc(func() error { return nil }),
+ },
+ wantErr: false,
+ },
+ {
+ name: "one failure",
+ appliers: []Applier{
+ ApplierFunc(func() error { return nil }),
+ ApplierFunc(func() error { return errors.New("fail 1") }),
+ },
+ wantErr: true,
+ },
+ {
+ name: "multiple failures",
+ appliers: []Applier{
+ ApplierFunc(func() error { return errors.New("fail 1") }),
+ ApplierFunc(func() error { return errors.New("fail 2") }),
+ },
+ wantErr: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var resources []Resource
+ for _, app := range tt.appliers {
+ resources = append(resources, Resource{
+ applier: app,
+ })
+ }
+
+ m := Multi(resources)
+ err := m.Apply()
+
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Multi.Apply() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}