Skip to content

Commit

Permalink
chore: bring golangci-lint back (#2571)
Browse files Browse the repository at this point in the history
* fix: enable golangci-lint again

It was accidentally dropped when bumping the Go version

* fix: lint

* fix: lint

* fix: lint

* fix: dolt module must raise errors with options

* fix: lint

* fix: return error in compose module

* fix: influxdb module must return error on customise

* chore: use assert

* fix: no named returns in k3s module

* chore: fix lint

* chore: lint

* fix: registry module must return error on customise

* fi: use same types
  • Loading branch information
mdelapenya committed Jun 10, 2024
1 parent 43670b6 commit 4d094ce
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 53 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ jobs:
id: go

- name: golangci-lint
# TODO: Remove each example/module once it passes the golangci-lint
if: ${{ inputs.platform == 'ubuntu-latest' && inputs.go-version == '1.20.x' }}
if: ${{ inputs.platform == 'ubuntu-latest' }}
uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
Expand Down
2 changes: 1 addition & 1 deletion docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ func TestContainerInspect_RawInspectIsCleanedOnStop(t *testing.T) {

assert.NotEmpty(t, inspect.ID)

container.Stop(context.Background(), nil)
require.NoError(t, container.Stop(context.Background(), nil))

assert.Nil(t, container.raw)
}
Expand Down
36 changes: 18 additions & 18 deletions modulegen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ func assertModuleDocContent(t *testing.T, module context.TestcontainersModule, m
title := module.Title()

data := sanitiseContent(content)
assert.Equal(t, data[0], "# "+title)
assert.Equal(t, "# "+title, data[0])
assert.Equal(t, `Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>`, data[2])
assert.Equal(t, "## Introduction", data[4])
assert.Equal(t, data[6], "The Testcontainers module for "+title+".")
assert.Equal(t, "The Testcontainers module for "+title+".", data[6])
assert.Equal(t, "## Adding this module to your project dependencies", data[8])
assert.Equal(t, data[10], "Please run the following command to add the "+title+" module to your Go dependencies:")
assert.Equal(t, data[13], "go get github.com/testcontainers/testcontainers-go/"+module.ParentDir()+"/"+lower)
assert.Equal(t, "Please run the following command to add the "+title+" module to your Go dependencies:", data[10])
assert.Equal(t, "go get github.com/testcontainers/testcontainers-go/"+module.ParentDir()+"/"+lower, data[13])
assert.Equal(t, "<!--codeinclude-->", data[18])
assert.Equal(t, data[19], "[Creating a "+title+" container](../../"+module.ParentDir()+"/"+lower+"/examples_test.go) inside_block:run"+title+"Container")
assert.Equal(t, "[Creating a "+title+" container](../../"+module.ParentDir()+"/"+lower+"/examples_test.go) inside_block:run"+title+"Container", data[19])
assert.Equal(t, "<!--/codeinclude-->", data[20])
assert.Equal(t, data[24], "The "+title+" module exposes one entrypoint function to create the "+title+" container, and this function receives two parameters:")
assert.Equal(t, "The "+title+" module exposes one entrypoint function to create the "+title+" container, and this function receives two parameters:", data[24])
assert.True(t, strings.HasSuffix(data[27], "(*"+title+"Container, error)"))
assert.Equal(t, "for "+title+". E.g. `testcontainers.WithImage(\""+module.Image+"\")`.", data[40])
}
Expand Down Expand Up @@ -419,18 +419,18 @@ func assertModuleContent(t *testing.T, module context.TestcontainersModule, exam
entrypoint := module.Entrypoint()

data := sanitiseContent(content)
assert.Equal(t, data[0], "package "+lower)
assert.Equal(t, data[9], "// "+containerName+" represents the "+exampleName+" container type used in the module")
assert.Equal(t, data[10], "type "+containerName+" struct {")
assert.Equal(t, data[11], "\t*testcontainers.DockerContainer")
assert.Equal(t, data[14], "// "+entrypoint+" creates an instance of the "+exampleName+" container type")
assert.Equal(t, data[15], "func "+entrypoint+"(ctx context.Context, opts ...testcontainers.RequestCustomizer) (*"+containerName+", error) {")
assert.Equal(t, data[16], "\treq := testcontainers.Request{")
assert.Equal(t, data[17], "\t\tImage: \""+module.Image+"\",")
assert.Equal(t, data[18], "\t\tStarted: true,")
assert.Equal(t, data[22], "\t\tif err := opt.Customize(&req); err != nil {")
assert.Equal(t, data[23], "\t\t\treturn nil, fmt.Errorf(\"customize: %w\", err)")
assert.Equal(t, data[32], "\treturn &"+containerName+"{DockerContainer: container}, nil")
assert.Equal(t, "package "+lower, data[0])
assert.Equal(t, "// "+containerName+" represents the "+exampleName+" container type used in the module", data[9])
assert.Equal(t, "type "+containerName+" struct {", data[10])
assert.Equal(t, "\t*testcontainers.DockerContainer", data[11])
assert.Equal(t, "// "+entrypoint+" creates an instance of the "+exampleName+" container type", data[14])
assert.Equal(t, "func "+entrypoint+"(ctx context.Context, opts ...testcontainers.RequestCustomizer) (*"+containerName+", error) {", data[15])
assert.Equal(t, "\treq := testcontainers.Request{", data[16])
assert.Equal(t, "\t\tImage: \""+module.Image+"\",", data[17])
assert.Equal(t, "\t\tStarted: true,", data[18])
assert.Equal(t, "\t\tif err := opt.Customize(&req); err != nil {", data[22])
assert.Equal(t, "\t\t\treturn nil, fmt.Errorf(\"customize: %w\", err)", data[23])
assert.Equal(t, "\treturn &"+containerName+"{DockerContainer: container}, nil", data[32])
}

// assert content GitHub workflow for the module
Expand Down
4 changes: 3 additions & 1 deletion modules/dolt/dolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.RequestCustomizer)
opts = append(opts, WithDefaultCredentials())

for _, opt := range opts {
opt.Customize(&req)
if err := opt.Customize(&req); err != nil {
return nil, err
}
}

createUser := true
Expand Down
1 change: 0 additions & 1 deletion modules/elasticsearch/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func TestElasticsearch8WithoutSSL(t *testing.T) {
}
})
}

}

func TestElasticsearch8WithoutCredentials(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion modules/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.RequestCustomizer)
}

for _, opt := range opts {
opt.Customize(&req)
if err := opt.Customize(&req); err != nil {
return nil, err
}
}

hasInitDb := false
Expand Down
4 changes: 2 additions & 2 deletions modules/influxdb/influxdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestWithInitDb(t *testing.T) {
ctx := context.Background()
influxDbContainer, err := influxdb.RunContainer(ctx,
testcontainers.WithImage("influxdb:1.8.10"),
influxdb.WithInitDb(filepath.Join("testdata")),
influxdb.WithInitDb("testdata"),
)
require.NoError(t, err)
t.Cleanup(func() {
Expand Down Expand Up @@ -122,5 +122,5 @@ func TestWithConfigFile(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, "1.8.10", version)
assert.True(t, ping > 0)
assert.Greater(t, ping, time.Duration(0))
}
5 changes: 3 additions & 2 deletions modules/k3s/k3s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ func TestLoadImages(t *testing.T) {
})
}

