@@ -14,8 +14,10 @@ import (
1414 "github.com/cirruslabs/orchard/internal/controller"
1515 "github.com/cirruslabs/orchard/internal/imageconstant"
1616 "github.com/cirruslabs/orchard/internal/tests/devcontroller"
17+ "github.com/cirruslabs/orchard/internal/tests/platformdependent"
1718 "github.com/cirruslabs/orchard/internal/tests/wait"
1819 "github.com/cirruslabs/orchard/internal/worker/ondiskname"
20+ "github.com/cirruslabs/orchard/internal/worker/vmmanager"
1921 "github.com/cirruslabs/orchard/internal/worker/vmmanager/tart"
2022 v1 "github.com/cirruslabs/orchard/pkg/resource/v1"
2123 "github.com/google/uuid"
@@ -34,20 +36,14 @@ func TestSingleVM(t *testing.T) {
3436 t .Fatal (err )
3537 }
3638 assert .Equal (t , 1 , len (workers ))
37- err = devClient .VMs ().Create (context .Background (), & v1.VM {
38- Meta : v1.Meta {
39- Name : "test-vm" ,
40- },
41- Image : imageconstant .DefaultMacosImage ,
42- CPU : 4 ,
43- Memory : 8 * 1024 ,
44- Headless : true ,
45- Status : v1 .VMStatusPending ,
46- StartupScript : & v1.VMScript {
47- ScriptContent : "echo \" Hello, $FOO!\" \n for i in $(seq 1 1000); do echo \" $i\" ; done" ,
48- Env : map [string ]string {"FOO" : "Bar" },
49- },
50- })
39+
40+ vm := platformdependent .VM ("test-vm" )
41+ vm .StartupScript = & v1.VMScript {
42+ ScriptContent : "echo \" Hello, $FOO!\" \n for i in $(seq 1 1000); do echo \" $i\" ; done" ,
43+ Env : map [string ]string {"FOO" : "Bar" },
44+ }
45+
46+ err = devClient .VMs ().Create (context .Background (), vm )
5147 if err != nil {
5248 t .Fatal (err )
5349 }
@@ -82,7 +78,7 @@ func TestSingleVM(t *testing.T) {
8278 assert .Contains (t , strings .Join (logLines , "\n " ), strings .Join (expectedLogs , "\n " ))
8379
8480 // Ensure that the VM exists on disk before deleting it
85- require .True (t , hasVMByPredicate (t , func (info tart .VMInfo ) bool {
81+ require .True (t , hasVMByPredicate (t , func (info vmmanager .VMInfo ) bool {
8682 return strings .Contains (info .Name , runningVM .UID )
8783 }, nil ))
8884
@@ -93,7 +89,7 @@ func TestSingleVM(t *testing.T) {
9389 assert .True (t , wait .Wait (2 * time .Minute , func () bool {
9490 t .Logf ("Waiting for the VM to be garbage collected..." )
9591
96- return ! hasVMByPredicate (t , func (info tart .VMInfo ) bool {
92+ return ! hasVMByPredicate (t , func (info vmmanager .VMInfo ) bool {
9793 return strings .Contains (info .Name , runningVM .UID )
9894 }, nil )
9995 }), "VM was not garbage collected in a timely manner" )
@@ -107,19 +103,13 @@ func TestFailedStartupScript(t *testing.T) {
107103 t .Fatal (err )
108104 }
109105 assert .Equal (t , 1 , len (workers ))
110- err = devClient .VMs ().Create (context .Background (), & v1.VM {
111- Meta : v1.Meta {
112- Name : "test-vm" ,
113- },
114- Image : imageconstant .DefaultMacosImage ,
115- CPU : 4 ,
116- Memory : 8 * 1024 ,
117- Headless : true ,
118- Status : v1 .VMStatusPending ,
119- StartupScript : & v1.VMScript {
120- ScriptContent : "exit 123" ,
121- },
122- })
106+
107+ vm := platformdependent .VM ("test-vm" )
108+ vm .StartupScript = & v1.VMScript {
109+ ScriptContent : "exit 123" ,
110+ }
111+
112+ err = devClient .VMs ().Create (context .Background (), vm )
123113 if err != nil {
124114 t .Fatal (err )
125115 }
@@ -145,15 +135,7 @@ func TestPortForwarding(t *testing.T) {
145135 devClient , _ , _ := devcontroller .StartIntegrationTestEnvironment (t )
146136
147137 // Create a generic macOS VM
148- err := devClient .VMs ().Create (ctx , & v1.VM {
149- Meta : v1.Meta {
150- Name : "test-vm" ,
151- },
152- Image : imageconstant .DefaultMacosImage ,
153- CPU : 4 ,
154- Memory : 8 * 1024 ,
155- Headless : true ,
156- })
138+ err := devClient .VMs ().Create (ctx , platformdependent .VM ("test-vm" ))
157139 require .NoError (t , err )
158140
159141 // Establish port forwarding to VMs SSH port
@@ -468,12 +450,12 @@ func TestHostDirsInvalidPolicy(t *testing.T) {
468450}
469451
470452func hasVM (t * testing.T , name string , logger * zap.Logger ) bool {
471- return hasVMByPredicate (t , func (vmInfo tart .VMInfo ) bool {
453+ return hasVMByPredicate (t , func (vmInfo vmmanager .VMInfo ) bool {
472454 return vmInfo .Name == name
473455 }, logger )
474456}
475457
476- func hasVMByPredicate (t * testing.T , predicate func (tart .VMInfo ) bool , logger * zap.Logger ) bool {
458+ func hasVMByPredicate (t * testing.T , predicate func (vmmanager .VMInfo ) bool , logger * zap.Logger ) bool {
477459 if logger == nil {
478460 logger = zap .Must (zap .NewDevelopment ())
479461 }
0 commit comments