mirror of https://github.com/docker/cli.git
Merge pull request #3502 from thaJeztah/bump_golangci_lint
lint: update golangci-lint to v1.45.2
This commit is contained in:
commit
9fe6cb4b39
|
@ -6,12 +6,10 @@ linters:
|
||||||
- dogsled
|
- dogsled
|
||||||
- gocyclo
|
- gocyclo
|
||||||
- goimports
|
- goimports
|
||||||
- golint
|
|
||||||
- gosec
|
- gosec
|
||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- interfacer
|
|
||||||
- lll
|
- lll
|
||||||
- megacheck
|
- megacheck
|
||||||
- misspell
|
- misspell
|
||||||
|
@ -22,6 +20,7 @@ linters:
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
- unused
|
- unused
|
||||||
|
- revive
|
||||||
- varcheck
|
- varcheck
|
||||||
|
|
||||||
disable:
|
disable:
|
||||||
|
@ -59,30 +58,65 @@ issues:
|
||||||
- parameter .* always receives
|
- parameter .* always receives
|
||||||
|
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
# These are copied from the default exclude rules, except for "ineffective break statement"
|
# We prefer to use an "exclude-list" so that new "default" exclusions are not
|
||||||
# and GoDoc checks.
|
# automatically inherited. We can decide whether or not to follow upstream
|
||||||
# https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36
|
# defaults when updating golang-ci-lint versions.
|
||||||
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
|
# Unfortunately, this means we have to copy the whole exclusion pattern, as
|
||||||
|
# (unlike the "include" option), the "exclude" option does not take exclusion
|
||||||
|
# ID's.
|
||||||
|
#
|
||||||
|
# These exclusion patterns are copied from the default excluses at:
|
||||||
|
# https://github.com/golangci/golangci-lint/blob/v1.44.0/pkg/config/issues.go#L10-L104
|
||||||
|
|
||||||
|
# EXC0001
|
||||||
|
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked"
|
||||||
linters:
|
linters:
|
||||||
- errcheck
|
- errcheck
|
||||||
|
# EXC0003
|
||||||
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
|
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
|
||||||
linters:
|
linters:
|
||||||
- golint
|
- revive
|
||||||
- text: "G103: Use of unsafe calls should be audited"
|
# EXC0006
|
||||||
|
- text: "Use of unsafe calls should be audited"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
- text: "G104: Errors unhandled"
|
# EXC0007
|
||||||
|
- text: "Subprocess launch(ed with variable|ing should be audited)"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
- text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)"
|
# EXC0008
|
||||||
|
# TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close" (gosec)
|
||||||
|
- text: "(G104|G307)"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
- text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
|
# EXC0009
|
||||||
|
- text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
- text: "G304: Potential file inclusion via variable"
|
# EXC0010
|
||||||
|
- text: "Potential file inclusion via variable"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
- text: "(G201|G202): SQL string (formatting|concatenation)"
|
|
||||||
|
# Looks like the match in "EXC0007" above doesn't catch this one
|
||||||
|
# TODO: consider upstreaming this to golangci-lint's default exclusion rules
|
||||||
|
- text: "G204: Subprocess launched with a potential tainted input or cmd arguments"
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
|
# Looks like the match in "EXC0009" above doesn't catch this one
|
||||||
|
# TODO: consider upstreaming this to golangci-lint's default exclusion rules
|
||||||
|
- text: "G306: Expect WriteFile permissions to be 0600 or less"
|
||||||
|
linters:
|
||||||
|
- gosec
|
||||||
|
|
||||||
|
# Exclude some linters from running on tests files.
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- errcheck
|
||||||
|
- gosec
|
||||||
|
|
||||||
|
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
|
||||||
|
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
|
||||||
|
max-same-issues: 0
|
||||||
|
|
|
@ -19,13 +19,11 @@ func TestConfigContextFormatWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{formatter.Context{Format: NewFormat("table", false)},
|
{formatter.Context{Format: NewFormat("table", false)},
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestConfigInspectErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"foo", "bar"},
|
args: []string{"foo", "bar"},
|
||||||
|
|
|
@ -157,7 +157,7 @@ func (cid *cidFile) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := os.Remove(cid.path); err != nil {
|
if err := os.Remove(cid.path); err != nil {
|
||||||
return errors.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
|
return errors.Wrapf(err, "failed to remove the CID file '%s'", cid.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -168,7 +168,7 @@ func (cid *cidFile) Write(id string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, err := cid.file.Write([]byte(id)); err != nil {
|
if _, err := cid.file.Write([]byte(id)); err != nil {
|
||||||
return errors.Errorf("Failed to write the container ID to the file: %s", err)
|
return errors.Wrap(err, "failed to write the container ID to the file")
|
||||||
}
|
}
|
||||||
cid.written = true
|
cid.written = true
|
||||||
return nil
|
return nil
|
||||||
|
@ -179,12 +179,12 @@ func newCIDFile(path string) (*cidFile, error) {
|
||||||
return &cidFile{}, nil
|
return &cidFile{}, nil
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(path); err == nil {
|
if _, err := os.Stat(path); err == nil {
|
||||||
return nil, errors.Errorf("Container ID file found, make sure the other container isn't running or delete %s", path)
|
return nil, errors.Errorf("container ID file found, make sure the other container isn't running or delete %s", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Create(path)
|
f, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("Failed to create the container ID file: %s", err)
|
return nil, errors.Wrap(err, "failed to create the container ID file")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &cidFile{path: path, file: f}, nil
|
return &cidFile{path: path, file: f}, nil
|
||||||
|
|
|
@ -38,7 +38,7 @@ func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
|
||||||
defer tempfile.Remove()
|
defer tempfile.Remove()
|
||||||
|
|
||||||
_, err := newCIDFile(tempfile.Path())
|
_, err := newCIDFile(tempfile.Path())
|
||||||
assert.ErrorContains(t, err, "Container ID file found")
|
assert.ErrorContains(t, err, "container ID file found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCIDFileCloseWithNoWrite(t *testing.T) {
|
func TestCIDFileCloseWithNoWrite(t *testing.T) {
|
||||||
|
|
|
@ -181,14 +181,14 @@ func (c *statsContext) ID() string {
|
||||||
|
|
||||||
func (c *statsContext) CPUPerc() string {
|
func (c *statsContext) CPUPerc() string {
|
||||||
if c.s.IsInvalid {
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("--")
|
return "--"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%.2f%%", c.s.CPUPercentage)
|
return fmt.Sprintf("%.2f%%", c.s.CPUPercentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *statsContext) MemUsage() string {
|
func (c *statsContext) MemUsage() string {
|
||||||
if c.s.IsInvalid {
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("-- / --")
|
return "-- / --"
|
||||||
}
|
}
|
||||||
if c.os == winOSType {
|
if c.os == winOSType {
|
||||||
return units.BytesSize(c.s.Memory)
|
return units.BytesSize(c.s.Memory)
|
||||||
|
@ -198,28 +198,28 @@ func (c *statsContext) MemUsage() string {
|
||||||
|
|
||||||
func (c *statsContext) MemPerc() string {
|
func (c *statsContext) MemPerc() string {
|
||||||
if c.s.IsInvalid || c.os == winOSType {
|
if c.s.IsInvalid || c.os == winOSType {
|
||||||
return fmt.Sprintf("--")
|
return "--"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%.2f%%", c.s.MemoryPercentage)
|
return fmt.Sprintf("%.2f%%", c.s.MemoryPercentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *statsContext) NetIO() string {
|
func (c *statsContext) NetIO() string {
|
||||||
if c.s.IsInvalid {
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("--")
|
return "--"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.NetworkRx, 3), units.HumanSizeWithPrecision(c.s.NetworkTx, 3))
|
return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.NetworkRx, 3), units.HumanSizeWithPrecision(c.s.NetworkTx, 3))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *statsContext) BlockIO() string {
|
func (c *statsContext) BlockIO() string {
|
||||||
if c.s.IsInvalid {
|
if c.s.IsInvalid {
|
||||||
return fmt.Sprintf("--")
|
return "--"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.BlockRead, 3), units.HumanSizeWithPrecision(c.s.BlockWrite, 3))
|
return fmt.Sprintf("%s / %s", units.HumanSizeWithPrecision(c.s.BlockRead, 3), units.HumanSizeWithPrecision(c.s.BlockWrite, 3))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *statsContext) PIDs() string {
|
func (c *statsContext) PIDs() string {
|
||||||
if c.s.IsInvalid || c.os == winOSType {
|
if c.s.IsInvalid || c.os == winOSType {
|
||||||
return fmt.Sprintf("--")
|
return "--"
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%d", c.s.PidsCurrent)
|
return fmt.Sprintf("%d", c.s.PidsCurrent)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,11 @@ func TestContainerStatsContextWrite(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "table {{.MemUsage}}"},
|
formatter.Context{Format: "table {{.MemUsage}}"},
|
||||||
|
|
|
@ -130,13 +130,11 @@ func TestContainerContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
Context{Format: "{{InvalidFunction}}"},
|
Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: "{{nil}}"},
|
Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,8 +61,7 @@ CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
|
||||||
Format: "{{InvalidFunction}}",
|
Format: "{{InvalidFunction}}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DiskUsageContext{
|
DiskUsageContext{
|
||||||
|
@ -70,8 +69,7 @@ CACHE ID CACHE TYPE SIZE CREATED LAST USED USAGE SHARED
|
||||||
Format: "{{nil}}",
|
Format: "{{nil}}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (c *Context) preFormat() {
|
||||||
func (c *Context) parseFormat() (*template.Template, error) {
|
func (c *Context) parseFormat() (*template.Template, error) {
|
||||||
tmpl, err := templates.Parse(c.finalFormat)
|
tmpl, err := templates.Parse(c.finalFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tmpl, errors.Errorf("Template parsing error: %v\n", err)
|
return tmpl, errors.Wrap(err, "template parsing error")
|
||||||
}
|
}
|
||||||
return tmpl, err
|
return tmpl, err
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) {
|
||||||
|
|
||||||
func (c *Context) contextFormat(tmpl *template.Template, subContext SubContext) error {
|
func (c *Context) contextFormat(tmpl *template.Template, subContext SubContext) error {
|
||||||
if err := tmpl.Execute(c.buffer, subContext); err != nil {
|
if err := tmpl.Execute(c.buffer, subContext); err != nil {
|
||||||
return errors.Errorf("Template parsing error: %v\n", err)
|
return errors.Wrap(err, "template parsing error")
|
||||||
}
|
}
|
||||||
if c.Format.IsTable() && c.header != nil {
|
if c.Format.IsTable() && c.header != nil {
|
||||||
c.header = subContext.FullHeader()
|
c.header = subContext.FullHeader()
|
||||||
|
|
|
@ -119,8 +119,7 @@ func TestImageContextWrite(t *testing.T) {
|
||||||
Format: "{{InvalidFunction}}",
|
Format: "{{InvalidFunction}}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ImageContext{
|
ImageContext{
|
||||||
|
@ -128,8 +127,7 @@ func TestImageContextWrite(t *testing.T) {
|
||||||
Format: "{{nil}}",
|
Format: "{{nil}}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,13 +62,11 @@ func TestVolumeContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
Context{Format: "{{InvalidFunction}}"},
|
Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Context{Format: "{{nil}}"},
|
Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -254,7 +254,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := build.ValidateContextDirectory(contextDir, excludes); err != nil {
|
if err := build.ValidateContextDirectory(contextDir, excludes); err != nil {
|
||||||
return errors.Errorf("error checking context: '%s'.", err)
|
return errors.Wrap(err, "error checking context")
|
||||||
}
|
}
|
||||||
|
|
||||||
// And canonicalize dockerfile name to a platform-independent one
|
// And canonicalize dockerfile name to a platform-independent one
|
||||||
|
|
|
@ -50,7 +50,7 @@ func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, e
|
||||||
|
|
||||||
tmpl, err := templates.Parse(tmplStr)
|
tmpl, err := templates.Parse(tmplStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("Template parsing error: %s", err)
|
return nil, errors.Errorf("template parsing error: %s", err)
|
||||||
}
|
}
|
||||||
return NewTemplateInspector(out, tmpl), nil
|
return NewTemplateInspector(out, tmpl), nil
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte)
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
if err := i.tmpl.Execute(buffer, typedElement); err != nil {
|
if err := i.tmpl.Execute(buffer, typedElement); err != nil {
|
||||||
if rawElement == nil {
|
if rawElement == nil {
|
||||||
return errors.Errorf("Template parsing error: %v", err)
|
return errors.Errorf("template parsing error: %v", err)
|
||||||
}
|
}
|
||||||
return i.tryRawInspectFallback(rawElement)
|
return i.tryRawInspectFallback(rawElement)
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error {
|
||||||
|
|
||||||
tmplMissingKey := i.tmpl.Option("missingkey=error")
|
tmplMissingKey := i.tmpl.Option("missingkey=error")
|
||||||
if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
|
if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil {
|
||||||
return errors.Errorf("Template parsing error: %v", rawErr)
|
return errors.Errorf("template parsing error: %v", rawErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
i.buffer.Write(buffer.Bytes())
|
i.buffer.Write(buffer.Bytes())
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestTemplateInspectorTemplateError(t *testing.T) {
|
||||||
t.Fatal("Expected error got nil")
|
t.Fatal("Expected error got nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(err.Error(), "Template parsing error") {
|
if !strings.HasPrefix(err.Error(), "template parsing error") {
|
||||||
t.Fatalf("Expected template error, got %v", err)
|
t.Fatalf("Expected template error, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ func TestTemplateInspectorRawFallbackError(t *testing.T) {
|
||||||
t.Fatal("Expected error got nil")
|
t.Fatal("Expected error got nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(err.Error(), "Template parsing error") {
|
if !strings.HasPrefix(err.Error(), "template parsing error") {
|
||||||
t.Fatalf("Expected template error, got %v", err)
|
t.Fatalf("Expected template error, got %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,13 +79,11 @@ func TestNetworkContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -62,15 +62,13 @@ func TestNodeContextWrite(t *testing.T) {
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
context: formatter.Context{Format: "{{InvalidFunction}}"},
|
context: formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
expected: `Template parsing error: template: :1: function "InvalidFunction" not defined
|
expected: `template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
|
clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
context: formatter.Context{Format: "{{nil}}"},
|
context: formatter.Context{Format: "{{nil}}"},
|
||||||
expected: `Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
expected: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
|
clusterInfo: swarm.ClusterInfo{TLSInfo: swarm.TLSInfo{TrustRoot: "hi"}},
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
|
|
|
@ -59,13 +59,11 @@ func TestPluginContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,7 +61,7 @@ func TestInspectErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestListErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,13 +112,11 @@ func TestSearchContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,13 +19,11 @@ func TestSecretContextFormatWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{formatter.Context{Format: NewFormat("table", false)},
|
{formatter.Context{Format: NewFormat("table", false)},
|
||||||
|
|
|
@ -36,7 +36,7 @@ func TestSecretInspectErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"foo", "bar"},
|
args: []string{"foo", "bar"},
|
||||||
|
|
|
@ -29,13 +29,11 @@ func TestServiceContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -914,7 +914,7 @@ func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions, defaultFlagValu
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagCredentialSpec = "credential-spec"
|
flagCredentialSpec = "credential-spec" //nolint:gosec // ignore G101: Potential hardcoded credentials
|
||||||
flagPlacementPref = "placement-pref"
|
flagPlacementPref = "placement-pref"
|
||||||
flagPlacementPrefAdd = "placement-pref-add"
|
flagPlacementPrefAdd = "placement-pref-add"
|
||||||
flagPlacementPrefRemove = "placement-pref-rm"
|
flagPlacementPrefRemove = "placement-pref-rm"
|
||||||
|
|
|
@ -16,13 +16,11 @@ func TestStackContextWrite(t *testing.T) {
|
||||||
// Errors
|
// Errors
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table format
|
// Table format
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestListErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.
|
||||||
config, err := loader.Load(configDetails)
|
config, err := loader.Load(configDetails)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
|
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
|
||||||
|
//nolint:revive // ignore capitalization error; this error is intentionally formatted multi-line
|
||||||
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
|
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
|
||||||
propertyWarnings(fpe.Properties))
|
propertyWarnings(fpe.Properties))
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestStackServicesErrors(t *testing.T) {
|
||||||
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
return []swarm.Service{*Service()}, nil
|
return []swarm.Service{*Service()}, nil
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -548,7 +548,7 @@ func formatInfo(dockerCli command.Cli, info info, format string) error {
|
||||||
tmpl, err := templates.Parse(format)
|
tmpl, err := templates.Parse(format)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.StatusError{StatusCode: 64,
|
return cli.StatusError{StatusCode: 64,
|
||||||
Status: "Template parsing error: " + err.Error()}
|
Status: "template parsing error: " + err.Error()}
|
||||||
}
|
}
|
||||||
err = tmpl.Execute(dockerCli.Out(), info)
|
err = tmpl.Execute(dockerCli.Out(), info)
|
||||||
dockerCli.Out().Write([]byte{'\n'})
|
dockerCli.Out().Write([]byte{'\n'})
|
||||||
|
|
|
@ -396,7 +396,7 @@ func TestFormatInfo(t *testing.T) {
|
||||||
{
|
{
|
||||||
doc: "syntax",
|
doc: "syntax",
|
||||||
template: "{{}",
|
template: "{{}",
|
||||||
expectedError: `Status: Template parsing error: template: :1: unexpected "}" in command, Code: 64`,
|
expectedError: `Status: template parsing error: template: :1: unexpected "}" in command, Code: 64`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
doc: "syntax",
|
doc: "syntax",
|
||||||
|
|
|
@ -198,7 +198,7 @@ func newVersionTemplate(templateFormat string) (*template.Template, error) {
|
||||||
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
|
tmpl := templates.New("version").Funcs(template.FuncMap{"getDetailsOrder": getDetailsOrder})
|
||||||
tmpl, err := tmpl.Parse(templateFormat)
|
tmpl, err := tmpl.Parse(templateFormat)
|
||||||
|
|
||||||
return tmpl, errors.Wrap(err, "Template parsing error")
|
return tmpl, errors.Wrap(err, "template parsing error")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDetailsOrder(v types.ComponentVersion) []string {
|
func getDetailsOrder(v types.ComponentVersion) []string {
|
||||||
|
|
|
@ -20,13 +20,11 @@ func TestTaskContextWrite(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{InvalidFunction}}"},
|
formatter.Context{Format: "{{InvalidFunction}}"},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: "{{nil}}"},
|
formatter.Context{Format: "{{nil}}"},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{Format: NewTaskFormat("table", true)},
|
formatter.Context{Format: NewTaskFormat("table", true)},
|
||||||
|
|
|
@ -95,15 +95,13 @@ func TestTrustTagContextWrite(t *testing.T) {
|
||||||
formatter.Context{
|
formatter.Context{
|
||||||
Format: "{{InvalidFunction}}",
|
Format: "{{InvalidFunction}}",
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{
|
formatter.Context{
|
||||||
Format: "{{nil}}",
|
Format: "{{nil}}",
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
|
@ -191,15 +189,13 @@ func TestSignerInfoContextWrite(t *testing.T) {
|
||||||
formatter.Context{
|
formatter.Context{
|
||||||
Format: "{{InvalidFunction}}",
|
Format: "{{InvalidFunction}}",
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1: function "InvalidFunction" not defined
|
`template parsing error: template: :1: function "InvalidFunction" not defined`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
formatter.Context{
|
formatter.Context{
|
||||||
Format: "{{nil}}",
|
Format: "{{nil}}",
|
||||||
},
|
},
|
||||||
`Template parsing error: template: :1:2: executing "" at <nil>: nil is not a command
|
`template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
|
||||||
`,
|
|
||||||
},
|
},
|
||||||
// Table Format
|
// Table Format
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
if options.name != "" {
|
if options.name != "" {
|
||||||
return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
|
return errors.Errorf("conflicting options: either specify --name or provide positional arg, not both")
|
||||||
}
|
}
|
||||||
options.name = args[0]
|
options.name = args[0]
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestVolumeCreateErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"name": "volumeName",
|
"name": "volumeName",
|
||||||
},
|
},
|
||||||
expectedError: "Conflicting options: either specify --name or provide positional arg, not both",
|
expectedError: "conflicting options: either specify --name or provide positional arg, not both",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"too", "many"},
|
args: []string{"too", "many"},
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestVolumeInspectErrors(t *testing.T) {
|
||||||
flags: map[string]string{
|
flags: map[string]string{
|
||||||
"format": "{{invalid format}}",
|
"format": "{{invalid format}}",
|
||||||
},
|
},
|
||||||
expectedError: "Template parsing error",
|
expectedError: "template parsing error",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
args: []string{"foo", "bar"},
|
args: []string{"foo", "bar"},
|
||||||
|
|
|
@ -99,7 +99,7 @@ func newPathError(path Path, err error) error {
|
||||||
return nil
|
return nil
|
||||||
case *template.InvalidTemplateError:
|
case *template.InvalidTemplateError:
|
||||||
return errors.Errorf(
|
return errors.Errorf(
|
||||||
"invalid interpolation format for %s: %#v. You may need to escape any $ with another $.",
|
"invalid interpolation format for %s: %#v; you may need to escape any $ with another $",
|
||||||
path, err.Template)
|
path, err.Template)
|
||||||
default:
|
default:
|
||||||
return errors.Wrapf(err, "error while interpolating %s", path)
|
return errors.Wrapf(err, "error while interpolating %s", path)
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestInvalidInterpolation(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := Interpolate(services, Options{LookupValue: defaultMapping})
|
_, err := Interpolate(services, Options{LookupValue: defaultMapping})
|
||||||
assert.Error(t, err, `invalid interpolation format for servicea.image: "${". You may need to escape any $ with another $.`)
|
assert.Error(t, err, `invalid interpolation format for servicea.image: "${"; you may need to escape any $ with another $`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInterpolateWithDefaults(t *testing.T) {
|
func TestInterpolateWithDefaults(t *testing.T) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
remoteCredentialsPrefix = "docker-credential-"
|
remoteCredentialsPrefix = "docker-credential-" //nolint:gosec // ignore G101: Potential hardcoded credentials
|
||||||
tokenUsername = "<token>"
|
tokenUsername = "<token>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
ARG GO_VERSION=1.17.8
|
ARG GO_VERSION=1.17.8
|
||||||
ARG GOLANGCI_LINT_VERSION=v1.23.8
|
ARG GOLANGCI_LINT_VERSION=v1.45.2
|
||||||
|
|
||||||
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
|
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue