-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pkg/healthsrv): add tests to complete all failure cases in the he…
…alth probe handler
- Loading branch information
Aaron Schlesinger
committed
Feb 9, 2016
1 parent
692fbdb
commit e792bcc
Showing
4 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package healthsrv | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/arschles/assert" | ||
"github.com/deis/builder/pkg/sshd" | ||
) | ||
|
||
var ( | ||
testErr = errors.New("test error") | ||
) | ||
|
||
func TestHealthZCircuitOpen(t *testing.T) { | ||
nsLister := emptyNamespaceLister{} | ||
bLister := emptyBucketLister{} | ||
c := sshd.NewCircuit() | ||
|
||
h := healthZHandler(nsLister, bLister, c) | ||
w := httptest.NewRecorder() | ||
r, err := http.NewRequest("GET", "/healthz", bytes.NewBuffer(nil)) | ||
assert.NoErr(t, err) | ||
h.ServeHTTP(w, r) | ||
assert.Equal(t, w.Code, http.StatusServiceUnavailable, "response code") | ||
expectedBody := "SSH Server is not yet started" | ||
assert.Equal(t, strings.TrimSpace(string(w.Body.Bytes())), expectedBody, "response body") | ||
} | ||
|
||
func TestHealthZBucketListErr(t *testing.T) { | ||
nsLister := emptyNamespaceLister{} | ||
bLister := errBucketLister{err: testErr} | ||
c := sshd.NewCircuit() | ||
c.Close() | ||
h := healthZHandler(nsLister, bLister, c) | ||
|
||
w := httptest.NewRecorder() | ||
r, err := http.NewRequest("GET", "/healthz", bytes.NewBuffer(nil)) | ||
assert.NoErr(t, err) | ||
h.ServeHTTP(w, r) | ||
assert.Equal(t, w.Code, http.StatusServiceUnavailable, "response code") | ||
expectedBody := fmt.Sprintf("Error listing buckets (%s)", testErr) | ||
assert.Equal(t, strings.TrimSpace(string(w.Body.Bytes())), expectedBody, "response body") | ||
} | ||
|
||
func TestHealthZNamespaceListErr(t *testing.T) { | ||
nsLister := errNamespaceLister{err: testErr} | ||
bLister := emptyBucketLister{} | ||
c := sshd.NewCircuit() | ||
c.Close() | ||
|
||
h := healthZHandler(nsLister, bLister, c) | ||
w := httptest.NewRecorder() | ||
r, err := http.NewRequest("GET", "/healthz", bytes.NewBuffer(nil)) | ||
assert.NoErr(t, err) | ||
h.ServeHTTP(w, r) | ||
assert.Equal(t, w.Code, http.StatusServiceUnavailable, "response code") | ||
expectedBody := fmt.Sprintf("Error listing namespaces (%s)", testErr) | ||
assert.Equal(t, strings.TrimSpace(string(w.Body.Bytes())), expectedBody, "response body") | ||
} | ||
|
||
func TestHealthZSuccess(t *testing.T) { | ||
t.Skip("TODO") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters