Skip to content

Commit 2758a5a

Browse files
committed
sca
1 parent 99216a3 commit 2758a5a

File tree

13 files changed

+33
-37
lines changed

13 files changed

+33
-37
lines changed

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ linters-settings:
44
exhaustive:
55
default-signifies-exhaustive: false
66
funlen:
7-
lines: 120
8-
statements: 120
7+
lines: 150
8+
statements: 150
99
gci:
1010
local-prefixes: github.com/cloudradar-monitoring/tacoscript
1111
goconst:
@@ -25,7 +25,7 @@ linters-settings:
2525
- whyNoLint
2626
- wrapperFunc
2727
gocyclo:
28-
min-complexity: 20
28+
min-complexity: 30
2929
goimports:
3030
local-prefixes: github.com/golangci/golangci-lint
3131
golint:

apptest/fs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package apptest
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
76
"net/url"
87
"os"
98
"time"
@@ -62,7 +61,7 @@ func AssertFileMatchesExpectation(fe *FileExpectation) (isExpectationMatched boo
6261
return true, "", nil
6362
}
6463

65-
fileContentsBytes, err := ioutil.ReadFile(fe.FilePath)
64+
fileContentsBytes, err := os.ReadFile(fe.FilePath)
6665
if err != nil {
6766
return false, "", err
6867
}

apptest/fsOSWin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
package apptest
55

