@@ -59,42 +59,87 @@ func TestCreate(t *testing.T) {
5959 cli := makeFakeCli (t )
6060 assert .NilError (t , cli .ContextStore ().CreateOrUpdate (store.Metadata {Name : "existing-context" }))
6161 tests := []struct {
62+ doc string
6263 options CreateOptions
6364 expecterErr string
6465 }{
6566 {
67+ doc : "empty name" ,
6668 expecterErr : `context name cannot be empty` ,
6769 },
6870 {
71+ doc : "reserved name" ,
6972 options : CreateOptions {
7073 Name : "default" ,
7174 },
7275 expecterErr : `"default" is a reserved context name` ,
7376 },
7477 {
78+ doc : "whitespace-only name" ,
7579 options : CreateOptions {
7680 Name : " " ,
7781 },
7882 expecterErr : `context name " " is invalid` ,
7983 },
8084 {
85+ doc : "existing context" ,
8186 options : CreateOptions {
8287 Name : "existing-context" ,
8388 },
8489 expecterErr : `context "existing-context" already exists` ,
8590 },
8691 {
92+ doc : "invalid docker host" ,
8793 options : CreateOptions {
8894 Name : "invalid-docker-host" ,
8995 Docker : map [string ]string {
90- keyHost : "some///invalid/host" ,
96+ "host" : "some///invalid/host" ,
9197 },
9298 },
9399 expecterErr : `unable to parse docker host` ,
94100 },
101+ {
102+ doc : "ssh host with skip-tls-verify=false" ,
103+ options : CreateOptions {
104+ Name : "skip-tls-verify-false" ,
105+ Docker : map [string ]string {
106+ "host" : "ssh://example.com,skip-tls-verify=false" ,
107+ },
108+ },
109+ },
110+ {
111+ doc : "ssh host with skip-tls-verify=true" ,
112+ options : CreateOptions {
113+ Name : "skip-tls-verify-true" ,
114+ Docker : map [string ]string {
115+ "host" : "ssh://example.com,skip-tls-verify=true" ,
116+ },
117+ },
118+ },
119+ {
120+ doc : "ssh host with skip-tls-verify=INVALID" ,
121+ options : CreateOptions {
122+ Name : "skip-tls-verify-invalid" ,
123+ Docker : map [string ]string {
124+ "host" : "ssh://example.com" ,
125+ "skip-tls-verify" : "INVALID" ,
126+ },
127+ },
128+ expecterErr : `unable to create docker endpoint config: skip-tls-verify: parsing "INVALID": invalid syntax` ,
129+ },
130+ {
131+ doc : "unknown option" ,
132+ options : CreateOptions {
133+ Name : "unknown-option" ,
134+ Docker : map [string ]string {
135+ "UNKNOWN" : "value" ,
136+ },
137+ },
138+ expecterErr : `unable to create docker endpoint config: unrecognized config key: UNKNOWN` ,
139+ },
95140 }
96141 for _ , tc := range tests {
97- t .Run (tc .options . Name , func (t * testing.T ) {
142+ t .Run (tc .doc , func (t * testing.T ) {
98143 err := RunCreate (cli , & tc .options )
99144 if tc .expecterErr == "" {
100145 assert .NilError (t , err )
0 commit comments