Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checker test for bad pid #2191

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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