-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmisc_test.go
48 lines (39 loc) · 1.05 KB
/
misc_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 backlog
import (
"fmt"
"log"
"net/http"
"os"
"testing"
)
func TestErrorResponse(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/space", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusNotFound)
if _, err := fmt.Fprint(w, `{"errors":[{"message": "No space.", "code": 6, "moreInfo": ""}]}`); err != nil {
t.Fatal(err)
}
})
client.debug = true
client.httpclient = &http.Client{}
client.log = log.New(os.Stdout, "backlog: ", log.Lshortfile|log.LstdFlags)
client.Debugf("%s", "test")
client.Debugln("test")
if _, err := client.GetSpace(); err == nil {
t.Fatal("expected an error but got none", err)
}
}
func TestStatusUnAuthorized(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/space", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusUnauthorized)
})
_, err := client.GetSpace()
if err == nil {
t.Fatal("expected an error but got none", err)
}
}