From cf97af96b3822c86a8b068456c9f7008fbd267fd Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Sun, 5 May 2024 21:40:34 -0700 Subject: [PATCH] fix lint errors --- internal/resource/declaration.go | 3 +-- internal/resource/document_test.go | 5 +---- internal/resource/file.go | 5 +---- internal/resource/file_test.go | 14 +++++++++----- internal/resource/user.go | 5 ++++- internal/target/tar.go | 5 +---- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/internal/resource/declaration.go b/internal/resource/declaration.go index b664ab6..e652626 100644 --- a/internal/resource/declaration.go +++ b/internal/resource/declaration.go @@ -66,8 +66,7 @@ func (d *Declaration) Resource() Resource { func (d *Declaration) Apply() error { stater := d.Attributes.StateMachine() - stater.Trigger(d.Transition) - return nil + return stater.Trigger(d.Transition) } func (d *Declaration) SetURI(uri string) error { diff --git a/internal/resource/document_test.go b/internal/resource/document_test.go index 10a10ff..ebfcfd2 100644 --- a/internal/resource/document_test.go +++ b/internal/resource/document_test.go @@ -218,10 +218,7 @@ resources: assert.Nil(t, e) resources := d.Filter(func(d *Declaration) bool { - if d.Type == "file" { - return true - } - return false + return d.Type == "file" }) assert.Equal(t, 2, len(resources)) } diff --git a/internal/resource/file.go b/internal/resource/file.go index d701faf..e36d1c2 100644 --- a/internal/resource/file.go +++ b/internal/resource/file.go @@ -256,10 +256,7 @@ func (f *ResourceFileInfo) ModTime() time.Time { } func (f *ResourceFileInfo) IsDir() bool { - if f.resource.FileType == DirectoryFile { - return true - } - return false + return f.resource.FileType == DirectoryFile } func (f *ResourceFileInfo) Sys() any { diff --git a/internal/resource/file_test.go b/internal/resource/file_test.go index 5282708..3c37cdd 100644 --- a/internal/resource/file_test.go +++ b/internal/resource/file_test.go @@ -32,7 +32,7 @@ func TestNewFileNormalized(t *testing.T) { absFilePath,_ := filepath.Abs(file) f := NewNormalizedFile() assert.NotNil(t, f) - f.SetURI("file://" + file) + assert.Nil(t, f.SetURI("file://" + file)) assert.NotEqual(t, file, f.Path) assert.Equal(t, absFilePath, f.Path) @@ -290,8 +290,9 @@ func TestFileResourceFileInfo(t *testing.T) { f.State = "present" assert.Nil(t, f.Apply()) - f.Read(context.Background()) - + _, readErr := f.Read(context.Background()) + assert.Nil(t, readErr) + fi := f.FileInfo() assert.Equal(t, os.FileMode(0600), fi.Mode().Perm()) } @@ -309,7 +310,8 @@ func TestFileClone(t *testing.T) { f.State = "present" assert.Nil(t, f.Apply()) - f.Read(ctx) + _, readErr := f.Read(ctx) + assert.Nil(t, readErr) time.Sleep(100 * time.Millisecond) @@ -319,7 +321,9 @@ func TestFileClone(t *testing.T) { clone.Path = testCloneFile assert.Nil(t, clone.Apply()) - f.Read(ctx) + _, readErr := f.Read(ctx) + assert.Nil(t, readErr) + clone.Read(ctx) fmt.Printf("file %#v\nclone %#v\n", f, clone) diff --git a/internal/resource/user.go b/internal/resource/user.go index c673868..9803b0e 100644 --- a/internal/resource/user.go +++ b/internal/resource/user.go @@ -228,7 +228,6 @@ func (u *UserType) NewCRUD() (create *Command, read *Command, update *Command, d } return NewUserAddCreateCommand(), NewUserReadCommand(), NewUserUpdateCommand(), NewUserDelDeleteCommand() } - return nil, nil, nil, nil } func (u *UserType) UnmarshalValue(value string) error { @@ -271,12 +270,14 @@ func NewUserAddCreateCommand() *Command { } c.Extractor = func(out []byte, target any) error { return nil +/* for _,line := range strings.Split(string(out), "\n") { if line == "iptables: Chain already exists." { return nil } } return fmt.Errorf(string(out)) +*/ } return c } @@ -295,12 +296,14 @@ func NewAddUserCreateCommand() *Command { } c.Extractor = func(out []byte, target any) error { return nil +/* for _,line := range strings.Split(string(out), "\n") { if line == "iptables: Chain already exists." { return nil } } return fmt.Errorf(string(out)) +*/ } return c } diff --git a/internal/target/tar.go b/internal/target/tar.go index c1ac122..38368d7 100644 --- a/internal/target/tar.go +++ b/internal/target/tar.go @@ -73,10 +73,7 @@ func (t *Tar) EmitResources(documents []*resource.Document, filter resource.Reso for _,document := range documents { for _,res := range document.Filter(func(d *resource.Declaration) bool { - if d.Type == "file" { - return true - } - return false + return d.Type == "file" }) { var f *resource.File = res.Attributes.(*resource.File) slog.Info("Tar.EmitResources", "file", f)