-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdefaults_test.go
93 lines (83 loc) · 2.06 KB
/
defaults_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
92
93
package options_test
import (
"testing"
"github.com/coder/envbuilder/internal/chmodfs"
"github.com/go-git/go-billy/v5/osfs"
"github.com/stretchr/testify/assert"
"github.com/coder/envbuilder/constants"
"github.com/coder/envbuilder/options"
"github.com/stretchr/testify/require"
)
func TestDefaultWorkspaceFolder(t *testing.T) {
t.Parallel()
successTests := []struct {
name string
gitURL string
expected string
}{
{
name: "HTTP",
gitURL: "https://github.com/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "SSH",
gitURL: "[email protected]:coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "username and password",
gitURL: "https://username:[email protected]/coder/envbuilder.git",
expected: "/workspaces/envbuilder",
},
{
name: "fragment",
gitURL: "https://github.com/coder/envbuilder.git#feature-branch",
expected: "/workspaces/envbuilder",
},
{
name: "empty",
gitURL: "",
expected: constants.EmptyWorkspaceDir,
},
}
for _, tt := range successTests {
t.Run(tt.name, func(t *testing.T) {
dir := options.DefaultWorkspaceFolder(tt.gitURL)
require.Equal(t, tt.expected, dir)
})
}
invalidTests := []struct {
name string
invalidURL string
}{
{
name: "simple text",
invalidURL: "not a valid URL",
},
{
name: "website URL",
invalidURL: "www.google.com",
},
}
for _, tt := range invalidTests {
t.Run(tt.name, func(t *testing.T) {
dir := options.DefaultWorkspaceFolder(tt.invalidURL)
require.Equal(t, constants.EmptyWorkspaceDir, dir)
})
}
}
func TestOptions_SetDefaults(t *testing.T) {
t.Parallel()
expected := options.Options{
InitScript: "sleep infinity",
InitCommand: "/bin/sh",
IgnorePaths: []string{"/var/run", "/product_uuid", "/product_name"},
Filesystem: chmodfs.New(osfs.New("/")),
GitURL: "",
WorkspaceFolder: constants.EmptyWorkspaceDir,
}
var actual options.Options
actual.SetDefaults()
assert.Equal(t, expected, actual)
}