-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
41 lines (32 loc) · 996 Bytes
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/pranav93/RackspaceAssignment/setup"
)
func TestPingRoute(t *testing.T) {
// The setupServer method, that we previously refactored
// is injected into a test server
ts := httptest.NewServer(setup.Server())
// Shut down the server and block until all requests have gone through
defer ts.Close()
// Make a request to our server with the {base url}/ping
resp, err := http.Get(fmt.Sprintf("%s/", ts.URL))
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if resp.StatusCode != 200 {
t.Fatalf("Expected status code 200, got %v", resp.StatusCode)
}
val, ok := resp.Header["Content-Type"]
// Assert that the "content-type" header is actually set
if !ok {
t.Fatalf("Expected Content-Type header to be set")
}
// Assert that it was set as expected
if val[0] != "application/json; charset=utf-8" {
t.Fatalf("Expected \"application/json; charset=utf-8\", got %s", val[0])
}
}