-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo_test.go
91 lines (88 loc) · 2.05 KB
/
repo_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
89
90
91
package main
import (
"errors"
"testing"
)
func TestRepoService_GetRepositoryURL(t *testing.T) {
type fields struct {
cmd Commander
}
tests := []struct {
name string
fields fields
want string
wantErr bool
}{
{
name: "https remote",
fields: fields{
cmd: TestCommander{Output: "https://github.com/Flexicon/gitopen.git", Error: nil},
},
want: "https://github.com/Flexicon/gitopen",
wantErr: false,
},
{
name: "git remote",
fields: fields{
cmd: TestCommander{Output: "[email protected]:Flexicon/gitopen.git", Error: nil},
},
want: "https://github.com/Flexicon/gitopen",
wantErr: false,
},
{
name: "non-github git remote",
fields: fields{
cmd: TestCommander{Output: "[email protected]:gitlab-org/ruby/gems/gitlab-styles.git", Error: nil},
},
want: "https://gitlab.com/gitlab-org/ruby/gems/gitlab-styles",
wantErr: false,
},
{
name: "ssh remote",
fields: fields{
cmd: TestCommander{Output: "ssh://[email protected]/Flexicon/gitopen", Error: nil},
},
want: "https://github.com/Flexicon/gitopen",
wantErr: false,
},
{
name: "ssh remote - longer",
fields: fields{
cmd: TestCommander{Output: "ssh://[email protected]/Homebrew/homebrew-core", Error: nil},
},
want: "https://github.com/Homebrew/homebrew-core",
wantErr: false,
},
{
name: "invalid remote",
fields: fields{
cmd: TestCommander{Output: "i-am-invalid", Error: nil},
},
want: "",
wantErr: true,
},
{
name: "command error",
fields: fields{
cmd: TestCommander{Output: "", Error: errors.New("command error")},
},
want: "",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &RepoService{
cmd: tt.fields.cmd,
}
got, err := s.GetRepositoryURL("origin")
if (err != nil) != tt.wantErr {
t.Errorf("RepoService.GetRepositoryURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("RepoService.GetRepositoryURL() = %v, want %v", got, tt.want)
}
})
}
}