88 "time"
99
1010 "github.com/onkernel/hypeman/lib/guest"
11+ "github.com/onkernel/hypeman/lib/hypervisor"
1112 "github.com/onkernel/hypeman/lib/oapi"
1213 "github.com/onkernel/hypeman/lib/paths"
1314 "github.com/onkernel/hypeman/lib/system"
@@ -109,10 +110,14 @@ func TestCpToAndFromInstance(t *testing.T) {
109110 err = os .WriteFile (srcFile , []byte (testContent ), 0644 )
110111 require .NoError (t , err )
111112
113+ // Create vsock dialer
114+ dialer , err := hypervisor .NewVsockDialer (actualInst .HypervisorType , actualInst .VsockSocket , actualInst .VsockCID )
115+ require .NoError (t , err )
116+
112117 // Test 1: Copy file TO instance
113118 t .Log ("Testing CopyToInstance..." )
114119 dstPath := "/tmp/copied-file.txt"
115- err = guest .CopyToInstance (ctx (), actualInst . VsockSocket , guest.CopyToInstanceOptions {
120+ err = guest .CopyToInstance (ctx (), dialer , guest.CopyToInstanceOptions {
116121 SrcPath : srcFile ,
117122 DstPath : dstPath ,
118123 })
@@ -121,7 +126,7 @@ func TestCpToAndFromInstance(t *testing.T) {
121126 // Verify the file was copied by reading it back via exec
122127 t .Log ("Verifying file was copied via exec..." )
123128 var stdout , stderr outputBuffer
124- exit , err := guest .ExecIntoInstance (ctx (), actualInst . VsockSocket , guest.ExecOptions {
129+ exit , err := guest .ExecIntoInstance (ctx (), dialer , guest.ExecOptions {
125130 Command : []string {"cat" , dstPath },
126131 Stdout : & stdout ,
127132 Stderr : & stderr ,
@@ -134,7 +139,7 @@ func TestCpToAndFromInstance(t *testing.T) {
134139 // Test 2: Copy file FROM instance
135140 t .Log ("Testing CopyFromInstance..." )
136141 localDstDir := t .TempDir ()
137- err = guest .CopyFromInstance (ctx (), actualInst . VsockSocket , guest.CopyFromInstanceOptions {
142+ err = guest .CopyFromInstance (ctx (), dialer , guest.CopyFromInstanceOptions {
138143 SrcPath : dstPath ,
139144 DstPath : localDstDir ,
140145 })
@@ -211,6 +216,10 @@ func TestCpDirectoryToInstance(t *testing.T) {
211216 actualInst , err := svc .InstanceManager .GetInstance (ctx (), inst .Id )
212217 require .NoError (t , err )
213218
219+ // Create vsock dialer
220+ dialer , err := hypervisor .NewVsockDialer (actualInst .HypervisorType , actualInst .VsockSocket , actualInst .VsockCID )
221+ require .NoError (t , err )
222+
214223 // Create a test directory structure
215224 srcDir := filepath .Join (t .TempDir (), "testdir" )
216225 require .NoError (t , os .MkdirAll (filepath .Join (srcDir , "subdir" ), 0755 ))
@@ -219,15 +228,15 @@ func TestCpDirectoryToInstance(t *testing.T) {
219228
220229 // Copy directory to instance
221230 t .Log ("Copying directory to instance..." )
222- err = guest .CopyToInstance (ctx (), actualInst . VsockSocket , guest.CopyToInstanceOptions {
231+ err = guest .CopyToInstance (ctx (), dialer , guest.CopyToInstanceOptions {
223232 SrcPath : srcDir ,
224233 DstPath : "/tmp/testdir" ,
225234 })
226235 require .NoError (t , err )
227236
228237 // Verify files exist via exec
229238 var stdout outputBuffer
230- exit , err := guest .ExecIntoInstance (ctx (), actualInst . VsockSocket , guest.ExecOptions {
239+ exit , err := guest .ExecIntoInstance (ctx (), dialer , guest.ExecOptions {
231240 Command : []string {"cat" , "/tmp/testdir/file1.txt" },
232241 Stdout : & stdout ,
233242 TTY : false ,
@@ -237,7 +246,7 @@ func TestCpDirectoryToInstance(t *testing.T) {
237246 assert .Equal (t , "file1 content" , stdout .String ())
238247
239248 stdout = outputBuffer {}
240- exit , err = guest .ExecIntoInstance (ctx (), actualInst . VsockSocket , guest.ExecOptions {
249+ exit , err = guest .ExecIntoInstance (ctx (), dialer , guest.ExecOptions {
241250 Command : []string {"cat" , "/tmp/testdir/subdir/file2.txt" },
242251 Stdout : & stdout ,
243252 TTY : false ,
@@ -249,7 +258,7 @@ func TestCpDirectoryToInstance(t *testing.T) {
249258 // Copy directory from instance
250259 t .Log ("Copying directory from instance..." )
251260 localDstDir := t .TempDir ()
252- err = guest .CopyFromInstance (ctx (), actualInst . VsockSocket , guest.CopyFromInstanceOptions {
261+ err = guest .CopyFromInstance (ctx (), dialer , guest.CopyFromInstanceOptions {
253262 SrcPath : "/tmp/testdir" ,
254263 DstPath : localDstDir ,
255264 })
@@ -266,4 +275,3 @@ func TestCpDirectoryToInstance(t *testing.T) {
266275
267276 t .Log ("Directory cp tests passed!" )
268277}
269-
0 commit comments