11package agentcontainers_test
22
33import (
4+ "path/filepath"
45"strings"
56"testing"
67
@@ -133,12 +134,12 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
133134wantDevcontainerScripts : []codersdk.WorkspaceAgentScript {
134135{
135136ID :devcontainerIDs [0 ],
136- Script :"devcontainer up --workspace-folder\" workspace1\" --config\" config1\" " ,
137+ Script :"devcontainer up --workspace-folder\" workspace1\" --config\" workspace1/ config1\" " ,
137138RunOnStart :false ,
138139},
139140{
140141ID :devcontainerIDs [1 ],
141- Script :"devcontainer up --workspace-folder\" workspace2\" --config\" config2\" " ,
142+ Script :"devcontainer up --workspace-folder\" workspace2\" --config\" workspace2/ config2\" " ,
142143RunOnStart :false ,
143144},
144145},
@@ -147,7 +148,7 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
147148name :"scripts match devcontainers with expand path" ,
148149args :args {
149150expandPath :func (s string ) (string ,error ) {
150- return "expanded /" + s ,nil
151+ return "/home /" + s ,nil
151152},
152153devcontainers : []codersdk.WorkspaceAgentDevcontainer {
153154{
@@ -170,12 +171,53 @@ func TestExtractAndInitializeDevcontainerScripts(t *testing.T) {
170171wantDevcontainerScripts : []codersdk.WorkspaceAgentScript {
171172{
172173ID :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\" " ,
174175RunOnStart :false ,
175176},
176177{
177178ID :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\" " ,
179221RunOnStart :false ,
180222},
181223},