Skip to content

Commit

Permalink
lint: enable nonamedreturns
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 9, 2023
1 parent 555cb76 commit 4d6e816
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 32 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
- gocritic
- gofumpt
- misspell
- nonamedreturns

linters-settings:
errorlint:
Expand Down
4 changes: 2 additions & 2 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,8 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul

// Health measure the healthiness of the provider. Right now we leverage the
// docker-client Info endpoint to see if the daemon is reachable.
func (p *DockerProvider) Health(ctx context.Context) (err error) {
_, err = p.client.Info(ctx)
func (p *DockerProvider) Health(ctx context.Context) error {
_, err := p.client.Info(ctx)
defer p.Close()

return err
Expand Down
2 changes: 1 addition & 1 deletion modules/kafka/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type TestKafkaConsumer struct {
message *sarama.ConsumerMessage
}

func NewTestKafkaConsumer(t *testing.T) (consumer *TestKafkaConsumer, ready <-chan bool, done <-chan bool, cancel func()) {
func NewTestKafkaConsumer(t *testing.T) (*TestKafkaConsumer, <-chan bool, <-chan bool, func()) {
kc := &TestKafkaConsumer{
t: t,
ready: make(chan bool, 1),
Expand Down
25 changes: 9 additions & 16 deletions modules/localstack/localstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ func StartContainer(ctx context.Context, overrideReq OverrideContainerRequestOpt
return RunContainer(ctx, overrideReq)
}

func configureDockerHost(req *LocalStackContainerRequest, envVar string) (reason string, err error) {
err = nil
reason = ""
func configureDockerHost(req *LocalStackContainerRequest, envVar string) (string, error) {
reason := ""

if _, ok := req.Env[envVar]; ok {
reason = "explicitly as environment variable"
return
return "explicitly as environment variable", nil
}

// if the container is not connected to the default network, use the last network alias in the first network
Expand All @@ -141,25 +139,20 @@ func configureDockerHost(req *LocalStackContainerRequest, envVar string) (reason
alias := req.NetworkAliases[req.Networks[0]][len(req.NetworkAliases[req.Networks[0]])-1]

req.Env[envVar] = alias
reason = "to match last network alias on container with non-default network"
return
return "to match last network alias on container with non-default network", nil
}

var dockerProvider *testcontainers.DockerProvider
dockerProvider, err = testcontainers.NewDockerProvider()
dockerProvider, err := testcontainers.NewDockerProvider()
if err != nil {
return
return reason, err
}
defer dockerProvider.Close()

var daemonHost string
daemonHost, err = dockerProvider.DaemonHost(context.Background())
daemonHost, err := dockerProvider.DaemonHost(context.Background())
if err != nil {
return
return reason, err
}

req.Env[envVar] = daemonHost
reason = "to match host-routable address for container"

return
return "to match host-routable address for container", nil
}
2 changes: 1 addition & 1 deletion wait/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (ws *ExitStrategy) Timeout() *time.Duration {
}

// WaitUntilReady implements Strategy.WaitUntilReady
func (ws *ExitStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (ws *ExitStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
if ws.timeout != nil {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, *ws.timeout)
Expand Down
2 changes: 1 addition & 1 deletion wait/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (ws *HealthStrategy) Timeout() *time.Duration {
}

// WaitUntilReady implements Strategy.WaitUntilReady
func (ws *HealthStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (ws *HealthStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
timeout := defaultStartupTimeout()
if ws.timeout != nil {
timeout = *ws.timeout
Expand Down
9 changes: 4 additions & 5 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (hp *HostPortStrategy) Timeout() *time.Duration {
}

// WaitUntilReady implements Strategy.WaitUntilReady
func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
timeout := defaultStartupTimeout()
if hp.timeout != nil {
timeout = *hp.timeout
Expand All @@ -82,7 +82,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT

ipAddress, err := target.Host(ctx)
if err != nil {
return
return err
}

waitInterval := hp.PollInterval
Expand All @@ -92,7 +92,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
var ports nat.PortMap
ports, err = target.Ports(ctx)
if err != nil {
return
return err
}
if len(ports) > 0 {
for p := range ports {
Expand All @@ -103,8 +103,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
}

if internalPort == "" {
err = fmt.Errorf("no port to wait for")
return
return fmt.Errorf("no port to wait for")
}

var port nat.Port
Expand Down
6 changes: 3 additions & 3 deletions wait/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (ws *HTTPStrategy) Timeout() *time.Duration {
}

// WaitUntilReady implements Strategy.WaitUntilReady
func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
timeout := defaultStartupTimeout()
if ws.timeout != nil {
timeout = *ws.timeout
Expand All @@ -141,7 +141,7 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge

ipAddress, err := target.Host(ctx)
if err != nil {
return
return err
}

var mappedPort nat.Port
Expand Down Expand Up @@ -252,7 +252,7 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
if ws.Body != nil {
body, err = io.ReadAll(ws.Body)
if err != nil {
return
return err
}
}

Expand Down
2 changes: 1 addition & 1 deletion wait/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (ws *LogStrategy) Timeout() *time.Duration {
}

// WaitUntilReady implements Strategy.WaitUntilReady
func (ws *LogStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (ws *LogStrategy) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
timeout := defaultStartupTimeout()
if ws.timeout != nil {
timeout = *ws.timeout
Expand Down
4 changes: 2 additions & 2 deletions wait/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (w *waitForSql) Timeout() *time.Duration {
// WaitUntilReady repeatedly tries to run "SELECT 1" or user defined query on the given port using sql and driver.
//
// If it doesn't succeed until the timeout value which defaults to 60 seconds, it will return an error.
func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget) (err error) {
func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget) error {
timeout := defaultStartupTimeout()
if w.timeout != nil {
timeout = *w.timeout
Expand All @@ -75,7 +75,7 @@ func (w *waitForSql) WaitUntilReady(ctx context.Context, target StrategyTarget)

host, err := target.Host(ctx)
if err != nil {
return
return err
}

ticker := time.NewTicker(w.PollInterval)
Expand Down

0 comments on commit 4d6e816

Please sign in to comment.