summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-03-28 21:24:12 +0300
committerValery Piashchynski <[email protected]>2021-03-29 13:33:06 +0300
commit5a6c8b22148d7e97d20cf94d4978557cf0faec37 (patch)
treefebd9dc96d3cc892fe8a83471fc1e888b5c2d4d2
parent92c5ee7ec150f48362fe839a73da9ec5fd646eb9 (diff)
- Fix new linters warningsv2.0.3
Signed-off-by: Valery Piashchynski <[email protected]>
-rwxr-xr-x.golangci.yml11
-rw-r--r--tests/mocks/mock_log.go20
-rw-r--r--tests/plugins/http/uploads_test.go8
-rw-r--r--tests/plugins/reload/reload_plugin_test.go46
-rwxr-xr-xutils/network.go2
5 files changed, 36 insertions, 51 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 5d3414ac..bfc69f57 100755
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -5,14 +5,6 @@ run:
skip-dirs:
- .github
- .git
- - tests
- skip-files:
- - plugins/http/tests/http_test.go
- - plugins/http/tests/plugin_test_old.go
- - plugins/http/tests/rpc_test_old.go
- - plugins/http/tests/config_test.go
- - plugins/static/tests/static_plugin_test.go
- - plugins/headers/tests/old.go
modules-download-mode: readonly
allow-parallel-runners: true
@@ -93,3 +85,6 @@ issues:
- funlen
- scopelint
- gocognit
+ - goconst
+ - noctx
+ - gosimple
diff --git a/tests/mocks/mock_log.go b/tests/mocks/mock_log.go
index 66c70b91..ad70f9c0 100644
--- a/tests/mocks/mock_log.go
+++ b/tests/mocks/mock_log.go
@@ -44,9 +44,7 @@ func (m *MockLogger) Debug(msg string, keyvals ...interface{}) {
defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
+ varargs = append(varargs, keyvals...)
m.ctrl.Call(m, "Debug", varargs...)
}
@@ -56,9 +54,7 @@ func (m *MockLogger) Warn(msg string, keyvals ...interface{}) {
defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
+ varargs = append(varargs, keyvals...)
m.ctrl.Call(m, "Warn", varargs...)
}
@@ -68,9 +64,7 @@ func (m *MockLogger) Info(msg string, keyvals ...interface{}) {
defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
+ varargs = append(varargs, keyvals...)
m.ctrl.Call(m, "Info", varargs...)
}
@@ -80,9 +74,7 @@ func (m *MockLogger) Error(msg string, keyvals ...interface{}) {
defer m.Unlock()
m.ctrl.T.Helper()
varargs := []interface{}{msg}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
+ varargs = append(varargs, keyvals...)
m.ctrl.Call(m, "Error", varargs...)
}
@@ -145,9 +137,7 @@ func (m *MockWithLogger) EXPECT() *MockWithLoggerMockRecorder {
func (m *MockWithLogger) With(keyvals ...interface{}) logger.Logger {
m.ctrl.T.Helper()
varargs := []interface{}{}
- for _, a := range keyvals {
- varargs = append(varargs, a)
- }
+ varargs = append(varargs, keyvals...)
ret := m.ctrl.Call(m, "With", varargs...)
ret0, _ := ret[0].(logger.Logger)
return ret0
diff --git a/tests/plugins/http/uploads_test.go b/tests/plugins/http/uploads_test.go
index 68d4cbae..bc7e17df 100644
--- a/tests/plugins/http/uploads_test.go
+++ b/tests/plugins/http/uploads_test.go
@@ -67,9 +67,9 @@ func TestHandler_Upload_File(t *testing.T) {
f := mustOpen(testFile)
defer func() {
- err := f.Close()
- if err != nil {
- t.Errorf("failed to close a file: error %v", err)
+ errC := f.Close()
+ if errC != nil {
+ t.Errorf("failed to close a file: error %v", errC)
}
}()
fw, err := w.CreateFormFile("upload", f.Name())
@@ -419,7 +419,7 @@ func fileString(f string, errNo int, mime string) string {
r, err := json.Marshal(v)
if err != nil {
- fmt.Println(fmt.Errorf("error marshalling fInfo, error: %v", err))
+ fmt.Println(fmt.Errorf("error marshaling fInfo, error: %v", err))
}
return string(r)
}
diff --git a/tests/plugins/reload/reload_plugin_test.go b/tests/plugins/reload/reload_plugin_test.go
index 2e246480..dcbedb0f 100644
--- a/tests/plugins/reload/reload_plugin_test.go
+++ b/tests/plugins/reload/reload_plugin_test.go
@@ -220,10 +220,10 @@ func randomlyChangeFile(t *testing.T) {
// let's try to randomly change it
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(500) // nolint:gosec
+ rSleep := rand.Int63n(500) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(hugeNumberOfFiles)) // nolint:gosec
- err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".txt"), []byte("Hello, Gophers!"), 0755) // nolint:gosec
+ rNum := rand.Int63n(int64(hugeNumberOfFiles)) //nolint:gosec
+ err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".txt"), []byte("Hello, Gophers!"), 0755) //nolint:gosec
assert.NoError(t, err)
}
}
@@ -339,20 +339,20 @@ func reloadFilteredExt(t *testing.T) {
// change files with abc extension
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(1000) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(hugeNumberOfFiles)) // nolint:gosec
- err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".abc"), []byte("Hello, Gophers!"), 0755) // nolint:gosec
+ rNum := rand.Int63n(int64(hugeNumberOfFiles)) //nolint:gosec
+ err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".abc"), []byte("Hello, Gophers!"), 0755) //nolint:gosec
assert.NoError(t, err)
}
// change files with def extension
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(1000) // nolint:gosec
+ rSleep := rand.Int63n(1000) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(hugeNumberOfFiles)) // nolint:gosec
- err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".def"), []byte("Hello, Gophers!"), 0755) // nolint:gosec
+ rNum := rand.Int63n(int64(hugeNumberOfFiles)) //nolint:gosec
+ err := ioutil.WriteFile(filepath.Join(testDir, "file_"+strconv.Itoa(int(rNum))+".def"), []byte("Hello, Gophers!"), 0755) //nolint:gosec
assert.NoError(t, err)
}
}
@@ -476,11 +476,11 @@ func reloadMoveSupport(t *testing.T) {
// move some files
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(500) // nolint:gosec
+ rSleep := rand.Int63n(500) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(33)) // nolint:gosec
- rDir := rand.Int63n(9) // nolint:gosec
- rExt := rand.Int63n(3) // nolint:gosec
+ rNum := rand.Int63n(int64(33)) //nolint:gosec
+ rDir := rand.Int63n(9) //nolint:gosec
+ rExt := rand.Int63n(3) //nolint:gosec
ext := []string{
".txt",
@@ -512,11 +512,11 @@ func removeFilesSupport(t *testing.T) {
// remove some files
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(500) // nolint:gosec
+ rSleep := rand.Int63n(500) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(100)) // nolint:gosec
- rDir := rand.Int63n(10) // nolint:gosec
- rExt := rand.Int63n(3) // nolint:gosec
+ rNum := rand.Int63n(int64(100)) //nolint:gosec
+ rDir := rand.Int63n(10) //nolint:gosec
+ rExt := rand.Int63n(3) //nolint:gosec
ext := []string{
".txt",
@@ -570,14 +570,14 @@ func randomChangesInRecursiveDirs(t *testing.T) {
}
for i := 0; i < 10; i++ {
// rand sleep
- rSleep := rand.Int63n(100) // nolint:gosec
+ rSleep := rand.Int63n(100) //nolint:gosec
time.Sleep(time.Millisecond * time.Duration(rSleep))
- rNum := rand.Int63n(int64(100)) // nolint:gosec
- rDir := rand.Int63n(10) // nolint:gosec
- rExt := rand.Int63n(3) // nolint:gosec
- rName := rand.Int63n(3) // nolint:gosec
+ rNum := rand.Int63n(int64(100)) //nolint:gosec
+ rDir := rand.Int63n(10) //nolint:gosec
+ rExt := rand.Int63n(3) //nolint:gosec
+ rName := rand.Int63n(3) //nolint:gosec
- err := ioutil.WriteFile(filepath.Join(dirs[rDir], filenames[rName]+strconv.Itoa(int(rNum))+ext[rExt]), []byte("Hello, Gophers!"), 0755) // nolint:gosec
+ err := ioutil.WriteFile(filepath.Join(dirs[rDir], filenames[rName]+strconv.Itoa(int(rNum))+ext[rExt]), []byte("Hello, Gophers!"), 0755) //nolint:gosec
assert.NoError(t, err)
}
}
diff --git a/utils/network.go b/utils/network.go
index e57854a8..b73363db 100755
--- a/utils/network.go
+++ b/utils/network.go
@@ -38,7 +38,7 @@ func CreateListener(address string) (net.Listener, error) {
if fileExists(dsn[1]) {
err := syscall.Unlink(dsn[1])
if err != nil {
- return nil, fmt.Errorf("error during the unlink syscall: error %v", err)
+ return nil, fmt.Errorf("error during the unlink syscall: error %w", err)
}
}
return net.Listen(dsn[0], dsn[1])