2015-12-15 20:53:17 -05:00
package opts
import (
2016-01-30 21:45:49 -05:00
"fmt"
2016-12-23 14:09:12 -05:00
"strings"
2015-12-15 20:53:17 -05:00
"testing"
)
func TestParseHost ( t * testing . T ) {
2016-02-17 19:05:52 -05:00
invalid := [ ] string {
"something with spaces" ,
"://" ,
"unknown://" ,
"tcp://:port" ,
"tcp://invalid:port" ,
2015-12-15 20:53:17 -05:00
}
2016-02-17 19:05:52 -05:00
2015-12-15 20:53:17 -05:00
valid := map [ string ] string {
2020-04-10 08:23:58 -04:00
"" : defaultHost ,
" " : defaultHost ,
" " : defaultHost ,
2015-12-15 20:53:17 -05:00
"fd://" : "fd://" ,
"fd://something" : "fd://something" ,
2020-04-10 08:23:58 -04:00
"tcp://host:" : fmt . Sprintf ( "tcp://host:%s" , defaultHTTPPort ) ,
"tcp://" : defaultTCPHost ,
"tcp://:2375" : fmt . Sprintf ( "tcp://%s:%s" , defaultHTTPHost , defaultHTTPPort ) ,
"tcp://:2376" : fmt . Sprintf ( "tcp://%s:%s" , defaultHTTPHost , defaultTLSHTTPPort ) ,
2015-12-15 20:53:17 -05:00
"tcp://0.0.0.0:8080" : "tcp://0.0.0.0:8080" ,
"tcp://192.168.0.0:12000" : "tcp://192.168.0.0:12000" ,
"tcp://192.168:8080" : "tcp://192.168:8080" ,
"tcp://0.0.0.0:1234567890" : "tcp://0.0.0.0:1234567890" , // yeah it's valid :P
2020-04-10 08:23:58 -04:00
" tcp://:7777/path " : fmt . Sprintf ( "tcp://%s:7777/path" , defaultHTTPHost ) ,
2015-12-15 20:53:17 -05:00
"tcp://docker.com:2375" : "tcp://docker.com:2375" ,
2020-04-10 08:23:58 -04:00
"unix://" : "unix://" + defaultUnixSocket ,
2015-12-15 20:53:17 -05:00
"unix://path/to/socket" : "unix://path/to/socket" ,
2020-04-10 08:23:58 -04:00
"npipe://" : "npipe://" + defaultNamedPipe ,
2016-01-30 21:45:49 -05:00
"npipe:////./pipe/foo" : "npipe:////./pipe/foo" ,
2015-12-15 20:53:17 -05:00
}
2016-02-17 19:05:52 -05:00
for _ , value := range invalid {
if _ , err := ParseHost ( false , value ) ; err == nil {
t . Errorf ( "Expected an error for %v, got [nil]" , value )
2015-12-15 20:53:17 -05:00
}
}
2016-02-17 19:05:52 -05:00
2015-12-15 20:53:17 -05:00
for value , expected := range valid {
2016-01-30 21:45:49 -05:00
if actual , err := ParseHost ( false , value ) ; err != nil || actual != expected {
t . Errorf ( "Expected for %v [%v], got [%v, %v]" , value , expected , actual , err )
2015-12-15 20:53:17 -05:00
}
}
}
func TestParseDockerDaemonHost ( t * testing . T ) {
invalids := map [ string ] string {
2019-08-14 04:04:43 -04:00
"tcp:a.b.c.d" : "" ,
"tcp:a.b.c.d/path" : "" ,
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
"udp://127.0.0.1" : "invalid bind address format: udp://127.0.0.1" ,
"udp://127.0.0.1:2375" : "invalid bind address format: udp://127.0.0.1:2375" ,
"tcp://unix:///run/docker.sock" : "invalid proto, expected tcp: unix:///run/docker.sock" ,
linting: address assorted issues found by gocritic
internal/test/builders/config.go:36:15: captLocal: `ID' should not be capitalized (gocritic)
func ConfigID(ID string) func(config *swarm.Config) {
^
internal/test/builders/secret.go:45:15: captLocal: `ID' should not be capitalized (gocritic)
func SecretID(ID string) func(secret *swarm.Secret) {
^
internal/test/builders/service.go:21:16: captLocal: `ID' should not be capitalized (gocritic)
func ServiceID(ID string) func(*swarm.Service) {
^
cli/command/image/formatter_history.go:100:15: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.h.CreatedBy, "\t", " ", -1)` (gocritic)
createdBy := strings.Replace(c.h.CreatedBy, "\t", " ", -1)
^
e2e/image/push_test.go:246:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
e2e/image/push_test.go:313:34: badCall: suspicious Join on 1 argument (gocritic)
assert.NilError(t, os.RemoveAll(filepath.Join(dir.Join("trust"))))
^
cli/config/configfile/file_test.go:185:2: assignOp: replace `c.GetAllCallCount = c.GetAllCallCount + 1` with `c.GetAllCallCount++` (gocritic)
c.GetAllCallCount = c.GetAllCallCount + 1
^
cli/command/context/inspect_test.go:20:58: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.MetadataPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<METADATA_PATH>", strings.Replace(si.MetadataPath, `\`, `\\`, -1), 1)
^
cli/command/context/inspect_test.go:21:53: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(si.TLSPath, `\`, `\\`, -1)` (gocritic)
expected = strings.Replace(expected, "<TLS_PATH>", strings.Replace(si.TLSPath, `\`, `\\`, -1), 1)
^
cli/command/container/formatter_stats.go:119:46: captLocal: `Stats' should not be capitalized (gocritic)
func statsFormatWrite(ctx formatter.Context, Stats []StatsEntry, osType string, trunc bool) error {
^
cli/command/container/stats_helpers.go:209:4: assignOp: replace `blkRead = blkRead + bioEntry.Value` with `blkRead += bioEntry.Value` (gocritic)
blkRead = blkRead + bioEntry.Value
^
cli/command/container/stats_helpers.go:211:4: assignOp: replace `blkWrite = blkWrite + bioEntry.Value` with `blkWrite += bioEntry.Value` (gocritic)
blkWrite = blkWrite + bioEntry.Value
^
cli/command/registry/formatter_search.go:67:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.s.Description, "\n", " ", -1)` (gocritic)
desc := strings.Replace(c.s.Description, "\n", " ", -1)
^
cli/command/registry/formatter_search.go:68:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", " ", -1)` (gocritic)
desc = strings.Replace(desc, "\r", " ", -1)
^
cli/command/service/list_test.go:164:5: assignOp: replace `tc.doc = tc.doc + " with quiet"` with `tc.doc += " with quiet"` (gocritic)
tc.doc = tc.doc + " with quiet"
^
cli/command/service/progress/progress.go:274:11: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(errMsg, "\n", " ", -1)` (gocritic)
errMsg = strings.Replace(errMsg, "\n", " ", -1)
^
cli/manifest/store/store.go:153:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(fileName, "/", "_", -1)` (gocritic)
return strings.Replace(fileName, "/", "_", -1)
^
cli/manifest/store/store.go:152:14: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(ref, ":", "-", -1)` (gocritic)
fileName := strings.Replace(ref, ":", "-", -1)
^
cli/command/plugin/formatter.go:79:10: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(c.p.Config.Description, "\n", "", -1)` (gocritic)
desc := strings.Replace(c.p.Config.Description, "\n", "", -1)
^
cli/command/plugin/formatter.go:80:9: wrapperFunc: use strings.ReplaceAll method in `strings.Replace(desc, "\r", "", -1)` (gocritic)
desc = strings.Replace(desc, "\r", "", -1)
^
cli/compose/convert/service.go:642:23: captLocal: `DNS' should not be capitalized (gocritic)
func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig {
^
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-11-20 07:30:05 -05:00
" tcp://:7777/path " : "invalid bind address format: tcp://:7777/path " , //nolint:gocritic // ignore mapKey: suspucious whitespace
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
"" : "invalid bind address format: " ,
2015-12-15 20:53:17 -05:00
}
valids := map [ string ] string {
"0.0.0.1:" : "tcp://0.0.0.1:2375" ,
"0.0.0.1:5555" : "tcp://0.0.0.1:5555" ,
"0.0.0.1:5555/path" : "tcp://0.0.0.1:5555/path" ,
"[::1]:" : "tcp://[::1]:2375" ,
"[::1]:5555/path" : "tcp://[::1]:5555/path" ,
"[0:0:0:0:0:0:0:1]:" : "tcp://[0:0:0:0:0:0:0:1]:2375" ,
"[0:0:0:0:0:0:0:1]:5555/path" : "tcp://[0:0:0:0:0:0:0:1]:5555/path" ,
2020-04-10 08:23:58 -04:00
":6666" : fmt . Sprintf ( "tcp://%s:6666" , defaultHTTPHost ) ,
":6666/path" : fmt . Sprintf ( "tcp://%s:6666/path" , defaultHTTPHost ) ,
"tcp://" : defaultTCPHost ,
"tcp://:7777" : fmt . Sprintf ( "tcp://%s:7777" , defaultHTTPHost ) ,
"tcp://:7777/path" : fmt . Sprintf ( "tcp://%s:7777/path" , defaultHTTPHost ) ,
2018-10-10 02:37:35 -04:00
"unix:///run/docker.sock" : "unix:///run/docker.sock" ,
2020-04-10 08:23:58 -04:00
"unix://" : "unix://" + defaultUnixSocket ,
2018-10-10 02:37:35 -04:00
"fd://" : "fd://" ,
"fd://something" : "fd://something" ,
"localhost:" : "tcp://localhost:2375" ,
"localhost:5555" : "tcp://localhost:5555" ,
"localhost:5555/path" : "tcp://localhost:5555/path" ,
2015-12-15 20:53:17 -05:00
}
for invalidAddr , expectedError := range invalids {
2019-08-14 04:04:43 -04:00
if addr , err := parseDockerDaemonHost ( invalidAddr ) ; err == nil || expectedError != "" && err . Error ( ) != expectedError {
2016-06-21 20:14:55 -04:00
t . Errorf ( "tcp %v address expected error %q return, got %q and addr %v" , invalidAddr , expectedError , err , addr )
2015-12-15 20:53:17 -05:00
}
}
for validAddr , expectedAddr := range valids {
2016-01-30 21:45:49 -05:00
if addr , err := parseDockerDaemonHost ( validAddr ) ; err != nil || addr != expectedAddr {
2015-12-15 20:53:17 -05:00
t . Errorf ( "%v -> expected %v, got (%v) addr (%v)" , validAddr , expectedAddr , err , addr )
}
}
}
func TestParseTCP ( t * testing . T ) {
2022-09-29 11:21:51 -04:00
defaultHTTPHost := "tcp://127.0.0.1:2376"
2015-12-15 20:53:17 -05:00
invalids := map [ string ] string {
2019-08-14 04:04:43 -04:00
"tcp:a.b.c.d" : "" ,
"tcp:a.b.c.d/path" : "" ,
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
"udp://127.0.0.1" : "invalid proto, expected tcp: udp://127.0.0.1" ,
"udp://127.0.0.1:2375" : "invalid proto, expected tcp: udp://127.0.0.1:2375" ,
2015-12-15 20:53:17 -05:00
}
valids := map [ string ] string {
"" : defaultHTTPHost ,
"tcp://" : defaultHTTPHost ,
"0.0.0.1:" : "tcp://0.0.0.1:2376" ,
"0.0.0.1:5555" : "tcp://0.0.0.1:5555" ,
"0.0.0.1:5555/path" : "tcp://0.0.0.1:5555/path" ,
":6666" : "tcp://127.0.0.1:6666" ,
":6666/path" : "tcp://127.0.0.1:6666/path" ,
"tcp://:7777" : "tcp://127.0.0.1:7777" ,
"tcp://:7777/path" : "tcp://127.0.0.1:7777/path" ,
"[::1]:" : "tcp://[::1]:2376" ,
"[::1]:5555" : "tcp://[::1]:5555" ,
"[::1]:5555/path" : "tcp://[::1]:5555/path" ,
"[0:0:0:0:0:0:0:1]:" : "tcp://[0:0:0:0:0:0:0:1]:2376" ,
"[0:0:0:0:0:0:0:1]:5555" : "tcp://[0:0:0:0:0:0:0:1]:5555" ,
"[0:0:0:0:0:0:0:1]:5555/path" : "tcp://[0:0:0:0:0:0:0:1]:5555/path" ,
"localhost:" : "tcp://localhost:2376" ,
"localhost:5555" : "tcp://localhost:5555" ,
"localhost:5555/path" : "tcp://localhost:5555/path" ,
}
for invalidAddr , expectedError := range invalids {
2019-08-14 04:04:43 -04:00
if addr , err := ParseTCPAddr ( invalidAddr , defaultHTTPHost ) ; err == nil || expectedError != "" && err . Error ( ) != expectedError {
2015-12-15 20:53:17 -05:00
t . Errorf ( "tcp %v address expected error %v return, got %s and addr %v" , invalidAddr , expectedError , err , addr )
}
}
for validAddr , expectedAddr := range valids {
2016-06-21 17:27:04 -04:00
if addr , err := ParseTCPAddr ( validAddr , defaultHTTPHost ) ; err != nil || addr != expectedAddr {
2015-12-15 20:53:17 -05:00
t . Errorf ( "%v -> expected %v, got %v and addr %v" , validAddr , expectedAddr , err , addr )
}
}
}
func TestParseInvalidUnixAddrInvalid ( t * testing . T ) {
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
if _ , err := parseSimpleProtoAddr ( "unix" , "tcp://127.0.0.1" , "unix:///var/run/docker.sock" ) ; err == nil || err . Error ( ) != "invalid proto, expected unix: tcp://127.0.0.1" {
2015-12-15 20:53:17 -05:00
t . Fatalf ( "Expected an error, got %v" , err )
}
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
if _ , err := parseSimpleProtoAddr ( "unix" , "unix://tcp://127.0.0.1" , "/var/run/docker.sock" ) ; err == nil || err . Error ( ) != "invalid proto, expected unix: tcp://127.0.0.1" {
2015-12-15 20:53:17 -05:00
t . Fatalf ( "Expected an error, got %v" , err )
}
2016-01-30 21:45:49 -05:00
if v , err := parseSimpleProtoAddr ( "unix" , "" , "/var/run/docker.sock" ) ; err != nil || v != "unix:///var/run/docker.sock" {
2015-12-15 20:53:17 -05:00
t . Fatalf ( "Expected an %v, got %v" , v , "unix:///var/run/docker.sock" )
}
}
2016-12-23 14:09:12 -05:00
func TestValidateExtraHosts ( t * testing . T ) {
valid := [ ] string {
` myhost:192.168.0.1 ` ,
` thathost:10.0.2.1 ` ,
` anipv6host:2003:ab34:e::1 ` ,
` ipv6local:::1 ` ,
2020-04-15 03:13:11 -04:00
` host.docker.internal:host-gateway ` ,
2016-12-23 14:09:12 -05:00
}
invalid := map [ string ] string {
` myhost:192.notanipaddress.1 ` : ` invalid IP ` ,
` thathost-nosemicolon10.0.0.1 ` : ` bad format ` ,
` anipv6host:::::1 ` : ` invalid IP ` ,
` ipv6local:::0:: ` : ` invalid IP ` ,
}
for _ , extrahost := range valid {
if _ , err := ValidateExtraHost ( extrahost ) ; err != nil {
t . Fatalf ( "ValidateExtraHost(`" + extrahost + "`) should succeed: error %v" , err )
}
}
for extraHost , expectedError := range invalid {
if _ , err := ValidateExtraHost ( extraHost ) ; err == nil {
t . Fatalf ( "ValidateExtraHost(`%q`) should have failed validation" , extraHost )
2023-11-20 07:54:53 -05:00
} else if ! strings . Contains ( err . Error ( ) , expectedError ) {
t . Fatalf ( "ValidateExtraHost(`%q`) error should contain %q" , extraHost , expectedError )
2016-12-23 14:09:12 -05:00
}
}
}