func getTestPodState(ctx context.Context, k8s *kubernetes.Clientset) (state corev1.ContainerState, err error) {
func getTestPodState(ctx context.Context, k8s *kubernetes.Clientset) (corev1.ContainerState, error) {
var pod *corev1.Pod
var err error
pod, err = k8s.CoreV1().Pods("default").Get(ctx, "test-pod", metav1.GetOptions{})
if err != nil || len(pod.Status.ContainerStatuses) == 0 {
return
return corev1.ContainerState{}, err
}
return pod.Status.ContainerStatuses[0].State, nil
}
Expand Down
3 changes: 0 additions & 3 deletions modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type DownloadableFile struct {
func (d *DownloadableFile) getDownloadPath() string {
baseName := path.Base(d.Uri.Path)
return path.Join(d.DownloadDir, baseName)

}

func downloadFileFromDescription(d DownloadableFile) error {
Expand Down Expand Up @@ -62,7 +61,6 @@ func downloadFileFromDescription(d DownloadableFile) error {

_, err = io.Copy(downloadedFile, resp.Body)
return err

}

// WithTestScript mounts the given script into the ./test directory in the container
Expand All @@ -78,7 +76,6 @@ func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption {
}

return WithTestScriptReader(f, scriptBaseName)

}

// WithTestScriptReader copies files into the Container using the Reader API
Expand Down
4 changes: 2 additions & 2 deletions modules/mysql/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func TestMySQL(t *testing.T) {
if err != nil {
t.Fatal(err)
}
mustConnectionString := container.MustConnectionString(ctx,"tls=skip-verify")
if mustConnectionString!=connectionString{
mustConnectionString := container.MustConnectionString(ctx, "tls=skip-verify")
if mustConnectionString != connectionString {
t.Errorf("ConnectionString was not equal to MustConnectionString")
}

Expand Down
4 changes: 1 addition & 3 deletions modules/nats/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ func TestNATS(t *testing.T) {
t.Fatalf("failed to get connection string: %s", err)
}
mustUri := container.MustConnectionString(ctx)
if mustUri!=uri{
if mustUri != uri {
t.Errorf("URI was not equal to MustUri")
}


// perform assertions
nc, err := nats.Connect(uri)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions modules/ollama/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func ExampleRunContainer_withModel_llama2_http() {

_, _, err = ollamaContainer.Exec(ctx, []string{"ollama", "pull", model})
if err != nil {
log.Fatalf("failed to pull model %s: %s", model, err)
log.Fatalf("failed to pull model %s: %s", model, err) // nolint:gocritic
}

_, _, err = ollamaContainer.Exec(ctx, []string{"ollama", "run", model})
if err != nil {
log.Fatalf("failed to run model %s: %s", model, err)
log.Fatalf("failed to run model %s: %s", model, err) // nolint:gocritic
}

connectionStr, err := ollamaContainer.ConnectionString(ctx)
Expand Down Expand Up @@ -121,12 +121,12 @@ func ExampleRunContainer_withModel_llama2_langchain() {

_, _, err = ollamaContainer.Exec(ctx, []string{"ollama", "pull", model})
if err != nil {
log.Fatalf("failed to pull model %s: %s", model, err)
log.Fatalf("failed to pull model %s: %s", model, err) // nolint:gocritic
}

_, _, err = ollamaContainer.Exec(ctx, []string{"ollama", "run", model})
if err != nil {
log.Fatalf("failed to run model %s: %s", model, err)
log.Fatalf("failed to run model %s: %s", model, err) // nolint:gocritic
}

connectionStr, err := ollamaContainer.ConnectionString(ctx)
Expand Down
16 changes: 8 additions & 8 deletions modules/rabbitmq/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func ExampleRunContainer_connectUsingAmqp() {

amqpConnection, err := amqp.Dial(amqpURL)
if err != nil {
log.Fatalf("failed to connect to RabbitMQ: %s", err)
log.Fatalf("failed to connect to RabbitMQ: %s", err) // nolint:gocritic
}
defer func() {
err := amqpConnection.Close()
if err != nil {
log.Fatalf("failed to close connection: %s", err)
log.Fatalf("failed to close connection: %s", err) // nolint:gocritic
}
}()

Expand All @@ -92,7 +92,7 @@ func ExampleRunContainer_withSSL() {

tmpDir := os.TempDir()
certDirs := tmpDir + "/rabbitmq"
if err := os.MkdirAll(certDirs, 0755); err != nil {
if err := os.MkdirAll(certDirs, 0o755); err != nil {
log.Fatalf("failed to create temporary directory: %s", err)
}
defer os.RemoveAll(certDirs)
Expand All @@ -105,7 +105,7 @@ func ExampleRunContainer_withSSL() {
ParentDir: certDirs,
})
if caCert == nil {
log.Fatal("failed to generate CA certificate")
log.Fatal("failed to generate CA certificate") // nolint:gocritic
}

cert := tlscert.SelfSignedFromRequest(tlscert.Request{
Expand All @@ -116,7 +116,7 @@ func ExampleRunContainer_withSSL() {
ParentDir: certDirs,
})
if cert == nil {
log.Fatal("failed to generate certificate")
log.Fatal("failed to generate certificate") // nolint:gocritic
}

sslSettings := rabbitmq.SSLSettings{
Expand All @@ -133,13 +133,13 @@ func ExampleRunContainer_withSSL() {
rabbitmq.WithSSL(sslSettings),
)
if err != nil {
log.Fatalf("failed to start container: %s", err)
log.Fatalf("failed to start container: %s", err) // nolint:gocritic
}
// }

defer func() {
if err := rabbitmqContainer.Terminate(ctx); err != nil {
log.Fatalf("failed to terminate container: %s", err)
log.Fatalf("failed to terminate container: %s", err) // nolint:gocritic
}
}()

Expand Down Expand Up @@ -205,7 +205,7 @@ func ExampleRunContainer_withCustomConfigFile() {

bytes, err := io.ReadAll(logs)
if err != nil {
log.Fatalf("failed to read logs: %s", err)
log.Fatalf("failed to read logs: %s", err) // nolint:gocritic
}

fmt.Println(strings.Contains(string(bytes), "config file(s) : /etc/rabbitmq/rabbitmq-testcontainers.conf"))
Expand Down
5 changes: 3 additions & 2 deletions modules/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (c *Container) DeleteImage(ctx context.Context, imageRef string) error {
return false
}).
WaitUntilReady(ctx, c)

if err != nil {
return fmt.Errorf("failed to get image digest: %w", err)
}
Expand Down Expand Up @@ -172,7 +171,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.RequestCustomizer)
}

for _, opt := range opts {
opt.Customize(&req)
if err := opt.Customize(&req); err != nil {
return nil, err
}
}

container, err := testcontainers.New(ctx, req)
Expand Down
4 changes: 2 additions & 2 deletions modules/weaviate/weaviate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"net/http"
"testing"

wvt "github.com/weaviate/weaviate-go-client/v4/weaviate"
wvtgrpc "github.com/weaviate/weaviate-go-client/v4/weaviate/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/weaviate"
wvt "github.com/weaviate/weaviate-go-client/v4/weaviate"
wvtgrpc "github.com/weaviate/weaviate-go-client/v4/weaviate/grpc"
)

func TestWeaviate(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion port_forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (sshdC *sshdContainer) exposeHostPort(ctx context.Context, ports ...int) er
pw := NewPortForwarder(fmt.Sprintf("localhost:%s", sshdC.port), sshdC.sshConfig, port, port)
sshdC.portForwarders = append(sshdC.portForwarders, *pw)

go pw.Forward(ctx)
go pw.Forward(ctx) //nolint:errcheck // Nothing we can usefully do with the error
}

var err error
Expand Down

0 comments on commit 4d094ce

Please sign in to comment.