1
1
package agentcontainers_test
2
2
3
3
import (
4
+ "path/filepath"
4
5
"strings"
5
6
"testing"
6
7
@@ -133,12 +134,12 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
133
134
wantDevcontainerScripts : []codersdk.WorkspaceAgentScript {
134
135
{
135
136
ID : devcontainerIDs [0 ],
136
- Script : "devcontainer up --workspace-folder \" workspace1\" --config \" config1\" " ,
137
+ Script : "devcontainer up --workspace-folder \" workspace1\" --config \" workspace1/ config1\" " ,
137
138
RunOnStart : false ,
138
139
},
139
140
{
140
141
ID : devcontainerIDs [1 ],
141
- Script : "devcontainer up --workspace-folder \" workspace2\" --config \" config2\" " ,
142
+ Script : "devcontainer up --workspace-folder \" workspace2\" --config \" workspace2/ config2\" " ,
142
143
RunOnStart : false ,
143
144
},
144
145
},
@@ -147,7 +148,7 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
147
148
name : "scripts match devcontainers with expand path" ,
148
149
args : args {
149
150
expandPath : func (s string ) (string , error ) {
150
- return "expanded /" + s , nil
151
+ return "/home /" + s , nil
151
152
},
152
153
devcontainers : []codersdk.WorkspaceAgentDevcontainer {
153
154
{
@@ -170,12 +171,53 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
170
171
wantDevcontainerScripts : []codersdk.WorkspaceAgentScript {
171
172
{
172
173
ID : devcontainerIDs [0 ],
173
- Script : "devcontainer up --workspace-folder \" expanded/ workspace1\" --config \" expanded /config1\" " ,
174
+ Script : "devcontainer up --workspace-folder \" /home/ workspace1\" --config \" /home/workspace1 /config1\" " ,
174
175
RunOnStart : false ,
175
176
},
176
177
{
177
178
ID : devcontainerIDs [1 ],
178
- Script : "devcontainer up --workspace-folder \" expanded/workspace2\" --config \" expanded/config2\" " ,
179
+ Script : "devcontainer up --workspace-folder \" /home/workspace2\" --config \" /home/workspace2/config2\" " ,
180
+ RunOnStart : false ,
181
+ },
182
+ },
183
+ },
184
+ {
185
+ name : "expand config path when ~" ,
186
+ args : args {
187
+ expandPath : func (s string ) (string , error ) {
188
+ s = strings .Replace (s , "~/" , "" , 1 )
189
+ if filepath .IsAbs (s ) {
190
+ return s , nil
191
+ }
192
+ return "/home/" + s , nil
193
+ },
194
+ devcontainers : []codersdk.WorkspaceAgentDevcontainer {
195
+ {
196
+ ID : devcontainerIDs [0 ],
197
+ WorkspaceFolder : "workspace1" ,
198
+ ConfigPath : "~/config1" ,
199
+ },
200
+ {
201
+ ID : devcontainerIDs [1 ],
202
+ WorkspaceFolder : "workspace2" ,
203
+ ConfigPath : "/config2" ,
204
+ },
205
+ },
206
+ scripts : []codersdk.WorkspaceAgentScript {
207
+ {ID : devcontainerIDs [0 ], RunOnStart : true },
208
+ {ID : devcontainerIDs [1 ], RunOnStart : true },
209
+ },
210
+ },
211
+ wantFilteredScripts : []codersdk.WorkspaceAgentScript {},
212
+ wantDevcontainerScripts : []codersdk.WorkspaceAgentScript {
213
+ {
214
+ ID : devcontainerIDs [0 ],
215
+ Script : "devcontainer up --workspace-folder \" /home/workspace1\" --config \" /home/config1\" " ,
216
+ RunOnStart : false ,
217
+ },
218
+ {
219
+ ID : devcontainerIDs [1 ],
220
+ Script : "devcontainer up --workspace-folder \" /home/workspace2\" --config \" /config2\" " ,
179
221
RunOnStart : false ,
180
222
},
181
223
},
0 commit comments