forked from alfg/widevine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
65 lines (52 loc) · 1002 Bytes
/
client_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
65
package widevine
import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
)
type testResponse struct {
Test string `json:"test"`
}
var server *httptest.Server
func TestMain(m *testing.M) {
setup()
retCode := m.Run()
teardown()
os.Exit(retCode)
}
func teardown() {
defer server.Close()
}
func setup() {
// Mock server.
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
fmt.Fprintln(w, `{"test": "testing123"}`)
}))
}
func TestGet(t *testing.T) {
// Test client.
resp := testResponse{}
client, _ := NewClient()
err := client.get(server.URL, &resp)
if err != nil {
t.Error()
}
if resp.Test != "testing123" {
t.Error()
}
}
func TestPost(t *testing.T) {
// Test client.
resp := testResponse{}
client, _ := NewClient()
err := client.post(server.URL, &resp, map[string]interface{}{})
if err != nil {
t.Error()
}
if resp.Test != "testing123" {
t.Error()
}
}