@@ -3,9 +3,10 @@ package client
33import (
44 "fmt"
55 "os"
6+ "strings"
67 "testing"
78
8- cliconfig "github.com/docker/docker /cli/config"
9+ cliconfig "github.com/docker/cli /cli/config"
910 "github.com/docker/go-connections/tlsconfig"
1011)
1112
@@ -24,13 +25,13 @@ func TestCreateWithEnv(t *testing.T) {
2425 envs : map [string ]string {
2526 "DOCKER_CERT_PATH" : "invalid/path" ,
2627 },
27- expectedError : "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory. Make sure the key is not encrypted " ,
28+ expectedError : "Could not load X509 key pair: open invalid/path/cert.pem: no such file or directory" ,
2829 },
2930 {
3031 envs : map [string ]string {
3132 "DOCKER_HOST" : "host" ,
3233 },
33- expectedError : "unable to parse docker host `host` " ,
34+ expectedError : "unable to parse docker host" ,
3435 },
3536 {
3637 envs : map [string ]string {
@@ -55,8 +56,8 @@ func TestCreateWithEnv(t *testing.T) {
5556 recoverEnvs := setupEnvs (t , c .envs )
5657 apiclient , err := Create (Options {})
5758 if c .expectedError != "" {
58- if err == nil || err .Error () != c .expectedError {
59- t .Errorf ("expected an error %s , got %s , for %v" , c .expectedError , err .Error (), c )
59+ if err == nil || ! strings . Contains ( err .Error (), c .expectedError ) {
60+ t .Errorf ("expected an error '%s' , got '%s' , for %v" , c .expectedError , err .Error (), c )
6061 }
6162 } else {
6263 if err != nil {
@@ -81,7 +82,7 @@ func TestCreateWithOptions(t *testing.T) {
8182 options : Options {
8283 Host : "host" ,
8384 },
84- expectedError : "unable to parse docker host `host` " ,
85+ expectedError : "unable to parse docker host" ,
8586 },
8687 {
8788 options : Options {
@@ -109,7 +110,7 @@ func TestCreateWithOptions(t *testing.T) {
109110 TLS : true ,
110111 APIVersion : "v1.22" ,
111112 },
112- expectedError : fmt .Sprintf ("Could not load X509 key pair: open %s/cert.pem: no such file or directory. Make sure the key is not encrypted " , cliconfig .Dir ()),
113+ expectedError : fmt .Sprintf ("Could not load X509 key pair: open %s/cert.pem: no such file or directory" , cliconfig .Dir ()),
113114 },
114115 {
115116 options : Options {
@@ -123,7 +124,7 @@ func TestCreateWithOptions(t *testing.T) {
123124 TrustKey : "invalid/trust/key" ,
124125 APIVersion : "v1.22" ,
125126 },
126- expectedError : "Could not load X509 key pair: open invalid/cert/file: no such file or directory. Make sure the key is not encrypted " ,
127+ expectedError : "Could not load X509 key pair: open invalid/cert/file: no such file or directory" ,
127128 },
128129 {
129130 options : Options {
@@ -136,7 +137,7 @@ func TestCreateWithOptions(t *testing.T) {
136137 },
137138 APIVersion : "v1.22" ,
138139 },
139- expectedError : "unable to parse docker host `host` " ,
140+ expectedError : "unable to parse docker host" ,
140141 },
141142 {
142143 options : Options {
@@ -155,8 +156,8 @@ func TestCreateWithOptions(t *testing.T) {
155156 for _ , c := range cases {
156157 apiclient , err := Create (c .options )
157158 if c .expectedError != "" {
158- if err == nil || err .Error () != c .expectedError {
159- t .Errorf ("expected an error %s , got %s , for %v" , c .expectedError , err .Error (), c )
159+ if err == nil || ! strings . Contains ( err .Error (), c .expectedError ) {
160+ t .Errorf ("expected an error '%s' , got '%s' , for %v" , c .expectedError , err .Error (), c )
160161 }
161162 } else {
162163 if err != nil {
0 commit comments