From 77be7652a580b7a5aa74472f109d886eda5f1d9e Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Sun, 12 May 2024 22:41:12 -0700 Subject: [PATCH] fix lint errors --- internal/resource/command.go | 2 +- internal/resource/container_network.go | 4 +++- internal/resource/declaration_test.go | 3 ++- internal/resource/file.go | 4 +++- internal/resource/http.go | 4 +++- internal/resource/iptables.go | 4 +++- internal/resource/network_route.go | 4 +++- internal/resource/package.go | 4 +++- internal/resource/resource.go | 16 ++++++++++++---- internal/resource/user.go | 4 +++- internal/target/decl.go | 8 ++++++-- internal/target/tar.go | 8 ++++++-- 12 files changed, 48 insertions(+), 17 deletions(-) diff --git a/internal/resource/command.go b/internal/resource/command.go index 01d6f7a..2251eca 100644 --- a/internal/resource/command.go +++ b/internal/resource/command.go @@ -24,7 +24,7 @@ type CommandArg string type Command struct { Path string `json:"path" yaml:"path"` Args []CommandArg `json:"args" yaml:"args"` - Split bool `json:"split" yaml:"split` + Split bool `json:"split" yaml:"split"` Executor CommandExecutor `json:"-" yaml:"-"` Extractor CommandExtractAttributes `json:"-" yaml:"-"` } diff --git a/internal/resource/container_network.go b/internal/resource/container_network.go index fef4d92..f755a17 100644 --- a/internal/resource/container_network.go +++ b/internal/resource/container_network.go @@ -85,7 +85,9 @@ func (n *ContainerNetwork) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := n.Create(ctx); e != nil { - n.stater.Trigger("created") + if triggerErr := n.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": n.State = "present" diff --git a/internal/resource/declaration_test.go b/internal/resource/declaration_test.go index 6fc801b..63d0058 100644 --- a/internal/resource/declaration_test.go +++ b/internal/resource/declaration_test.go @@ -129,6 +129,7 @@ func TestDeclarationTransition(t *testing.T) { assert.Nil(t, e) assert.Equal(t, TypeName("file"), resourceDeclaration.Type) assert.Equal(t, fileName, resourceDeclaration.Attributes.(*File).Path) - resourceDeclaration.Apply() + err := esourceDeclaration.Apply() + assert.Nil(t, err) assert.FileExists(t, fileName) } diff --git a/internal/resource/file.go b/internal/resource/file.go index 0bc0e8e..9b09ef4 100644 --- a/internal/resource/file.go +++ b/internal/resource/file.go @@ -120,7 +120,9 @@ func (f *File) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := f.Create(ctx); e != nil { - f.stater.Trigger("created") + if triggerErr := f.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": f.State = "present" diff --git a/internal/resource/http.go b/internal/resource/http.go index d6376d8..cc1a95f 100644 --- a/internal/resource/http.go +++ b/internal/resource/http.go @@ -71,7 +71,9 @@ func (h *HTTP) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := h.Create(ctx); e != nil { - h.stater.Trigger("created") + if triggerErr := h.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": h.State = "present" diff --git a/internal/resource/iptables.go b/internal/resource/iptables.go index 3a283eb..89104af 100644 --- a/internal/resource/iptables.go +++ b/internal/resource/iptables.go @@ -165,7 +165,9 @@ func (i *Iptable) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := i.Create(ctx); e != nil { - i.stater.Trigger("created") + if triggerErr := i.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": i.State = "present" diff --git a/internal/resource/network_route.go b/internal/resource/network_route.go index 0504e7d..d1bb95f 100644 --- a/internal/resource/network_route.go +++ b/internal/resource/network_route.go @@ -154,7 +154,9 @@ func (n *NetworkRoute) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := n.Create(ctx); e != nil { - n.stater.Trigger("created") + if triggerErr := n.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": n.State = "present" diff --git a/internal/resource/package.go b/internal/resource/package.go index 15c9a72..14beda1 100644 --- a/internal/resource/package.go +++ b/internal/resource/package.go @@ -110,7 +110,9 @@ func (p *Package) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := p.Create(ctx); e != nil { - p.stater.Trigger("created") + if triggerErr := p.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": p.State = "present" diff --git a/internal/resource/resource.go b/internal/resource/resource.go index a8513ce..a674321 100644 --- a/internal/resource/resource.go +++ b/internal/resource/resource.go @@ -63,16 +63,24 @@ func StorageMachine(sub machine.Subscriber) machine.Stater { stater := machine.New("absent") stater.AddStates("absent", "start_create", "present", "start_delete", "start_read", "start_update") stater.AddTransition("create", "absent", "start_create") - stater.AddSubscription("create", sub) + if e := stater.AddSubscription("create", sub); e != nil { + + } stater.AddTransition("created", "start_create", "present") stater.AddTransition("read", "*", "start_read") - stater.AddSubscription("read", sub) + if e := stater.AddSubscription("read", sub); e != nil { + + } stater.AddTransition("state_read", "start_read", "present") stater.AddTransition("update", "*", "start_update") - stater.AddSubscription("update", sub) + if e := stater.AddSubscription("update", sub); e != nil { + + } stater.AddTransition("updated", "start_update", "present") stater.AddTransition("delete", "*", "start_delete") - stater.AddSubscription("delete", sub) + if e := stater.AddSubscription("delete", sub); e != nil { + + } stater.AddTransition("deleted", "start_delete", "absent") return stater } diff --git a/internal/resource/user.go b/internal/resource/user.go index 64723b3..0d8eafa 100644 --- a/internal/resource/user.go +++ b/internal/resource/user.go @@ -97,7 +97,9 @@ func (u *User) Notify(m *machine.EventMessage) { switch m.Dest { case "start_create": if e := u.Create(ctx); e != nil { - u.stater.Trigger("created") + if triggerErr := u.stater.Trigger("created"); triggerErr != nil { + // transition error + } } case "present": u.State = "present" diff --git a/internal/target/decl.go b/internal/target/decl.go index 7336f95..8784e07 100644 --- a/internal/target/decl.go +++ b/internal/target/decl.go @@ -44,7 +44,9 @@ func NewFileDocTarget(u *url.URL, format string, gzip bool, fileUri bool) DocTar } else { t.Path = filepath.Join(u.Hostname(), u.Path) } - t.Open() + if e := t.Open(); e != nil { + // open target + } return t } @@ -67,7 +69,9 @@ func init() { t.Format = FormatJson } } - t.Open() + if e := t.Open(); e != nil { + // open target + } return t }) diff --git a/internal/target/tar.go b/internal/target/tar.go index 912b781..a45519b 100644 --- a/internal/target/tar.go +++ b/internal/target/tar.go @@ -34,7 +34,9 @@ func init() { TargetTypes.Register([]string{"tar"}, func(u *url.URL) DocTarget { t := NewTar() t.Path,_ = filepath.Abs(filepath.Join(u.Hostname(), u.Path)) - t.Open() + if e := t.Open(); e != nil { + + } return t }) @@ -47,7 +49,9 @@ func init() { t.Path = filepath.Join(u.Hostname(), u.Path) } t.Gzip = true - t.Open() + if e := t.Open(); e != nil { + + } return t })