summaryrefslogtreecommitdiff
path: root/internal/resource/pkg
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-09 00:14:33 +0300
committerPaul Buetow <paul@buetow.org>2026-07-09 00:14:33 +0300
commit756ae621bd97a8b776fefb15e5e7e2292f98ee45 (patch)
treeb454f958e6aef70bf7ca40dcbc106323cee2a42f /internal/resource/pkg
parent3f8b79f2b1384e3abc2b1bb2fe913688c7ec251c (diff)
dependencies
Diffstat (limited to 'internal/resource/pkg')
-rw-r--r--internal/resource/pkg/dnf.go2
-rw-r--r--internal/resource/pkg/dnf_test.go26
-rw-r--r--internal/resource/pkg/pkg.go7
3 files changed, 19 insertions, 16 deletions
diff --git a/internal/resource/pkg/dnf.go b/internal/resource/pkg/dnf.go
index e970b10..34f0a5d 100644
--- a/internal/resource/pkg/dnf.go
+++ b/internal/resource/pkg/dnf.go
@@ -9,7 +9,7 @@ import (
func applyDNF(p *Package) error {
var args []string
- if p.absent {
+ if p.Absent {
args = []string{"remove", "-y", p.name}
} else if p.latest {
// update ensures the package is installed and updated to the latest version.
diff --git a/internal/resource/pkg/dnf_test.go b/internal/resource/pkg/dnf_test.go
index 6c929f2..ddd84e6 100644
--- a/internal/resource/pkg/dnf_test.go
+++ b/internal/resource/pkg/dnf_test.go
@@ -3,6 +3,8 @@ package pkg
import (
"os"
"testing"
+
+ "codeberg.org/snonux/gonf/internal/resource/embed"
)
func TestApplyDNF(t *testing.T) {
@@ -21,7 +23,7 @@ func TestApplyDNF(t *testing.T) {
}
t.Run("Present", func(t *testing.T) {
- p.absent = false
+ p.Absent = false
p.latest = false
if err := applyDNF(p); err != nil {
t.Errorf("applyDNF Present failed: %v", err)
@@ -29,7 +31,7 @@ func TestApplyDNF(t *testing.T) {
})
t.Run("Latest", func(t *testing.T) {
- p.absent = false
+ p.Absent = false
p.latest = true
if err := applyDNF(p); err != nil {
t.Errorf("applyDNF Latest failed: %v", err)
@@ -37,7 +39,7 @@ func TestApplyDNF(t *testing.T) {
})
t.Run("Absent", func(t *testing.T) {
- p.absent = true
+ p.Absent = true
p.latest = false
if err := applyDNF(p); err != nil {
t.Errorf("applyDNF Absent failed: %v", err)
@@ -46,9 +48,9 @@ func TestApplyDNF(t *testing.T) {
t.Run("NonExistentPresent", func(t *testing.T) {
pErr := &Package{
- name: "non-existent-package-gonf-12345",
- absent: false,
- latest: false,
+ name: "non-existent-package-gonf-12345",
+ Absence: embed.Absence{Absent: false},
+ latest: false,
}
if err := applyDNF(pErr); err == nil {
t.Error("applyDNF Present should have failed for non-existent package")
@@ -57,9 +59,9 @@ func TestApplyDNF(t *testing.T) {
t.Run("NonExistentLatest", func(t *testing.T) {
pErr := &Package{
- name: "non-existent-package-gonf-12345",
- absent: false,
- latest: true,
+ name: "non-existent-package-gonf-12345",
+ Absence: embed.Absence{Absent: false},
+ latest: true,
}
if err := applyDNF(pErr); err == nil {
t.Error("applyDNF Latest should have failed for non-existent package")
@@ -68,9 +70,9 @@ func TestApplyDNF(t *testing.T) {
t.Run("NonExistentAbsent", func(t *testing.T) {
pErr := &Package{
- name: "non-existent-package-gonf-12345",
- absent: true,
- latest: false,
+ name: "non-existent-package-gonf-12345",
+ Absence: embed.Absence{Absent: true},
+ latest: false,
}
// dnf remove is typically idempotent; removing a non-existent package should not error.
if err := applyDNF(pErr); err != nil {
diff --git a/internal/resource/pkg/pkg.go b/internal/resource/pkg/pkg.go
index b010c7a..c4799c8 100644
--- a/internal/resource/pkg/pkg.go
+++ b/internal/resource/pkg/pkg.go
@@ -6,15 +6,16 @@ import (
opt "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource"
+ "codeberg.org/snonux/gonf/internal/resource/embed"
)
type Package struct {
+ embed.DependsOn
+ embed.Absence
name string
- absent bool
latest bool
}
-func (p *Package) SetAbsent() { p.absent = true }
func (p *Package) SetLatest() { p.latest = true }
func (p *Package) apply() error {
@@ -41,7 +42,7 @@ func Present(name string, opts ...opt.Option) resource.Resource {
}
return resource.Register("Package", p.name,
- resource.ApplierFunc(func() error { return p.apply() }))
+ resource.ApplierFunc(func() error { return p.apply() }), p.DependsOn.IDs...)
}
func Absent(name string, opts ...opt.Option) resource.Resource {