forked from adampointer/cali
-
Notifications
You must be signed in to change notification settings - Fork 7
/
git_test.go
68 lines (59 loc) · 1.75 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
65
66
67
68
package cali
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetContainerName(t *testing.T) {
t.Log("Simple example")
name, err := GitCheckoutConfig{
Repo: "repo",
Branch: "branch",
RelPath: ".",
}.GetContainerName()
if assert.NoError(t, err) {
assert.Equal(t, "data_repo_branch_89bb6900736548ebd6455d0ab07aa5fe", name)
}
t.Log("Simple example, with empty path")
name, err = GitCheckoutConfig{
Repo: "repo",
Branch: "branch",
RelPath: "",
}.GetContainerName()
if assert.NoError(t, err) {
assert.Equal(t, "data_repo_branch_89bb6900736548ebd6455d0ab07aa5fe", name)
}
t.Log("Simple example, with unspecified path")
name, err = GitCheckoutConfig{
Repo: "repo",
Branch: "branch",
}.GetContainerName()
if assert.NoError(t, err) {
assert.Equal(t, "data_repo_branch_89bb6900736548ebd6455d0ab07aa5fe", name)
}
t.Log("Branches and paths with slashes")
name, err = GitCheckoutConfig{
Repo: "repo",
Branch: "branch/with-slash",
RelPath: "path/containing/slashes",
}.GetContainerName()
if assert.NoError(t, err) {
assert.Equal(t, "data_repo_path-containing-slashes_branch-with-slash_89bb6900736548ebd6455d0ab07aa5fe", name)
}
}
func TestRepoNameFromURL(t *testing.T) {
t.Log("Example git url")
name, err := repoNameFromURL("[email protected]:skybet/cali.git")
if assert.NoError(t, err) {
assert.Equal(t, "github-com-skybet-cali", name)
}
t.Log("Example https url")
name, err = repoNameFromURL("https://github.com/skybet/cali.git")
if assert.NoError(t, err) {
assert.Equal(t, "github-com-skybet-cali", name)
}
t.Log("Example git url with ssh protocol")
name, err = repoNameFromURL("ssh://[email protected]/skybet/cali.git")
if assert.NoError(t, err) {
assert.Equal(t, "github-com-skybet-cali", name)
}
}