-
-
Notifications
You must be signed in to change notification settings - Fork 669
/
Copy pathnode_git_test.go
85 lines (71 loc) · 3.28 KB
/
node_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package taskfile
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGitNode_ssh(t *testing.T) {
t.Parallel()
node, err := NewGitNode("[email protected]:foo/bar.git//Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
assert.Equal(t, "main", node.ref)
assert.Equal(t, "Taskfile.yml", node.filepath)
assert.Equal(t, "ssh://[email protected]/foo/bar.git//Taskfile.yml?ref=main", node.fullURL)
assert.Equal(t, "ssh://[email protected]/foo/bar.git", node.baseURL)
entrypoint, err := node.ResolveEntrypoint("common.yml")
assert.NoError(t, err)
assert.Equal(t, "ssh://[email protected]/foo/bar.git//common.yml?ref=main", entrypoint)
}
func TestGitNode_sshWithDir(t *testing.T) {
t.Parallel()
node, err := NewGitNode("[email protected]:foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
assert.Equal(t, "main", node.ref)
assert.Equal(t, "directory/Taskfile.yml", node.filepath)
assert.Equal(t, "ssh://[email protected]/foo/bar.git//directory/Taskfile.yml?ref=main", node.fullURL)
assert.Equal(t, "ssh://[email protected]/foo/bar.git", node.baseURL)
entrypoint, err := node.ResolveEntrypoint("common.yml")
assert.NoError(t, err)
assert.Equal(t, "ssh://[email protected]/foo/bar.git//directory/common.yml?ref=main", entrypoint)
}
func TestGitNode_https(t *testing.T) {
t.Parallel()
node, err := NewGitNode("https://git:[email protected]/foo/bar.git//Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
assert.Equal(t, "main", node.ref)
assert.Equal(t, "Taskfile.yml", node.filepath)
assert.Equal(t, "https://git:[email protected]/foo/bar.git//Taskfile.yml?ref=main", node.fullURL)
assert.Equal(t, "https://git:[email protected]/foo/bar.git", node.baseURL)
entrypoint, err := node.ResolveEntrypoint("common.yml")
assert.NoError(t, err)
assert.Equal(t, "https://git:[email protected]/foo/bar.git//common.yml?ref=main", entrypoint)
}
func TestGitNode_httpsWithDir(t *testing.T) {
t.Parallel()
node, err := NewGitNode("https://git:[email protected]/foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
assert.Equal(t, "main", node.ref)
assert.Equal(t, "directory/Taskfile.yml", node.filepath)
assert.Equal(t, "https://git:[email protected]/foo/bar.git//directory/Taskfile.yml?ref=main", node.fullURL)
assert.Equal(t, "https://git:[email protected]/foo/bar.git", node.baseURL)
entrypoint, err := node.ResolveEntrypoint("common.yml")
assert.NoError(t, err)
assert.Equal(t, "https://git:[email protected]/foo/bar.git//directory/common.yml?ref=main", entrypoint)
}
func TestGitNode_FilenameAndDir(t *testing.T) {
t.Parallel()
node, err := NewGitNode("https://github.com/foo/bar.git//directory/Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
dir, filename := node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, "directory", dir)
node, err = NewGitNode("https://github.com/foo/bar.git//Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
dir, filename = node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, ".", dir)
node, err = NewGitNode("https://github.com/foo/bar.git//multiple/directory/Taskfile.yml?ref=main", "", false)
assert.NoError(t, err)
dir, filename = node.FilenameAndLastDir()
assert.Equal(t, "Taskfile.yml", filename)
assert.Equal(t, "directory", dir)
}