forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathdotfiles_test.go
More file actions
121 lines (113 loc) · 2.82 KB
/
dotfiles_test.go
File metadata and controls
121 lines (113 loc) · 2.82 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package dotfiles
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtractKeysFromEnvKeyValuePairs(t *testing.T) {
tests := []struct {
name string
input []string
expected []string
}{
{
name: "empty input",
input: []string{},
expected: []string{},
},
{
name: "single key-value pair",
input: []string{"FOO=bar"},
expected: []string{"FOO"},
},
{
name: "multiple key-value pairs",
input: []string{"FOO=bar", "BAZ=qux"},
expected: []string{"FOO", "BAZ"},
},
{
name: "value contains equals sign",
input: []string{"FOO=bar=baz"},
expected: []string{"FOO"},
},
{
name: "entry without equals sign is skipped",
input: []string{"NOEQ", "FOO=bar"},
expected: []string{"FOO"},
},
{
name: "empty value",
input: []string{"FOO="},
expected: []string{"FOO"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := extractKeysFromEnvKeyValuePairs(tt.input)
assert.Equal(t, tt.expected, result)
})
}
}
func TestCollectDotfilesScriptEnvKeyValuePairs(t *testing.T) {
t.Run("empty file list", func(t *testing.T) {
result, err := collectDotfilesScriptEnvKeyValuePairs([]string{})
assert.NoError(t, err)
assert.Equal(t, []string{}, result)
})
t.Run("nonexistent file returns error", func(t *testing.T) {
_, err := collectDotfilesScriptEnvKeyValuePairs([]string{"/nonexistent/file"})
assert.Error(t, err)
})
}
func TestBuildDotCmdAgentArguments(t *testing.T) {
tests := []struct {
name string
dotfilesRepo string
dotfilesScript string
strictHostKey bool
debug bool
expected []string
}{
{
name: "basic repo only",
dotfilesRepo: "https://github.com/user/dotfiles",
expected: []string{
"agent", "workspace", "install-dotfiles",
"--repository", "https://github.com/user/dotfiles",
},
},
{
name: "with script",
dotfilesRepo: "https://github.com/user/dotfiles",
dotfilesScript: "install.sh",
expected: []string{
"agent", "workspace", "install-dotfiles",
"--repository", "https://github.com/user/dotfiles",
"--install-script", "install.sh",
},
},
{
name: "all options enabled",
dotfilesRepo: "https://github.com/user/dotfiles",
dotfilesScript: "setup.sh",
strictHostKey: true,
debug: true,
expected: []string{
"agent", "workspace", "install-dotfiles",
"--repository", "https://github.com/user/dotfiles",
"--strict-host-key-checking", "--debug",
"--install-script", "setup.sh",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := buildDotCmdAgentArguments(
tt.dotfilesRepo,
tt.dotfilesScript,
tt.strictHostKey,
tt.debug,
)
assert.Equal(t, tt.expected, result)
})
}
}