-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit_test.go
64 lines (48 loc) · 1.35 KB
/
git_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
package main
import (
"testing"
)
func TestGetRemoteUrlOrigin(t *testing.T) {
output := []byte(`
origin https://github.com/educas/lab (fetch)
`)
parsed, err := getRemoteUrlFromRemoteVOutput("origin", output)
if err != nil {
t.Fatal(err)
}
if parsed != "https://github.com/educas/lab" {
t.Fatal(parsed)
}
}
func TestGetRemoteUrlFromNothing(t *testing.T) {
output := []byte("")
parsed, err := getRemoteUrlFromRemoteVOutput("whatever", output)
if parsed != "" {
t.Fatal("Should not get parsed output:", parsed)
}
if _, ok := err.(ErrUnknownRemote); !ok {
t.Fatalf("Expected ErrNoOrigin error, got: %+v\n", err, err)
}
}
func TestGetOtherRemoteUrl(t *testing.T) {
output := []byte(`
origin https://something.com/wrong
something https://something.com/right
`)
parsed, err := getRemoteUrlFromRemoteVOutput("something", output)
if parsed != "https://something.com/right" {
t.Fatal("Expected remote: \"https://something.com/right\", got:", parsed)
}
if nil != err {
t.Fatal(err)
}
}
func TestParseGitHttpRemote(t *testing.T) {
remote := parseRemote("https://git.something.org/someday/somewhere.git")
if remote.base != "git.something.org" {
t.Fatal("Expected remote base: \"git.something.org\", got:", remote.base)
}
if remote.path != "someday/somewhere" {
t.Fatal("Expected remote path: \"someday/somewhere\", got:", remote.path)
}
}