-
Notifications
You must be signed in to change notification settings - Fork 1
/
request_test.go
48 lines (38 loc) · 1.14 KB
/
request_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
42
43
44
45
46
47
48
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func Test200Response(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `response from the mock server goes here`)
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 - OK!"))
}))
defer ts.Close()
mockServerURL := ts.URL
checkStatus(mockServerURL, 1, false, 1)
}
func Test404Response(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `response from the mock server goes here`)
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("404 - Not Found!"))
}))
defer ts.Close()
mockServerURL := ts.URL
checkStatus(mockServerURL, 1, false, 1)
}
//300 status code check
func Test300Response(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `response from the mock server goes here`)
w.WriteHeader(http.StatusMultipleChoices)
w.Write([]byte("300 - Multiple choices!"))
}))
defer ts.Close()
mockServerURL := ts.URL
checkStatus(mockServerURL, 1, false, 1)
}