-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroutes_test.go
81 lines (61 loc) · 2.36 KB
/
routes_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
76
77
78
79
80
81
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInfo(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/info"), "\"test-repo.git\"")
}
func TestInfoCurrentDir(t *testing.T) {
assert.Contains(t, request(t, "", "/api/info"), "\"gitviz\"")
}
func TestGraph(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/graph"), "f07c09068550591ffd7efda7814ec1dfda4a0da8")
}
func TestGraphCurrentDir(t *testing.T) {
assert.Contains(t, request(t, "", "/api/graph"), "\"from\":\"HEAD\"")
}
func TestObjectCommit(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/objects/commit/5b4ddc33ef3da7a248025cc228bc9ef7e860740a"), "author Manuel Riezebosch <[email protected]>")
}
func TestObjectBlob(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/objects/blob/f07c09068550591ffd7efda7814ec1dfda4a0da8"), "<html>")
}
func TestRef(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/refs/heads/simple-merge"), "6de25b8c5cd0cd49dc40d91e96f8e1cc9c2d07d8")
}
func TestFolderRef(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/refs/heads/feature/x"), "5b4ddc33ef3da7a248025cc228bc9ef7e860740a")
}
func TestRefTag(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/refs/tags/R0.1"), "07870fcf1cae67fcee108e7e0bac81a4c69842d0")
}
func TestRefRemoteTrackingBranch(t *testing.T) {
assert.NotEmpty(t, request(t, "test-repo.git", "/api/refs/remotes/github/master"))
}
func TestRefHead(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/refs/HEAD"), "ref: refs/heads/master")
}
func TestIndex(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", ""), "<html>")
}
func TestFavicon(t *testing.T) {
assert.NotContains(t, request(t, "test-repo.git", "/favicon.ico"), "404")
}
func TestObjectTree(t *testing.T) {
assert.Contains(t, request(t, "test-repo.git", "/api/objects/tree/4e84516b47b89c12f2f9bf41f34725ef6ddce099"), "Main.go")
}
func request(t *testing.T, repo string, path string) string {
ts := httptest.NewServer(Routes(repo))
defer ts.Close()
req, err := http.NewRequest("GET", ts.URL+path, nil)
assert.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
assert.NoError(t, err)
body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
return string(body)
}