-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In an attempt to: - make on-boarding a bit easier (`go test ./...` should now not need additional postgres setup) - get code coverage faster, not only scheduled at night - test the `create-account` binary
- Loading branch information
Showing
6 changed files
with
197 additions
and
77 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
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,54 @@ | ||
package pushgateway | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestNotify(t *testing.T) { | ||
wantResponse := NotifyResponse{ | ||
Rejected: []string{"testing"}, | ||
} | ||
|
||
var i = 0 | ||
|
||
svr := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// /notify only accepts POST requests | ||
if r.Method != http.MethodPost { | ||
w.WriteHeader(http.StatusNotImplemented) | ||
return | ||
} | ||
|
||
if i != 0 { // error path | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
|
||
// happy path | ||
json.NewEncoder(w).Encode(wantResponse) | ||
})) | ||
defer svr.Close() | ||
|
||
cl := NewHTTPClient(true) | ||
gotResponse := NotifyResponse{} | ||
|
||
// Test happy path | ||
err := cl.Notify(context.Background(), svr.URL, &NotifyRequest{}, &gotResponse) | ||
if err != nil { | ||
t.Errorf("failed to notify client") | ||
} | ||
if !reflect.DeepEqual(gotResponse, wantResponse) { | ||
t.Errorf("expected response %+v, got %+v", wantResponse, gotResponse) | ||
} | ||
|
||
// Test error path | ||
i++ | ||
err = cl.Notify(context.Background(), svr.URL, &NotifyRequest{}, &gotResponse) | ||
if err == nil { | ||
t.Errorf("expected notifying the pushgateway to fail, but it succeeded") | ||
} | ||
} |