Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use Go testable examples in modules #1603

Merged
merged 39 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ba14798
fix: rename vault container in tests
mdelapenya Sep 6, 2023
b192a81
chore: adjust comment in template
mdelapenya Sep 6, 2023
64bd746
docs(vault): use RunContainer example in usage section
mdelapenya Sep 6, 2023
14a6022
docs: update vault docs
mdelapenya Sep 6, 2023
d5b68da
docs: add RunContainer example for redpanda
mdelapenya Sep 7, 2023
4cb9f60
docs: add RunContainer example for redis
mdelapenya Sep 7, 2023
93f2a5c
docs: document creating networks
mdelapenya Sep 7, 2023
61b37ec
docs: add RunContainer example for pulsar
mdelapenya Sep 7, 2023
e547200
docs: add RunContainer example for postgres
mdelapenya Sep 7, 2023
2273da3
docs: add RunContainer example for neo4j
mdelapenya Sep 7, 2023
a2b03fd
docs: add RunContainer example for nats
mdelapenya Sep 7, 2023
8325e51
docs: update quickstart to not use testing libraries
mdelapenya Sep 7, 2023
2886ebd
docs: add RunContainer example for mysql
mdelapenya Sep 7, 2023
72cabe1
docs: add RunContainer example for mongo
mdelapenya Sep 7, 2023
86015c5
docs: add RunContainer example for mariadb
mdelapenya Sep 7, 2023
fc9b9ce
chore: use logger to print out hostname external reason
mdelapenya Sep 7, 2023
7ad9043
docs: document new Go examples file
mdelapenya Sep 7, 2023
fc9bea3
docs: add RunContainer example for localstack
mdelapenya Sep 7, 2023
9bd0377
chore: convert k3s test into a testable example
mdelapenya Sep 7, 2023
9911613
chore: convert mongodb test into testable example
mdelapenya Sep 7, 2023
8f90e0a
fix: handle errors in example tests for elasticsearch
mdelapenya Sep 7, 2023
af18064
fix: do not deprecate used fields
mdelapenya Sep 8, 2023
286c86f
chore: convert couchbase test into testable example
mdelapenya Sep 8, 2023
7a48310
chore: convert clickhouse test into testable example
mdelapenya Sep 8, 2023
ac4c5f0
docs: adjust artemis docs
mdelapenya Sep 8, 2023
a6c4780
chore: simplify postgres example
mdelapenya Sep 8, 2023
b01f6af
fix: lint
mdelapenya Sep 8, 2023
94386b9
Merge branch 'main' into migrate-examples
mdelapenya Sep 10, 2023
d411e3a
chore(deps): bump github.com/hashicorp/vault-client-go in /modules/va…
mmorel-35 Sep 11, 2023
7c5f468
ci(lint): enable gocritic linter (#1605)
mmorel-35 Sep 11, 2023
a85ac93
ci(lint): enable errorlint linter (#1604)
mmorel-35 Sep 11, 2023
d6c4221
fix: handle errors
mdelapenya Sep 11, 2023
9235361
chore(pulsar): create/remove the network properly
mdelapenya Sep 11, 2023
b5d3749
Merge branch 'main' into migrate-examples
mdelapenya Sep 11, 2023
0e28881
chore: better container logs on errors during startup
mdelapenya Sep 11, 2023
25adc7a
Revert "chore: better container logs on errors during startup"
mdelapenya Sep 11, 2023
2d91912
chore: better container logs on errors during startup
mdelapenya Sep 11, 2023
c8a8a7b
fix: do not wrap error but print it
mdelapenya Sep 11, 2023
1f64536
fix: avoid polluting default wait strategies in pulsar
mdelapenya Sep 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ci(lint): enable errorlint linter (#1604)
* ci(lint): enable errorlint linter

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>

* Apply suggestions from code review

Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>

---------

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Manuel de la Peña <social.mdelapenya@gmail.com>
  • Loading branch information
mmorel-35 and mdelapenya committed Sep 11, 2023
commit a85ac93842ae4b0c6c8e6735cb9ddbce393e0da6
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
linters:
enable:
- errorlint
- gci
- gocritic
- gofumpt
- misspell

linters-settings:
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors.
# See the https://github.com/polyfloyd/go-errorlint for caveats.
errorf: true
# Permit more than 1 %w verb, valid per Go 1.20 (Requires errorf:true)
errorf-multi: true
# Check for plain type assertions and type switches.
asserts: true
# Check for plain error comparisons.
comparison: true
gci:
sections:
- standard
Expand Down
6 changes: 4 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ func (p *DockerProvider) BuildImage(ctx context.Context, img ImageBuildInfo) (st
err = backoff.Retry(func() error {
resp, err = p.client.ImageBuild(ctx, buildContext, buildOptions)
if err != nil {
if _, ok := err.(errdefs.ErrNotFound); ok {
var enf errdefs.ErrNotFound
if errors.As(err, &enf) {
return backoff.Permanent(err)
}
Logger.Printf("Failed to build image: %s, will retry", err)
Expand Down Expand Up @@ -1161,7 +1162,8 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul
err = backoff.Retry(func() error {
pull, err = p.client.ImagePull(ctx, tag, pullOpt)
if err != nil {
if _, ok := err.(errdefs.ErrNotFound); ok {
var enf errdefs.ErrNotFound
if errors.As(err, &enf) {
return backoff.Permanent(err)
}
Logger.Printf("Failed to pull image: %s, will retry", err)
Expand Down
2 changes: 1 addition & 1 deletion internal/testcontainersdocker/docker_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func extractDockerHost(ctx context.Context) string {
for _, dockerHostFn := range dockerHostFns {
dockerHost, err := dockerHostFn(ctx)
if err != nil {
outerErr = fmt.Errorf("%w: %v", outerErr, err)
outerErr = fmt.Errorf("%w: %w", outerErr, err)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/testcontainersdocker/docker_rootless.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func rootlessDockerSocketPath(_ context.Context) (string, error) {
for _, socketPathFn := range socketPathFns {
s, err := socketPathFn()
if err != nil {
outerErr = fmt.Errorf("%w: %v", outerErr, err)
outerErr = fmt.Errorf("%w: %w", outerErr, err)
continue
}

Expand Down
10 changes: 6 additions & 4 deletions parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testcontainers

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -100,10 +101,10 @@ func TestParallelContainers(t *testing.T) {
res, err := ParallelContainers(context.Background(), tc.reqs, ParallelContainersOptions{})
if err != nil {
require.NotZero(t, tc.expErrors)
e, _ := err.(ParallelContainersError)

var e ParallelContainersError
errors.As(err, &e)
if len(e.Errors) != tc.expErrors {
t.Fatalf("expected erorrs: %d, got: %d\n", tc.expErrors, len(e.Errors))
t.Fatalf("expected errors: %d, got: %d\n", tc.expErrors, len(e.Errors))
}
}

Expand Down Expand Up @@ -157,7 +158,8 @@ func TestParallelContainersWithReuse(t *testing.T) {

res, err := ParallelContainers(ctx, parallelRequest, ParallelContainersOptions{})
if err != nil {
e, _ := err.(ParallelContainersError)
var e ParallelContainersError
errors.As(err, &e)
t.Fatalf("expected errors: %d, got: %d\n", 0, len(e.Errors))
}
// Container is reused, only terminate first container
Expand Down
7 changes: 5 additions & 2 deletions wait/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

package wait

import "syscall"
import (
"errors"
"syscall"
)

func isConnRefusedErr(err error) bool {
return err == syscall.ECONNREFUSED
return errors.Is(err, syscall.ECONNREFUSED)
}
2 changes: 1 addition & 1 deletion wait/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestExecStrategyWaitUntilReady_DeadlineExceeded(t *testing.T) {
}
wg := wait.NewExecStrategy([]string{"true"})
err := wg.WaitUntilReady(ctx, target)
if err != context.DeadlineExceeded {
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatal(err)
}
}
Expand Down
8 changes: 5 additions & 3 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT

select {
case <-ctx.Done():
return fmt.Errorf("%s:%w", ctx.Err(), err)
return fmt.Errorf("%w: %w", ctx.Err(), err)
case <-time.After(waitInterval):
if err := checkTarget(ctx, target); err != nil {
return err
Expand Down Expand Up @@ -155,8 +155,10 @@ func externalCheck(ctx context.Context, ipAddress string, port nat.Port, target
}
conn, err := dialer.DialContext(ctx, proto, address)
if err != nil {
if v, ok := err.(*net.OpError); ok {
if v2, ok := (v.Err).(*os.SyscallError); ok {
var v *net.OpError
if errors.As(err, &v) {
var v2 *os.SyscallError
if errors.As(v.Err, &v2) {
if isConnRefusedErr(v2.Err) {
time.Sleep(waitInterval)
continue
Expand Down
4 changes: 2 additions & 2 deletions wait/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
for err != nil {
select {
case <-ctx.Done():
return fmt.Errorf("%s:%w", ctx.Err(), err)
return fmt.Errorf("%w: %w", ctx.Err(), err)
case <-time.After(ws.PollInterval):
if err := checkTarget(ctx, target); err != nil {
return err
Expand All @@ -177,7 +177,7 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
for mappedPort == "" {
select {
case <-ctx.Done():
return fmt.Errorf("%s:%w", ctx.Err(), err)
return fmt.Errorf("%w: %w", ctx.Err(), err)
case <-time.After(ws.PollInterval):
if err := checkTarget(ctx, target); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions wait/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)
for port == "" {
select {
case <-ctx.Done():
return fmt.Errorf("%s:%w", ctx.Err(), err)
return fmt.Errorf("%w: %w", ctx.Err(), err)
case <-ticker.C:
if err := checkTarget(ctx, target); err != nil {
return err
Expand All @@ -98,7 +98,7 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)

db, err := sql.Open(w.Driver, w.URL(host, port))
if err != nil {
return fmt.Errorf("sql.Open: %v", err)
return fmt.Errorf("sql.Open: %w", err)
}
defer db.Close()
for {
Expand Down