Fix golang-ci linter errors (#10128)
* Fix golang-ci linter errors Signed-off-by: z1cheng <imchench@gmail.com> * Fix gofmt errors Signed-off-by: z1cheng <imchench@gmail.com> * Add nolint comment to defaults.Backend in Configuration Signed-off-by: z1cheng <imchench@gmail.com> * Add #nosec comment to rand.New func Signed-off-by: z1cheng <imchench@gmail.com> * Fix errcheck warnings Signed-off-by: z1cheng <imchench@gmail.com> * Fix gofmt check Signed-off-by: z1cheng <imchench@gmail.com> * Fix unit tests and comments Signed-off-by: z1cheng <imchench@gmail.com> --------- Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
parent
f50431a9f9
commit
d44a8e0045
37 changed files with 206 additions and 162 deletions
|
|
@ -76,7 +76,10 @@ func TestNginxCheck(t *testing.T) {
|
|||
})
|
||||
|
||||
// create pid file
|
||||
os.MkdirAll("/tmp/nginx", file.ReadWriteByUser)
|
||||
if err := os.MkdirAll("/tmp/nginx", file.ReadWriteByUser); err != nil {
|
||||
t.Errorf("unexpected error creating pid file: %v", err)
|
||||
}
|
||||
|
||||
pidFile, err := os.Create(nginx.PID)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
@ -90,14 +93,23 @@ func TestNginxCheck(t *testing.T) {
|
|||
|
||||
// start dummy process to use the PID
|
||||
cmd := exec.Command("sleep", "3600")
|
||||
cmd.Start()
|
||||
if err := cmd.Start(); err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
pid := cmd.Process.Pid
|
||||
defer cmd.Process.Kill()
|
||||
defer func() {
|
||||
if err := cmd.Process.Kill(); err != nil {
|
||||
t.Errorf("unexpected error killing the process: %v", err)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
cmd.Wait()
|
||||
cmd.Wait() //nolint:errcheck
|
||||
}()
|
||||
|
||||
pidFile.Write([]byte(fmt.Sprintf("%v", pid)))
|
||||
if _, err := pidFile.Write([]byte(fmt.Sprintf("%v", pid))); err != nil {
|
||||
t.Errorf("unexpected error writing the pid file: %v", err)
|
||||
}
|
||||
|
||||
pidFile.Close()
|
||||
|
||||
healthz.InstallPathHandler(mux, tt.healthzPath, n)
|
||||
|
|
@ -109,7 +121,7 @@ func TestNginxCheck(t *testing.T) {
|
|||
})
|
||||
|
||||
// pollute pid file
|
||||
pidFile.Write([]byte("999999"))
|
||||
pidFile.Write([]byte("999999")) //nolint:errcheck
|
||||
pidFile.Close()
|
||||
|
||||
t.Run("bad pid", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue