-
Notifications
You must be signed in to change notification settings - Fork 5
/
methods_test.go
75 lines (58 loc) · 1.8 KB
/
methods_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
66
67
68
69
70
71
72
73
74
75
package gogi
import (
"encoding/json"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestList(t *testing.T) {
setUp()
defer tearDown()
path := fmt.Sprintf("%s/list", typePath)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte("test list"))
})
data, err := client.List()
require.NoError(t, err)
expected := "test list"
assert.Equal(t, expected, data)
}
func TestListJson(t *testing.T) {
setUp()
defer tearDown()
goItem := &ListJsonItem{
Contents: "\n### Go ###\n# Binaries for programs and plugins\n*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n\n# Test binary, built with `go test -c`\n*.test\n\n# Output of the go coverage tool, specifically when used with LiteIDE\n*.out\n\n# Dependency directories (remove the comment below to include it)\n# vendor/\n\n### Go Patch ###\n/vendor/\n/Godeps/\n",
FileName: "Go.gitignore",
Key: "go",
Name: "go",
}
path := fmt.Sprintf("%s/list", typePath)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
assert.Equal(t, "json", r.URL.Query().Get("format"))
res := map[string]*ListJsonItem{
"go": goItem,
}
assert.NoError(t, json.NewEncoder(w).Encode(res))
})
data, err := client.ListJson()
require.NoError(t, err)
assert.Len(t, data, 1)
assert.Equal(t, goItem, data["go"])
}
func TestCreate(t *testing.T) {
setUp()
defer tearDown()
path := fmt.Sprintf("%s/foo", typePath)
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, "GET", r.Method)
_, _ = w.Write([]byte("test create foo"))
})
data, err := client.Create("foo")
require.NoError(t, err)
expected := "test create foo"
assert.Equal(t, expected, data)
}