-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutil_test.go
88 lines (73 loc) · 2.46 KB
/
util_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
82
83
84
85
86
87
88
package gittp
import (
"bytes"
"fmt"
"net/url"
"testing"
)
func parseURL(raw string) (parsed *url.URL) {
parsed, _ = url.Parse(raw)
return
}
func Test_parseRepoName(t *testing.T) {
testCases := map[string]string{
"/adam/project.git/info/refs?service=git-receive-pack": "adam/project.git",
"/adam/dude/project.git/info/refs?service=git-receive-pack": "adam/dude/project.git",
"/adam/project.git": errNotAGitRequest.Error(),
"/adam/gittp.git/git-receive-pack": "adam/gittp.git",
"/adam/gittp/info/refs?service=git-receive-pack": "adam/gittp",
"/adam/dude/project/git-receive-pack": "adam/dude/project",
"/adamveld12/goku.git/info/refs?service=git-receive-pack": "adamveld12/goku.git",
}
for input, expected := range testCases {
actual, err := parseRepoName(input)
if err != nil && err.Error() != expected {
t.Error(err)
} else if err == nil && actual != expected {
t.Errorf("expected:\n%s\nactual:\n%s\n", expected, actual)
}
}
}
func Test_pktline(t *testing.T) {
cases := map[string]string{
"000fHello world": "Hello world",
"0017☃woooo☃☃woooo": "☃woooo☃☃woooo",
}
for expected, testcase := range cases {
actual := pktline(testcase)
if !bytes.Equal([]byte(expected), actual) {
t.Errorf("expected:\n%s\nactual:\n%s\n", expected, actual)
}
}
}
func Test_encode(t *testing.T) {
cases := map[string]string{
"0010\u0002Hello world": "Hello world",
"0018\u0002☃woooo☃☃woooo": "☃woooo☃☃woooo",
}
for expected, testcase := range cases {
actual := encodeWithPrefix(progressStreamCode, testcase)
if !bytes.Equal([]byte(expected), actual) {
fmt.Println("expected:", []byte(expected))
fmt.Println("actual: ", actual)
t.Errorf("expected:\n%s\nactual:\n%s\n", expected, actual)
}
}
}
func Test_newPacketHeader(t *testing.T) {
// need to get some git-receive-pack data to test with
packData := []byte("00940000000000000000000000000000000000000000 68839ad5d8bedf1147c214e4897ca6ad8afbfecc refs/heads/master\x00report-status side-band-64k agent=git/2.8.30000")
actual := newPacketHeader(packData)
if actual.Agent != "git/2.8.3" {
t.Error(actual.Agent)
}
if actual.Branch != "refs/heads/master" {
t.Error(actual.Branch)
}
if actual.Last != "0000000000000000000000000000000000000000" {
t.Error(actual.Last)
}
if actual.Head != "68839ad5d8bedf1147c214e4897ca6ad8afbfecc" {
t.Error(actual.Head)
}
}