forked from rhysd/dot-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository_test.go
72 lines (65 loc) · 1.7 KB
/
repository_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
package main
import (
"strings"
"testing"
)
func TestWebURL(t *testing.T) {
r := NewRepositoryFromURL("https://github.com/rhysd/dot-github.git")
if r.User != "rhysd" {
t.Fatalf("User name is invalid: %v", r.User)
}
if r.Name != "dot-github" {
t.Fatalf("Repository name is invalid: %v", r.Name)
}
if !strings.HasSuffix(r.Path, "dot-github") {
t.Fatalf("Repository root must end with its name: %v", r.Path)
}
}
func TestGitURL(t *testing.T) {
r := NewRepositoryFromURL("git://github.com/rhysd/dot-github.git")
if r.User != "rhysd" {
t.Fatalf("User name is invalid: %v", r.User)
}
if r.Name != "dot-github" {
t.Fatalf("Repository name is invalid: %v", r.Name)
}
if !strings.HasSuffix(r.Path, "dot-github") {
t.Fatalf("Repository root must end with its name: %v", r.Path)
}
}
func TestSshURL(t *testing.T) {
r := NewRepositoryFromURL("[email protected]:rhysd/dot-github.git")
if r.User != "rhysd" {
t.Fatalf("User name is invalid: %v", r.User)
}
if r.Name != "dot-github" {
t.Fatalf("Repository name is invalid: %v", r.Name)
}
if !strings.HasSuffix(r.Path, "dot-github") {
t.Fatalf("Repository root must end with its name: %v", r.Path)
}
}
func TestInvalidPath(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("URL without path must cause panic")
}
}()
NewRepositoryFromURL("https://github.com")
}
func TestInvalidGitURL(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Invalid URL must cause panic")
}
}()
NewRepositoryFromURL("invalid-blah")
}
func TestInvalidURLScheme(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Invalid Scheme must cause panic")
}
}()
NewRepositoryFromURL("file://blah.jp")
}