2016-09-08 13:11:39 -04:00
|
|
|
package swarm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-22 12:12:14 -05:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
is "gotest.tools/v3/assert/cmp"
|
2016-09-08 13:11:39 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
|
|
|
|
opt := NewNodeAddrOption("old:123")
|
|
|
|
addr := "newhost:5555"
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set(addr))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(addr, opt.Value()))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostOnly(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set("newhost"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("newhost:2377", opt.Value()))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set("::1"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("[::1]:2377", opt.Value()))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetPortOnly(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set(":4545"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("0.0.0.0:4545", opt.Value()))
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
|
|
|
|
opt := NewListenAddrOption()
|
linting: ST1005: error strings should not be capitalized (stylecheck)
While fixing, also updated errors without placeholders to `errors.New()`, and
updated some code to use pkg/errors if it was already in use in the file.
cli/command/config/inspect.go:59:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/node/inspect.go:61:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/secret/inspect.go:57:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Cannot supply extra formatting options to the pretty template")
^
cli/command/trust/common.go:77:74: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signatures or cannot access %s", remote)
^
cli/command/trust/common.go:85:73: ST1005: error strings should not be capitalized (stylecheck)
return []trustTagRow{}, []client.RoleWithSignatures{}, []data.Role{}, fmt.Errorf("No signers for %s", remote)
^
cli/command/trust/sign.go:137:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("No tag specified for %s", imgRefAndAuth.Name())
^
cli/command/trust/sign.go:151:19: ST1005: error strings should not be capitalized (stylecheck)
return *target, fmt.Errorf("No tag specified")
^
cli/command/trust/signer_add.go:77:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Failed to add signer to: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:52:10: ST1005: error strings should not be capitalized (stylecheck)
return fmt.Errorf("Error removing signer from: %s", strings.Join(errRepos, ", "))
^
cli/command/trust/signer_remove.go:67:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("All signed tags are currently revoked, use docker trust sign to fix")
^
cli/command/trust/signer_remove.go:108:17: ST1005: error strings should not be capitalized (stylecheck)
return false, fmt.Errorf("No signer %s for repository %s", signerName, repoName)
^
opts/hosts.go:89:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", addr)
^
opts/hosts.go:100:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected %s: %s", proto, addr)
^
opts/hosts.go:119:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid proto, expected tcp: %s", tryAddr)
^
opts/hosts.go:144:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
opts/hosts.go:155:14: ST1005: error strings should not be capitalized (stylecheck)
return "", fmt.Errorf("Invalid bind address format: %s", tryAddr)
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-02 18:04:53 -04:00
|
|
|
assert.Error(t, opt.Set("http://localhost:4545"), "invalid proto, expected tcp: http://localhost:4545")
|
2016-09-08 13:11:39 -04:00
|
|
|
}
|
2016-12-25 16:23:35 -05:00
|
|
|
|
|
|
|
func TestExternalCAOptionErrors(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
externalCA string
|
|
|
|
expectedError string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
externalCA: "",
|
|
|
|
expectedError: "EOF",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "anything",
|
|
|
|
expectedError: "invalid field 'anything' must be a key=value pair",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "foo=bar",
|
|
|
|
expectedError: "the external-ca option needs a protocol= parameter",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=baz",
|
|
|
|
expectedError: "unrecognized external CA protocol baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=cfssl",
|
|
|
|
expectedError: "the external-ca option needs a url= parameter",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
opt := &ExternalCAOption{}
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, opt.Set(tc.externalCA), tc.expectedError)
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExternalCAOption(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
externalCA string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
externalCA: "protocol=cfssl,url=anything",
|
|
|
|
expected: "cfssl: anything",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=CFSSL,url=anything",
|
|
|
|
expected: "cfssl: anything",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=Cfssl,url=https://example.com",
|
|
|
|
expected: "cfssl: https://example.com",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=Cfssl,url=https://example.com,foo=bar",
|
|
|
|
expected: "cfssl: https://example.com",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
externalCA: "protocol=Cfssl,url=https://example.com,foo=bar,foo=baz",
|
|
|
|
expected: "cfssl: https://example.com",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
|
|
opt := &ExternalCAOption{}
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set(tc.externalCA))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(tc.expected, opt.String()))
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExternalCAOptionMultiple(t *testing.T) {
|
|
|
|
opt := &ExternalCAOption{}
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com"))
|
|
|
|
assert.NilError(t, opt.Set("protocol=CFSSL,url=anything"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Len(opt.Value(), 2))
|
|
|
|
assert.Check(t, is.Equal("cfssl: https://example.com, cfssl: anything", opt.String()))
|
2016-12-25 16:23:35 -05:00
|
|
|
}
|