Skip to content

Commit

Permalink
Add checker test for bad pid (#2191)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineco authored and aledbf committed Mar 9, 2018
1 parent dbbeffb commit 4a49d67
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions internal/ingress/controller/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func TestNginxCheck(t *testing.T) {

t.Run("no pid or process", func(t *testing.T) {
if err := callHealthz(true, mux); err == nil {
t.Errorf("expected an error but none returned")
t.Error("expected an error but none returned")
}
})

// create required files
// create pid file
fs.MkdirAll("/run", 0655)
pidFile, err := fs.Create("/run/nginx.pid")
if err != nil {
Expand All @@ -68,7 +68,7 @@ func TestNginxCheck(t *testing.T) {

t.Run("no process", func(t *testing.T) {
if err := callHealthz(true, mux); err == nil {
t.Errorf("expected an error but none returned")
t.Error("expected an error but none returned")
}
})

Expand All @@ -92,23 +92,20 @@ func TestNginxCheck(t *testing.T) {
}
})

pidFile, err = fs.Create("/run/nginx.pid")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
pidFile.Write([]byte(fmt.Sprintf("%v", pid)))
// pollute pid file
pidFile.Write([]byte(fmt.Sprint("999999")))
pidFile.Close()

t.Run("valid request", func(t *testing.T) {
t.Run("bad pid", func(t *testing.T) {
if err := callHealthz(true, mux); err == nil {
t.Errorf("expected an error but none returned")
t.Error("expected an error but none returned")
}
})

t.Run("invalid port", func(t *testing.T) {
n.cfg.ListenPorts.Status = 9000
if err := callHealthz(true, mux); err == nil {
t.Errorf("expected an error but none returned")
t.Error("expected an error but none returned")
}
})
}
Expand Down

0 comments on commit 4a49d67

Please sign in to comment.