-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathremote_test.go
54 lines (42 loc) · 1.61 KB
/
remote_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
package commands
import (
"os"
"regexp"
"testing"
"github.com/github/hub/v2/fixtures"
"github.com/github/hub/v2/github"
"github.com/github/hub/v2/internal/assert"
)
func TestTransformRemoteArgs(t *testing.T) {
repo := fixtures.SetupTestRepo()
defer repo.TearDown()
os.Setenv("HUB_PROTOCOL", "git")
github.CreateTestConfigs("jingweno", "123")
args := NewArgs([]string{"remote", "add", "jingweno"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "jingweno", args.GetParam(1))
reg := regexp.MustCompile("^git@github\\.com:jingweno/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "-p", "mislav"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "mislav", args.GetParam(1))
reg = regexp.MustCompile("^git@github\\.com:mislav/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "origin"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "origin", args.GetParam(1))
reg = regexp.MustCompile("^git@github\\.com:jingweno/.+\\.git$")
assert.T(t, reg.MatchString(args.GetParam(2)))
args = NewArgs([]string{"remote", "add", "jingweno", "[email protected]:jingweno/gh.git"})
transformRemoteArgs(args)
assert.Equal(t, 3, args.ParamsSize())
assert.Equal(t, "jingweno", args.GetParam(1))
assert.Equal(t, "add", args.FirstParam())
assert.Equal(t, "[email protected]:jingweno/gh.git", args.GetParam(2))
}