@@ -12,67 +12,70 @@ import (
12
12
"github.com/docker/docker/api"
13
13
"github.com/docker/docker/api/types"
14
14
"github.com/docker/docker/internal/testutil"
15
+ "github.com/gotestyourself/gotestyourself/skip"
15
16
"github.com/stretchr/testify/assert"
16
17
)
17
18
18
19
func TestNewEnvClient (t * testing.T ) {
19
- if runtime .GOOS == "windows" {
20
- t . Skip ( "skipping unix only test for windows" )
21
- }
22
- cases := [] struct {
20
+ skip . IfCondition ( t , runtime .GOOS == "windows" )
21
+
22
+ testcases := [] struct {
23
+ doc string
23
24
envs map [string ]string
24
25
expectedError string
25
26
expectedVersion string
26
27
}{
27
28
{
29
+ doc : "default api version" ,
28
30
envs : map [string ]string {},
29
31
expectedVersion : api .DefaultVersion ,
30
32
},
31
33
{
34
+ doc : "invalid cert path" ,
32
35
envs : map [string ]string {
33
36
"DOCKER_CERT_PATH" : "invalid/path" ,
34
37
},
35
38
expectedError : "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory" ,
36
39
},
37
40
{
41
+ doc : "default api version with cert path" ,
38
42
envs : map [string ]string {
39
43
"DOCKER_CERT_PATH" : "testdata/" ,
40
44
},
41
45
expectedVersion : api .DefaultVersion ,
42
46
},
43
47
{
48
+ doc : "default api version with cert path and tls verify" ,
44
49
envs : map [string ]string {
45
50
"DOCKER_CERT_PATH" : "testdata/" ,
46
51
"DOCKER_TLS_VERIFY" : "1" ,
47
52
},
48
53
expectedVersion : api .DefaultVersion ,
49
54
},
50
55
{
56
+ doc : "default api version with cert path and host" ,
51
57
envs : map [string ]string {
52
58
"DOCKER_CERT_PATH" : "testdata/" ,
53
59
"DOCKER_HOST" : "https://notaunixsocket" ,
54
60
},
55
61
expectedVersion : api .DefaultVersion ,
56
62
},
57
63
{
64
+ doc : "invalid docker host" ,
58
65
envs : map [string ]string {
59
66
"DOCKER_HOST" : "host" ,
60
67
},
61
68
expectedError : "unable to parse docker host `host`" ,
62
69
},
63
70
{
71
+ doc : "invalid docker host, with good format" ,
64
72
envs : map [string ]string {
65
73
"DOCKER_HOST" : "invalid://url" ,
66
74
},
67
75
expectedVersion : api .DefaultVersion ,
68
76
},
69
77
{
70
- envs : map [string ]string {
71
- "DOCKER_API_VERSION" : "anything" ,
72
- },
73
- expectedVersion : "anything" ,
74
- },
75
- {
78
+ doc : "override api version" ,
76
79
envs : map [string ]string {
77
80
"DOCKER_API_VERSION" : "1.22" ,
78
81
},
@@ -82,24 +85,23 @@ func TestNewEnvClient(t *testing.T) {
82
85
83
86
env := envToMap ()
84
87
defer mapToEnv (env )
85
- for _ , c := range cases {
86
- mapToEnv (env )
88
+ for _ , c := range testcases {
87
89
mapToEnv (c .envs )
88
90
apiclient , err := NewEnvClient ()
89
91
if c .expectedError != "" {
90
- assert .Error (t , err )
91
- assert .Equal (t , c .expectedError , err .Error ())
92
+ assert .Error (t , err , c . doc )
93
+ assert .Equal (t , c .expectedError , err .Error (), c . doc )
92
94
} else {
93
- assert .NoError (t , err )
95
+ assert .NoError (t , err , c . doc )
94
96
version := apiclient .ClientVersion ()
95
- assert .Equal (t , c .expectedVersion , version )
97
+ assert .Equal (t , c .expectedVersion , version , c . doc )
96
98
}
97
99
98
100
if c .envs ["DOCKER_TLS_VERIFY" ] != "" {
99
101
// pedantic checking that this is handled correctly
100
102
tr := apiclient .client .Transport .(* http.Transport )
101
- assert .NotNil (t , tr .TLSClientConfig )
102
- assert .Equal (t , tr .TLSClientConfig .InsecureSkipVerify , false )
103
+ assert .NotNil (t , tr .TLSClientConfig , c . doc )
104
+ assert .Equal (t , tr .TLSClientConfig .InsecureSkipVerify , false , c . doc )
103
105
}
104
106
}
105
107
}
0 commit comments