Skip to content

Commit

Permalink
fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils committed Oct 30, 2023
1 parent 4cfe9e8 commit 005e389
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ linters:
- unparam
- unused
- varcheck
fast: false
fast: false
disable:
- paralleltest
13 changes: 9 additions & 4 deletions examples/api/healthcheck/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"net/http"
"os"
"time"
Expand All @@ -20,15 +21,19 @@ func getBaseURL() string {

func main() {
http.DefaultClient.Timeout = clientTimeout
ctx, cancel := context.WithTimeout(context.Background(), clientTimeout)
defer cancel()

r, err := http.DefaultClient.Get(getBaseURL())
req, err := http.NewRequestWithContext(ctx, http.MethodGet, getBaseURL(), nil)
if err != nil {
os.Exit(1)
}

defer func() { _ = r.Body.Close() }()
resp, err := http.DefaultClient.Do(req)

if r.StatusCode != http.StatusOK {
os.Exit(unhealthyExitCode)
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
defer os.Exit(unhealthyExitCode)
}
}
2 changes: 1 addition & 1 deletion examples/api/nameapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
var storage []string

func main() {
err := http.ListenAndServe("0.0.0.0:8080", http.HandlerFunc(
err := http.ListenAndServe("0.0.0.0:8080", http.HandlerFunc( //nolint:gosec
func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
Expand Down
22 changes: 14 additions & 8 deletions examples/api/tests/api_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"context"
"fmt"
"io"
"net/http"
Expand All @@ -15,7 +16,10 @@ const someName = "Kermit"
// see examples/api/main.go:60
func TestApi(t *testing.T) {
t.Logf("running tests against: %s", apiBaseURL())
resp, err := http.Get(apiBaseURL())
ctx := context.Background()
reqGET, err := http.NewRequestWithContext(ctx, http.MethodGet, apiBaseURL(), nil)
failOnError(t, err)
resp, err := http.DefaultClient.Do(reqGET)
failOnError(t, err)

defer func() {
Expand All @@ -32,29 +36,31 @@ func TestApi(t *testing.T) {
t.Fatalf("Did expect and empty result for get in the first call, but got: %v", string(content))
}

var req *http.Request
req, err = http.NewRequest("PUT", fmt.Sprintf("%s/%s", apiBaseURL(), someName), nil)
var reqPUT *http.Request
reqPUT, err = http.NewRequestWithContext(ctx, http.MethodPut, fmt.Sprintf("%s/%s", apiBaseURL(), someName), nil)
failOnError(t, err)

resp, err = http.DefaultClient.Do(req)
resp1, err := http.DefaultClient.Do(reqPUT)
failOnError(t, err)

defer func() {
err := resp.Body.Close()
err := resp1.Body.Close()
if err != nil {
t.Fatalf("Error closing response body: %v", err)
}
}()

expectedStatusCode := http.StatusOK
if resp.StatusCode != expectedStatusCode {
if resp1.StatusCode != expectedStatusCode {
t.Fatalf("Expected status code to be %v, but got: %v", expectedStatusCode, resp.StatusCode)
}

resp, err = http.Get(apiBaseURL())
reqGET2, err := http.NewRequestWithContext(ctx, http.MethodGet, apiBaseURL(), nil)
failOnError(t, err)
resp2, err := http.DefaultClient.Do(reqGET2)
failOnError(t, err)

content, err = io.ReadAll(resp.Body)
content, err = io.ReadAll(resp2.Body)
failOnError(t, err)

if string(content) != someName {
Expand Down
4 changes: 3 additions & 1 deletion wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func waitForContainerLog(ctx context.Context, search string, dockerClient *clien
return err
}

defer reader.Close()
defer func() {
_ = reader.Close()
}()

var (
buffer = strings.Builder{}
Expand Down

0 comments on commit 005e389

Please sign in to comment.