Fix errcheck warnings

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
z1cheng 2023-06-28 16:10:39 +00:00 committed by k8s-infra-cherrypick-robot
parent 236a41a23b
commit 2bbd69e0d9
27 changed files with 207 additions and 70 deletions

View file

@ -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,25 @@ 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()
if err := cmd.Wait(); err != nil {
t.Errorf("unexpected error waiting for the process: %v", err)
}
}()
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 +123,9 @@ func TestNginxCheck(t *testing.T) {
})
// pollute pid file
pidFile.Write([]byte("999999"))
if _, err := pidFile.Write([]byte("999999")); err != nil {
t.Errorf("unexpected error polluting the pid file: %v", err)
}
pidFile.Close()
t.Run("bad pid", func(t *testing.T) {