@@ -314,30 +314,65 @@ func TestConvertDNSConfigSearch(t *testing.T) {
314314}
315315
316316func TestConvertCredentialSpec (t * testing.T ) {
317- swarmSpec , err := convertCredentialSpec (composetypes.CredentialSpecConfig {})
318- assert .NilError (t , err )
319- assert .Check (t , is .Nil (swarmSpec ))
320-
321- swarmSpec , err = convertCredentialSpec (composetypes.CredentialSpecConfig {
322- File : "/foo" ,
323- })
324- assert .NilError (t , err )
325- assert .Check (t , is .Equal (swarmSpec .File , "/foo" ))
326- assert .Check (t , is .Equal (swarmSpec .Registry , "" ))
317+ tests := []struct {
318+ name string
319+ in composetypes.CredentialSpecConfig
320+ out * swarm.CredentialSpec
321+ expectedErr string
322+ }{
323+ {
324+ name : "empty" ,
325+ },
326+ {
327+ name : "config-and-file" ,
328+ in : composetypes.CredentialSpecConfig {Config : "0bt9dmxjvjiqermk6xrop3ekq" , File : "somefile.json" },
329+ expectedErr : `invalid credential spec: cannot specify both "Config" and "File"` ,
330+ },
331+ {
332+ name : "config-and-registry" ,
333+ in : composetypes.CredentialSpecConfig {Config : "0bt9dmxjvjiqermk6xrop3ekq" , Registry : "testing" },
334+ expectedErr : `invalid credential spec: cannot specify both "Config" and "Registry"` ,
335+ },
336+ {
337+ name : "file-and-registry" ,
338+ in : composetypes.CredentialSpecConfig {File : "somefile.json" , Registry : "testing" },
339+ expectedErr : `invalid credential spec: cannot specify both "File" and "Registry"` ,
340+ },
341+ {
342+ name : "config-and-file-and-registry" ,
343+ in : composetypes.CredentialSpecConfig {Config : "0bt9dmxjvjiqermk6xrop3ekq" , File : "somefile.json" , Registry : "testing" },
344+ expectedErr : `invalid credential spec: cannot specify both "Config", "File", and "Registry"` ,
345+ },
346+ {
347+ name : "config" ,
348+ in : composetypes.CredentialSpecConfig {Config : "0bt9dmxjvjiqermk6xrop3ekq" },
349+ out : & swarm.CredentialSpec {Config : "0bt9dmxjvjiqermk6xrop3ekq" },
350+ },
351+ {
352+ name : "file" ,
353+ in : composetypes.CredentialSpecConfig {File : "somefile.json" },
354+ out : & swarm.CredentialSpec {File : "somefile.json" },
355+ },
356+ {
357+ name : "registry" ,
358+ in : composetypes.CredentialSpecConfig {Registry : "testing" },
359+ out : & swarm.CredentialSpec {Registry : "testing" },
360+ },
361+ }
327362
328- swarmSpec , err = convertCredentialSpec (composetypes.CredentialSpecConfig {
329- Registry : "foo" ,
330- })
331- assert .NilError (t , err )
332- assert .Check (t , is .Equal (swarmSpec .File , "" ))
333- assert .Check (t , is .Equal (swarmSpec .Registry , "foo" ))
363+ for _ , tc := range tests {
364+ tc := tc
365+ t .Run (tc .name , func (t * testing.T ) {
366+ swarmSpec , err := convertCredentialSpec (tc .in )
334367
335- swarmSpec , err = convertCredentialSpec (composetypes.CredentialSpecConfig {
336- File : "/asdf" ,
337- Registry : "foo" ,
338- })
339- assert .Check (t , is .ErrorContains (err , "" ))
340- assert .Check (t , is .Nil (swarmSpec ))
368+ if tc .expectedErr != "" {
369+ assert .Error (t , err , tc .expectedErr )
370+ } else {
371+ assert .NilError (t , err )
372+ }
373+ assert .DeepEqual (t , swarmSpec , tc .out )
374+ })
375+ }
341376}
342377
343378func TestConvertUpdateConfigOrder (t * testing.T ) {
0 commit comments