@@ -87,45 +87,35 @@ func TestSocketPath_VMDetection(t *testing.T) {
8787 t .Cleanup (func () { _ = os .RemoveAll (home ) })
8888 t .Setenv ("HOME" , home )
8989
90- t .Run ("colima socket exists returns remapped path" , func (t * testing.T ) {
91- colimaSock := filepath .Join (home , ".colima" , "default" , "docker.sock" )
92- require .NoError (t , os .MkdirAll (filepath .Dir (colimaSock ), 0o755 ))
93- f , err := os .Create (colimaSock )
94- require .NoError (t , err )
95- require .NoError (t , f .Close ())
96- t .Cleanup (func () {
97- require .NoError (t , os .Remove (colimaSock ))
98- })
99-
100- cli , err := client .NewClientWithOpts (client .WithHost ("unix://" + colimaSock ))
101- require .NoError (t , err )
102- rt := & DockerRuntime {client : cli }
103- assert .Equal (t , "/var/run/docker.sock" , rt .SocketPath ())
104- })
90+ vmTests := []struct {
91+ name string
92+ relPath string
93+ }{
94+ {"docker desktop" , ".docker/run/docker.sock" },
95+ {"colima" , ".colima/default/docker.sock" },
96+ {"orbstack" , ".orbstack/run/docker.sock" },
97+ {"lima host" , ".lima/docker/sock/docker.sock" },
98+ }
10599
106- t .Run ("orbstack socket exists returns remapped path" , func (t * testing.T ) {
107- orbstackSock := filepath .Join (home , ".orbstack" , "run" , "docker.sock" )
108- require .NoError (t , os .MkdirAll (filepath .Dir (orbstackSock ), 0o755 ))
109- f , err := os .Create (orbstackSock )
110- require .NoError (t , err )
111- require .NoError (t , f .Close ())
112- t .Cleanup (func () {
113- require .NoError (t , os .Remove (orbstackSock ))
100+ for _ , tc := range vmTests {
101+ t .Run (tc .name + " socket returns remapped path" , func (t * testing.T ) {
102+ sock := filepath .Join (home , filepath .FromSlash (tc .relPath ))
103+ require .NoError (t , os .MkdirAll (filepath .Dir (sock ), 0o755 ))
104+ require .NoError (t , os .WriteFile (sock , nil , 0o600 ))
105+ t .Cleanup (func () { require .NoError (t , os .Remove (sock )) })
106+
107+ cli , err := client .NewClientWithOpts (client .WithHost ("unix://" + sock ))
108+ require .NoError (t , err )
109+ rt := & DockerRuntime {client : cli }
110+ assert .Equal (t , "/var/run/docker.sock" , rt .SocketPath ())
114111 })
112+ }
115113
116- cli , err := client .NewClientWithOpts (client .WithHost ("unix://" + orbstackSock ))
117- require .NoError (t , err )
118- rt := & DockerRuntime {client : cli }
119- assert .Equal (t , "/var/run/docker.sock" , rt .SocketPath ())
120- })
121-
122- t .Run ("rootless socket exists returns actual path" , func (t * testing.T ) {
114+ t .Run ("rootless socket returns actual path" , func (t * testing.T ) {
123115 // Use a non-VM socket path (short path to avoid Docker client limit)
124116 rootlessSock := "/tmp/lstk-docker.sock"
125117 require .NoError (t , os .WriteFile (rootlessSock , nil , 0o600 ))
126- t .Cleanup (func () {
127- require .NoError (t , os .Remove (rootlessSock ))
128- })
118+ t .Cleanup (func () { require .NoError (t , os .Remove (rootlessSock )) })
129119
130120 cli , err := client .NewClientWithOpts (client .WithHost ("unix://" + rootlessSock ))
131121 require .NoError (t , err )
@@ -161,16 +151,28 @@ func TestFindDockerSocket_LimaVM(t *testing.T) {
161151 assert .Equal (t , "/var/run/docker.sock" , sock )
162152}
163153
164- func TestFindDockerSocket_IncludesLimaPathOnHost (t * testing.T ) {
154+ func TestFindDockerSocket_ProbesVMSockets (t * testing.T ) {
165155 t .Setenv ("LIMA_INSTANCE" , "" )
166156
167- tmpDir := t .TempDir ()
168- limaSock := filepath .Join (tmpDir , ".lima" , "docker" , "sock" , "docker.sock" )
169- require .NoError (t , os .MkdirAll (filepath .Dir (limaSock ), 0o700 ))
170- require .NoError (t , os .WriteFile (limaSock , nil , 0o600 ))
157+ tests := []struct {
158+ name string
159+ relPath string
160+ }{
161+ {"docker desktop" , ".docker/run/docker.sock" },
162+ {"colima" , ".colima/default/docker.sock" },
163+ {"orbstack" , ".orbstack/run/docker.sock" },
164+ {"lima host" , ".lima/docker/sock/docker.sock" },
165+ }
171166
172- t .Setenv ("HOME" , tmpDir )
167+ for _ , tc := range tests {
168+ t .Run (tc .name , func (t * testing.T ) {
169+ tmpDir := t .TempDir ()
170+ sock := filepath .Join (tmpDir , filepath .FromSlash (tc .relPath ))
171+ require .NoError (t , os .MkdirAll (filepath .Dir (sock ), 0o700 ))
172+ require .NoError (t , os .WriteFile (sock , nil , 0o600 ))
173+ t .Setenv ("HOME" , tmpDir )
173174
174- result := findDockerSocket ()
175- assert .Equal (t , limaSock , result )
175+ assert .Equal (t , sock , findDockerSocket ())
176+ })
177+ }
176178}
0 commit comments