This repository has been archived by the owner on Mar 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestExitWithBadResponseStatus(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusServiceUnavailable) | ||
})) | ||
defer ts.Close() | ||
|
||
var raw []byte | ||
|
||
origLogFatalf := logFatalf | ||
|
||
// After this test, replace the original fatal function | ||
defer func() { logFatalf = origLogFatalf }() | ||
|
||
var actualError string | ||
logFatalf = func(format string, args ...interface{}) { | ||
if len(args) > 0 { | ||
actualError = fmt.Sprintf(format, args) | ||
} else { | ||
actualError = format | ||
} | ||
} | ||
|
||
postMessage(raw, nil, ts.URL) | ||
expectedError := "Failed to post message, flowdock api returned: [503 Service Unavailable]" | ||
if actualError == expectedError { | ||
return | ||
} | ||
t.Fatalf("Expected error:\n%s\ngot:\n%s", expectedError, actualError) | ||
} |