-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathresult_test.go
64 lines (52 loc) · 1.41 KB
/
result_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package bamboo_test
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
bamboo "github.com/rcarmstrong/go-bamboo"
)
func TestLatestResult(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(latestResultStub))
defer ts.Close()
client := bamboo.NewSimpleClient(nil, "", "")
client.SetURL(ts.URL)
_, resp, err := client.Results.LatestResult("CORE-TEST")
if err != nil {
if resp != nil {
t.Log(resp.Status)
}
t.Error(err)
}
}
func latestResultStub(w http.ResponseWriter, r *http.Request) {
var expectedURL = "CORE-TEST-latest"
check := strings.Split(strings.Split(r.URL.String(), "result/")[1], "?")[0]
if check == expectedURL && r.Method == http.MethodGet {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusBadRequest)
}
}
func TestNumberedResult(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(numberedResultStub))
defer ts.Close()
client := bamboo.NewSimpleClient(nil, "", "")
client.SetURL(ts.URL)
_, resp, err := client.Results.NumberedResult("CORE-TEST-1")
if err != nil {
if resp != nil {
t.Log(resp.Status)
}
t.Error(err)
}
}
func numberedResultStub(w http.ResponseWriter, r *http.Request) {
var expectedURL = "CORE-TEST-1"
check := strings.Split(strings.Split(r.URL.String(), "result/")[1], "?")[0]
if check == expectedURL && r.Method == http.MethodGet {
w.WriteHeader(http.StatusOK)
} else {
w.WriteHeader(http.StatusBadRequest)
}
}