-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpriority_test.go
More file actions
80 lines (65 loc) · 1.71 KB
/
priority_test.go
File metadata and controls
80 lines (65 loc) · 1.71 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package backlog
import (
"fmt"
"net/http"
"net/url"
"reflect"
"strings"
"testing"
"github.com/kylelemons/godebug/pretty"
"github.com/pkg/errors"
)
const testJSONPriority string = `{
"id": 2,
"name": "高"
}`
func getTestPriority() *Priority {
return &Priority{
ID: Int(2),
Name: String("高"),
}
}
func TestGetPriorities(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/priorities", func(w http.ResponseWriter, _ *http.Request) {
j := fmt.Sprintf("[%s]", testJSONPriority)
if _, err := fmt.Fprint(w, j); err != nil {
t.Fatal(err)
}
})
expected, err := client.GetPriorities()
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
want := []*Priority{getTestPriority()}
if !reflect.DeepEqual(want, expected) {
t.Fatal(ErrIncorrectResponse, errors.New(pretty.Compare(want, expected)))
}
}
func TestGetPrioritiesFailed(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/priorities", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
})
if _, err := client.GetPriorities(); err == nil {
t.Fatal("expected an error but got none")
}
}
func TestGetPriorities_NewRequestError(t *testing.T) {
client, _, _, teardown := setup()
defer teardown()
originalBaseURL := client.baseURL
invalidURL, _ := url.Parse("https://example.com/api/v2/")
client.baseURL = invalidURL
_, err := client.GetPriorities()
if err == nil {
t.Error("Expected error for invalid baseURL")
}
if err != nil && !strings.Contains(err.Error(), "trailing slash") {
t.Errorf("Expected error message to contain 'trailing slash', got %v", err.Error())
}
client.baseURL = originalBaseURL
}