-
-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathnode_http_test.go
76 lines (66 loc) · 2.13 KB
/
node_http_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
package taskfile
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHTTPNode_https(t *testing.T) {
t.Parallel()
node, err := NewHTTPNode("https://raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml", "", false, time.Second)
require.NoError(t, err)
assert.Equal(t, time.Second, node.timeout)
assert.Equal(t, "https://raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yml", node.url.String())
entrypoint, err := node.ResolveEntrypoint("common.yml")
require.NoError(t, err)
assert.Equal(t, "https://raw.githubusercontent.com/my-org/my-repo/main/common.yml", entrypoint)
}
func TestHTTPNode_redaction(t *testing.T) {
t.Parallel()
node, err := NewHTTPNode("https://user:[email protected]/Taskfile.yml", "", false, time.Second)
t.Run("the location is redacted", func(t *testing.T) {
t.Parallel()
require.NoError(t, err)
assert.Equal(t, "https://user:[email protected]/Taskfile.yml", node.Location())
})
t.Run("resolved entrypoints contain the username and password", func(t *testing.T) {
t.Parallel()
location, err := node.ResolveEntrypoint("common.yaml")
require.NoError(t, err)
assert.Equal(t, "https://user:[email protected]/common.yaml", location)
})
}
func TestHTTPNode_FilenameAndDir(t *testing.T) {
t.Parallel()
tests := map[string]struct {
entrypoint string
filename string
dir string
}{
"file at root": {
entrypoint: "https://example.com/Taskfile.yaml",
filename: "Taskfile.yaml",
dir: ".",
},
"file in folder": {
entrypoint: "https://example.com/taskfiles/Taskfile.yaml",
filename: "Taskfile.yaml",
dir: "taskfiles",
},
"nested structure": {
entrypoint: "https://raw.githubusercontent.com/my-org/my-repo/main/Taskfile.yaml",
filename: "Taskfile.yaml",
dir: "main",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()
node, err := NewHTTPNode(tt.entrypoint, "", false, time.Second)
require.NoError(t, err)
dir, filename := node.FilenameAndLastDir()
assert.Equal(t, tt.filename, filename)
assert.Equal(t, tt.dir, dir)
})
}
}