6-
func AssertFileMatchesExpectationOS(filePath string, fe *FileExpectation) (bool, string, error) {
6+
func AssertFileMatchesExpectationOS(filePath string, fe *FileExpectation) (isMatched bool, reason string, err error) {
77
return true, "", nil
88
}

cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type errorResult struct {
4141

4242
func Execute() error {
4343
if err := rootCmd.Execute(); err != nil {
44-
4544
logrus.Debugf("Execute failed: %v", err)
4645

4746
y, _ := yaml.Marshal(errorResult{Error: err.Error()})

conv/conv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func ConvertToKeyValues(val interface{}, path string) (KeyValues, error) {
4646
key := item.Key.(string)
4747
val := item.Value
4848
res = append(res, KeyValue{
49-
Key: fmt.Sprint(key),
49+
Key: key,
5050
Value: fmt.Sprint(val),
5151
})
5252
}

exec/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (sr SystemRunner) createCmd(execContext *Context, tmpFile *os.File) (cmd *e
174174

175175
rawCmds := prelude + strings.Join(execContext.Cmds, newLine)
176176

177-
if _, err = tmpFile.Write([]byte(rawCmds)); err != nil {
177+
if _, err = tmpFile.WriteString(rawCmds); err != nil {
178178
return
179179
}
180180

script/builder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"io/ioutil"
7+
"os"
88
"text/template"
99

1010
"github.com/cloudradar-monitoring/tacoscript/utils"
@@ -19,7 +19,7 @@ type FileDataProvider struct {
1919
}
2020

2121
func (fdp FileDataProvider) Read() ([]byte, error) {
22-
return ioutil.ReadFile(fdp.Path)
22+
return os.ReadFile(fdp.Path)
2323
}
2424

2525
type RawDataProvider interface {
@@ -83,7 +83,7 @@ func (p Builder) BuildScripts() (tasks.Scripts, error) {
8383
script.Tasks = append(script.Tasks, task)
8484
}
8585
} else {
86-
errs.Add(fmt.Errorf("Script failed to run. Input YAML is malformed."))
86+
errs.Add(fmt.Errorf("script failed to run. input YAML is malformed"))
8787
}
8888
scripts = append(scripts, script)
8989
}

script/builder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package script
33
import (
44
"context"
55
"errors"
6-
"io/ioutil"
76
"os"
7+
"path/filepath"
88
"testing"
99

1010
"github.com/cloudradar-monitoring/tacoscript/utils"
@@ -65,7 +65,7 @@ func (tm *TaskBuilderTaskMock) GetPath() string {
6565

6666
func (rdpm RawDataProviderMock) Read() ([]byte, error) {
6767
if rdpm.FileName != "" {
68-
return ioutil.ReadFile("yaml" + string(os.PathSeparator) + rdpm.FileName)
68+
return os.ReadFile(filepath.Join("yaml", rdpm.FileName))
6969
}
7070

7171
return []byte(rdpm.DataToReturn), rdpm.ErrToReturn

tasks/fileManagedTask.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"database/sql"
77
"fmt"
8+
"io/fs"
89
"os"
910
"time"
1011

@@ -185,10 +186,9 @@ func (crt *FileManagedTask) GetPath() string {
185186
return crt.Path
186187
}
187188

188-
/*
189189
func (crt *FileManagedTask) String() string {
190190
return fmt.Sprintf("task '%s' at path '%s'", crt.TypeName, crt.GetPath())
191-
}*/
191+
}
192192

193193
type HashManager interface {
194194
HashEquals(hashStr, filePath string) (hashEquals bool, actualCache string, err error)
@@ -265,7 +265,8 @@ func (fmte *FileManagedTaskExecutor) Execute(ctx context.Context, task Task) Exe
265265
}
266266
fileManagedTask.Updated = true
267267

268-
info, err := fmte.FsManager.Stat(fileManagedTask.Name)
268+
var info fs.FileInfo
269+
info, err = fmte.FsManager.Stat(fileManagedTask.Name)
269270
if err != nil {
270271
execRes.Err = err
271272
return execRes
@@ -316,7 +317,7 @@ func (fmte *FileManagedTaskExecutor) checkOnlyIfs(ctx *exec2.Context, fileManage
316317
if err != nil {
317318
runErr, isRunErr := err.(exec2.RunError)
318319
if isRunErr {
319-
logrus.Debugf("will skip %s since onlyif condition has failed: %v", fileManagedTask, runErr)
320+
logrus.Debugf("will skip %s since onlyif condition has failed: %v", fileManagedTask.String(), runErr)
320321
return false, nil
321322
}
322323

@@ -376,7 +377,7 @@ func (fmte *FileManagedTaskExecutor) shouldBeExecuted(
376377
return skipReasonForContents, nil
377378
}
378379

379-
logrus.Debugf("all execution conditions are met, will continue %s", fileManagedTask)
380+
logrus.Debugf("all execution conditions are met, will continue %s", fileManagedTask.String())
380381
return "", nil
381382
}
382383

tasks/fileManagedTask_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8-
"io/ioutil"
98
"net/url"
9+
"os"
1010
"os/exec"
1111
"strings"
1212
"testing"
@@ -75,27 +75,27 @@ func TestFileManagedTaskExecution(t *testing.T) {
7575
"sourceFileFTP.txt",
7676
}
7777

78-
err = ioutil.WriteFile("sourceFileAtLocal.txt", []byte("one two three"), 0600)
78+
err = os.WriteFile("sourceFileAtLocal.txt", []byte("one two three"), 0600)
7979
assert.NoError(t, err)
8080
if err != nil {
8181
return
8282
}
8383

84-
err = ioutil.WriteFile("sourceFileHTTPS.txt", []byte("one two three"), 0600)
84+
err = os.WriteFile("sourceFileHTTPS.txt", []byte("one two three"), 0600)
8585
assert.NoError(t, err)
8686
if err != nil {
8787
return
8888
}
8989
httpsSrvURL.Path = "/sourceFileHTTPS.txt"
9090

91-
err = ioutil.WriteFile("sourceFileHTTP.txt", []byte("one two three"), 0600)
91+
err = os.WriteFile("sourceFileHTTP.txt", []byte("one two three"), 0600)
9292
assert.NoError(t, err)
9393
if err != nil {
9494
return
9595
}
9696
httpSrvURL.Path = "/sourceFileHTTP.txt"
9797

98-
err = ioutil.WriteFile("sourceFileFTP.txt", []byte("one two three"), 0600)
98+
err = os.WriteFile("sourceFileFTP.txt", []byte("one two three"), 0600)
9999
assert.NoError(t, err)
100100
if err != nil {
101101
return
@@ -541,7 +541,7 @@ three`,
541541
if tc.ContentEncodingToWrite != "" {
542542
e = utils.WriteEncodedFile(tc.ContentEncodingToWrite, tc.ContentToWrite, tc.Task.Name, 0600)
543543
} else {
544-
e = ioutil.WriteFile(tc.Task.Name, []byte(tc.ContentToWrite), 0600)
544+
e = os.WriteFile(tc.Task.Name, []byte(tc.ContentToWrite), 0600)
545545
}
546546
assert.NoError(t, e)
547547
}

0 commit comments

Comments
 (0)