зеркало из https://github.com/docker/compose.git
ci: enable testifylint linter
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Родитель
a9de9abcfb
Коммит
11e9621da5
|
@ -22,6 +22,7 @@ linters:
|
||||||
- nakedret
|
- nakedret
|
||||||
- nolintlint
|
- nolintlint
|
||||||
- staticcheck
|
- staticcheck
|
||||||
|
- testifylint
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
|
@ -71,3 +72,11 @@ issues:
|
||||||
# golangci hides some golint warnings (the warning about exported things
|
# golangci hides some golint warnings (the warning about exported things
|
||||||
# without documentation for example), this will make it show them anyway.
|
# without documentation for example), this will make it show them anyway.
|
||||||
exclude-use-default: false
|
exclude-use-default: false
|
||||||
|
# Maximum issues count per one linter.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
# Default: 50
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
# Maximum count of issues with the same text.
|
||||||
|
# Set to 0 to disable.
|
||||||
|
# Default: 3
|
||||||
|
max-same-issues: 0
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
"github.com/docker/compose/v2/pkg/mocks"
|
"github.com/docker/compose/v2/pkg/mocks"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/mock/gomock"
|
"go.uber.org/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -74,13 +75,13 @@ func TestPsTable(t *testing.T) {
|
||||||
cli.EXPECT().Out().Return(stdout).AnyTimes()
|
cli.EXPECT().Out().Return(stdout).AnyTimes()
|
||||||
cli.EXPECT().ConfigFile().Return(&configfile.ConfigFile{}).AnyTimes()
|
cli.EXPECT().ConfigFile().Return(&configfile.ConfigFile{}).AnyTimes()
|
||||||
err = runPs(ctx, cli, backend, nil, opts)
|
err = runPs(ctx, cli, backend, nil, opts)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = f.Seek(0, 0)
|
_, err = f.Seek(0, 0)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
output, err := os.ReadFile(out)
|
output, err := os.ReadFile(out)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Contains(t, string(output), "8080/tcp, 8443/tcp")
|
assert.Contains(t, string(output), "8080/tcp, 8443/tcp")
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPreferredIndentationStr(t *testing.T) {
|
func TestPreferredIndentationStr(t *testing.T) {
|
||||||
|
@ -83,10 +83,12 @@ func TestPreferredIndentationStr(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := preferredIndentationStr(tt.args.size, tt.args.useSpace)
|
got, err := preferredIndentationStr(tt.args.size, tt.args.useSpace)
|
||||||
if tt.wantErr && assert.NotNilf(t, err, fmt.Sprintf("preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)) {
|
if tt.wantErr {
|
||||||
return
|
require.Errorf(t, err, "preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)
|
||||||
}
|
} else {
|
||||||
|
require.NoError(t, err)
|
||||||
assert.Equalf(t, tt.want, got, "preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)
|
assert.Equalf(t, tt.want, got, "preferredIndentationStr(%v, %v)", tt.args.size, tt.args.useSpace)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/v2/types"
|
"github.com/compose-spec/compose-go/v2/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/mock/gomock"
|
"go.uber.org/mock/gomock"
|
||||||
|
|
||||||
compose "github.com/docker/compose/v2/pkg/api"
|
compose "github.com/docker/compose/v2/pkg/api"
|
||||||
|
@ -128,7 +129,7 @@ func TestViz(t *testing.T) {
|
||||||
IncludeImageName: false,
|
IncludeImageName: false,
|
||||||
IncludeNetworks: false,
|
IncludeNetworks: false,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err, "viz command failed")
|
require.NoError(t, err, "viz command failed")
|
||||||
|
|
||||||
// check indentation
|
// check indentation
|
||||||
assert.Contains(t, graphStr, "\n ", graphStr)
|
assert.Contains(t, graphStr, "\n ", graphStr)
|
||||||
|
@ -187,7 +188,7 @@ func TestViz(t *testing.T) {
|
||||||
IncludeImageName: true,
|
IncludeImageName: true,
|
||||||
IncludeNetworks: true,
|
IncludeNetworks: true,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err, "viz command failed")
|
require.NoError(t, err, "viz command failed")
|
||||||
|
|
||||||
// check indentation
|
// check indentation
|
||||||
assert.Contains(t, graphStr, "\n\t", graphStr)
|
assert.Contains(t, graphStr, "\n\t", graphStr)
|
||||||
|
|
|
@ -33,18 +33,17 @@ func TestPs(t *testing.T) {
|
||||||
const projectName = "e2e-ps"
|
const projectName = "e2e-ps"
|
||||||
|
|
||||||
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "up", "-d")
|
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "up", "-d")
|
||||||
if assert.NoError(t, res.Error) {
|
require.NoError(t, res.Error)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
|
_ = c.RunDockerComposeCmd(t, "--project-name", projectName, "down")
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
assert.Contains(t, res.Combined(), "Container e2e-ps-busybox-1 Started", res.Combined())
|
assert.Contains(t, res.Combined(), "Container e2e-ps-busybox-1 Started", res.Combined())
|
||||||
|
|
||||||
t.Run("table", func(t *testing.T) {
|
t.Run("table", func(t *testing.T) {
|
||||||
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
|
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
|
||||||
lines := strings.Split(res.Stdout(), "\n")
|
lines := strings.Split(res.Stdout(), "\n")
|
||||||
assert.Equal(t, 4, len(lines))
|
assert.Len(t, lines, 4)
|
||||||
count := 0
|
count := 0
|
||||||
for _, line := range lines[1:3] {
|
for _, line := range lines[1:3] {
|
||||||
if strings.Contains(line, "e2e-ps-busybox-1") {
|
if strings.Contains(line, "e2e-ps-busybox-1") {
|
||||||
|
@ -77,12 +76,12 @@ func TestPs(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
assert.Equal(t, 2, len(output))
|
assert.Len(t, output, 2)
|
||||||
for _, service := range output {
|
for _, service := range output {
|
||||||
assert.Equal(t, projectName, service.Project)
|
assert.Equal(t, projectName, service.Project)
|
||||||
publishers := service.Publishers
|
publishers := service.Publishers
|
||||||
if service.Name == "e2e-ps-busybox-1" {
|
if service.Name == "e2e-ps-busybox-1" {
|
||||||
assert.Equal(t, 1, len(publishers))
|
assert.Len(t, publishers, 1)
|
||||||
assert.Equal(t, api.PortPublishers{
|
assert.Equal(t, api.PortPublishers{
|
||||||
{
|
{
|
||||||
URL: "127.0.0.1",
|
URL: "127.0.0.1",
|
||||||
|
@ -94,7 +93,7 @@ func TestPs(t *testing.T) {
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
if service.Name == "e2e-ps-nginx-1" {
|
if service.Name == "e2e-ps-nginx-1" {
|
||||||
assert.Equal(t, 3, len(publishers))
|
assert.Len(t, publishers, 3)
|
||||||
assert.Equal(t, api.PortPublishers{
|
assert.Equal(t, api.PortPublishers{
|
||||||
{TargetPort: 80, Protocol: "tcp"},
|
{TargetPort: 80, Protocol: "tcp"},
|
||||||
{TargetPort: 443, Protocol: "tcp"},
|
{TargetPort: 443, Protocol: "tcp"},
|
||||||
|
@ -109,20 +108,20 @@ func TestPs(t *testing.T) {
|
||||||
|
|
||||||
t.Run("ps --all", func(t *testing.T) {
|
t.Run("ps --all", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
|
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
|
||||||
assert.NoError(t, res.Error)
|
require.NoError(t, res.Error)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
|
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps")
|
||||||
lines := strings.Split(res.Stdout(), "\n")
|
lines := strings.Split(res.Stdout(), "\n")
|
||||||
assert.Equal(t, 2, len(lines))
|
assert.Len(t, lines, 2)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--all")
|
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "--all")
|
||||||
lines = strings.Split(res.Stdout(), "\n")
|
lines = strings.Split(res.Stdout(), "\n")
|
||||||
assert.Equal(t, 4, len(lines))
|
assert.Len(t, lines, 4)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("ps unknown", func(t *testing.T) {
|
t.Run("ps unknown", func(t *testing.T) {
|
||||||
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
|
res := c.RunDockerComposeCmd(t, "--project-name", projectName, "stop")
|
||||||
assert.NoError(t, res.Error)
|
require.NoError(t, res.Error)
|
||||||
|
|
||||||
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "nginx")
|
res = c.RunDockerComposeCmd(t, "-f", "./fixtures/ps-test/compose.yaml", "--project-name", projectName, "ps", "nginx")
|
||||||
res.Assert(t, icmd.Success)
|
res.Assert(t, icmd.Success)
|
||||||
|
|
|
@ -98,7 +98,7 @@ func TestUpDependenciesNotStopped(t *testing.T) {
|
||||||
if exitErr.ExitCode() == -1 {
|
if exitErr.ExitCode() == -1 {
|
||||||
t.Fatalf("`compose up` was killed: %v", err)
|
t.Fatalf("`compose up` was killed: %v", err)
|
||||||
}
|
}
|
||||||
require.EqualValues(t, exitErr.ExitCode(), 130)
|
require.EqualValues(t, 130, exitErr.ExitCode())
|
||||||
}
|
}
|
||||||
|
|
||||||
RequireServiceState(t, c, "app", "exited")
|
RequireServiceState(t, c, "app", "exited")
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/docker/compose/v2/pkg/watch"
|
"github.com/docker/compose/v2/pkg/watch"
|
||||||
)
|
)
|
||||||
|
@ -36,14 +37,12 @@ func TestEphemeralPathMatcher(t *testing.T) {
|
||||||
matcher := watch.EphemeralPathMatcher()
|
matcher := watch.EphemeralPathMatcher()
|
||||||
for _, p := range ignored {
|
for _, p := range ignored {
|
||||||
ok, err := matcher.Matches(p)
|
ok, err := matcher.Matches(p)
|
||||||
if assert.NoErrorf(t, err, "Matching %s", p) {
|
require.NoErrorf(t, err, "Matching %s", p)
|
||||||
assert.Truef(t, ok, "Path %s should have matched", p)
|
assert.Truef(t, ok, "Path %s should have matched", p)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const includedPath = "normal.txt"
|
const includedPath = "normal.txt"
|
||||||
ok, err := matcher.Matches(includedPath)
|
ok, err := matcher.Matches(includedPath)
|
||||||
if assert.NoErrorf(t, err, "Matching %s", includedPath) {
|
require.NoErrorf(t, err, "Matching %s", includedPath)
|
||||||
assert.Falsef(t, ok, "Path %s should NOT have matched", includedPath)
|
assert.Falsef(t, ok, "Path %s should NOT have matched", includedPath)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,15 @@ func TestWindowsBufferSize(t *testing.T) {
|
||||||
defer os.Setenv(WindowsBufferSizeEnvVar, orig) //nolint:errcheck
|
defer os.Setenv(WindowsBufferSizeEnvVar, orig) //nolint:errcheck
|
||||||
|
|
||||||
err := os.Setenv(WindowsBufferSizeEnvVar, "")
|
err := os.Setenv(WindowsBufferSizeEnvVar, "")
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, defaultBufferSize, DesiredWindowsBufferSize())
|
assert.Equal(t, defaultBufferSize, DesiredWindowsBufferSize())
|
||||||
|
|
||||||
err = os.Setenv(WindowsBufferSizeEnvVar, "a")
|
err = os.Setenv(WindowsBufferSizeEnvVar, "a")
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, defaultBufferSize, DesiredWindowsBufferSize())
|
assert.Equal(t, defaultBufferSize, DesiredWindowsBufferSize())
|
||||||
|
|
||||||
err = os.Setenv(WindowsBufferSizeEnvVar, "10")
|
err = os.Setenv(WindowsBufferSizeEnvVar, "10")
|
||||||
assert.Nil(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, 10, DesiredWindowsBufferSize())
|
assert.Equal(t, 10, DesiredWindowsBufferSize())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,17 +21,18 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGreatestExistingAncestor(t *testing.T) {
|
func TestGreatestExistingAncestor(t *testing.T) {
|
||||||
f := NewTempDirFixture(t)
|
f := NewTempDirFixture(t)
|
||||||
|
|
||||||
p, err := greatestExistingAncestor(f.Path())
|
p, err := greatestExistingAncestor(f.Path())
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, f.Path(), p)
|
assert.Equal(t, f.Path(), p)
|
||||||
|
|
||||||
p, err = greatestExistingAncestor(f.JoinPath("missing"))
|
p, err = greatestExistingAncestor(f.JoinPath("missing"))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, f.Path(), p)
|
assert.Equal(t, f.Path(), p)
|
||||||
|
|
||||||
missingTopLevel := "/missingDir/a/b/c"
|
missingTopLevel := "/missingDir/a/b/c"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче