-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_test.go
56 lines (48 loc) · 1.13 KB
/
status_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
package uststat
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"testing"
)
type mockTransport struct {
live bool
}
func newMockTransport(live bool) http.RoundTripper {
return &mockTransport{live: live}
}
func (t *mockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
response := &http.Response{
Header: make(http.Header),
Request: req,
StatusCode: http.StatusOK,
}
response.Header.Set("Content-Type", "application/json")
var status string
if t.live {
status = "live"
} else {
status = "offline"
}
responseBody := fmt.Sprintf(`{"channel": {"status": "%s"}}`, status)
response.Body = ioutil.NopCloser(strings.NewReader(responseBody))
return response, nil
}
func TestClient_IsLiveByChannelID(t *testing.T) {
var (
c *Client
b bool
err error
)
c, _ = New(WithHTTPTransport(newMockTransport(true)))
b, err = c.IsLiveByChannelID("1234567")
if !b || err != nil {
t.Errorf("Expected true, got %v, %v", b, err)
}
c, _ = New(WithHTTPTransport(newMockTransport(false)))
b, err = c.IsLiveByChannelID("1234567")
if b || err != nil {
t.Errorf("Expected false, got %v, %v", b, err)
}
}