github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/swarmkit/cli/external_ca_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/swarmkit/api"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestParseExternalCA(t *testing.T) {
    11  	invalidSpecs := []string{
    12  		"",
    13  		"asdf",
    14  		"asdf=",
    15  		"protocol",
    16  		"protocol=foo",
    17  		"protocol=cfssl",
    18  		"url",
    19  		"url=https://xyz",
    20  		"url,protocol",
    21  	}
    22  
    23  	for _, spec := range invalidSpecs {
    24  		_, err := parseExternalCA(spec)
    25  		assert.Error(t, err)
    26  	}
    27  
    28  	validSpecs := []struct {
    29  		input    string
    30  		expected *api.ExternalCA
    31  	}{
    32  		{
    33  			input: "protocol=cfssl,url=https://example.com",
    34  			expected: &api.ExternalCA{
    35  				Protocol: api.ExternalCA_CAProtocolCFSSL,
    36  				URL:      "https://example.com",
    37  				Options:  map[string]string{},
    38  			},
    39  		},
    40  	}
    41  
    42  	for _, spec := range validSpecs {
    43  		parsed, err := parseExternalCA(spec.input)
    44  		assert.NoError(t, err)
    45  		assert.Equal(t, spec.expected, parsed)
    46  	}
    47  }