-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
66 lines (59 loc) · 1.11 KB
/
main_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
package main
import (
"net/url"
"testing"
)
func TestErrShortURL(t *testing.T) {
// fail on truncated url
u, err := url.Parse("https://example.com/insufficient")
if err != nil {
t.Fatal(err)
}
t.Log(u)
_, _, err = paths(u)
_, ok := err.(ErrShortURL)
if !ok {
t.Fatalf("err should be ErrShortUrl, got %T", err)
}
}
func TestPaths(t *testing.T) {
gotExp := "got:%v expected:%v"
type test struct {
argURL string
truncatedURL *url.URL
gitPath string
}
goodURL, err := url.Parse("https://example.com/one/two")
if err != nil {
t.Fatal(err)
}
cases := []test{
test{
"https://example.com/one/two/three",
goodURL,
"example.com/one/two",
},
test{
"https://example.com/one/two",
goodURL,
"example.com/one/two",
},
}
for _, c := range cases {
t.Log(c.argURL)
u, err := url.Parse(c.argURL)
if err != nil {
t.Fatal(err)
}
gitU, gitP, err := paths(u)
if err != nil {
t.Fatal(err)
}
if gitU.String() != c.truncatedURL.String() {
t.Fatalf(gotExp, gitU.String(), c.truncatedURL.String())
}
if gitP != c.gitPath {
t.Fatalf(gotExp, gitP, gitP)
}
}
}