-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: account for osx special case socket (#217)
* fix: update docker client code to make exception for darwin socket --------- Signed-off-by: Christopher Phillips <[email protected]> Signed-off-by: Christopher Phillips <[email protected]> Co-authored-by: Christopher Phillips <[email protected]>
- Loading branch information
Showing
2 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package docker | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/docker/docker/client" | ||
) | ||
|
||
func Test_newClient(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
providedSocket string | ||
expectedSocket string | ||
setEnv func(t *testing.T) | ||
}{ | ||
{ | ||
name: "Test newClient returns the correct default location", | ||
providedSocket: "", | ||
expectedSocket: "unix:///var/run/docker.sock", | ||
}, | ||
{ | ||
name: "Test newClient with runtime specific path", | ||
providedSocket: "", | ||
setEnv: func(t *testing.T) { | ||
os.Setenv("DOCKER_HOST", "unix:///var/CUSTOM/docker.sock") | ||
|
||
}, | ||
expectedSocket: "unix:///var/CUSTOM/docker.sock", | ||
}, | ||
{ | ||
name: "Test newClient with runtime specific path", | ||
providedSocket: "unix:///var/NEWCUSTOM/docker.sock", | ||
expectedSocket: "unix:///var/NEWCUSTOM/docker.sock", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
if c.setEnv != nil { | ||
c.setEnv(t) | ||
} | ||
clientOpts := []client.Opt{ | ||
client.FromEnv, | ||
client.WithAPIVersionNegotiation(), | ||
} | ||
|
||
client, err := newClient(c.providedSocket, clientOpts...) | ||
if err != nil { | ||
t.Errorf("newClient() error = %v", err) | ||
return | ||
} | ||
|
||
if client.DaemonHost() != c.expectedSocket { | ||
t.Errorf("newClient() = %v, want %v", client.DaemonHost(), c.expectedSocket) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_possibleSocketPaths(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
provided string | ||
expected []string | ||
}{ | ||
{ | ||
name: "Test possibleSocketPaths returns the correct default location for darwin", | ||
provided: "darwin", | ||
expected: []string{"", "Library/Containers/com.docker.docker/Data/docker.raw.sock"}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
for i, socketPath := range possibleSocketPaths(c.provided) { | ||
if !strings.HasSuffix(socketPath, c.expected[i]) { | ||
t.Errorf("possibleSocketPaths() = %v, want %v", socketPath, c.expected[i]) | ||
} | ||
} | ||
}) | ||
} | ||
} |