Skip to content

Commit

Permalink
ci: enable rowserrcheck and bodyclose linters (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored Sep 28, 2021
1 parent 6425c74 commit 7e5ce44
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
version: v1.36.0
version: v1.42.0
args: --verbose
- run: git diff --exit-code

Expand Down
6 changes: 2 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ run:
- test
linters:
enable:
# TODO
# - bodyclose
- bodyclose
- deadcode
- errcheck
# only minor issues
Expand All @@ -21,8 +20,7 @@ linters:
- govet
- ineffassign
- misspell
# TODO
# - rowserrcheck
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
Expand Down
20 changes: 16 additions & 4 deletions runner/sidecar/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -135,9 +136,13 @@ func waitReady(ctx context.Context) error {
}
}
logger.Info("waiting for HTTP in interface to be ready")
if resp, err := httpClient.Get("http://127.0.0.1:8080/ready"); err == nil && resp.StatusCode < 300 {
logger.Info("HTTP in interface ready")
return nil
if resp, err := httpClient.Get("http://127.0.0.1:8080/ready"); err == nil {
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
if resp.StatusCode < 300 {
logger.Info("HTTP in interface ready")
return nil
}
}
time.Sleep(1 * time.Second)
}
Expand All @@ -151,9 +156,16 @@ func waitUnready(ctx context.Context) error {
return fmt.Errorf("failed to wait for un-ready: %w", ctx.Err())
default:
logger.Info("waiting for HTTP in interface to be unready")
if resp, err := httpClient.Get("http://127.0.0.1:8080/ready"); err != nil || resp.StatusCode >= 300 {
if resp, err := httpClient.Get("http://127.0.0.1:8080/ready"); err != nil {
logger.Info("HTTP in interface unready")
return nil
} else {
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
if resp.StatusCode >= 300 {
logger.Info("HTTP in interface unready")
return nil
}
}
time.Sleep(1 * time.Second)
}
Expand Down
3 changes: 3 additions & 0 deletions runner/sidecar/source/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func queryData(ctx context.Context, db *sql.DB, sourceURN, query, offsetColumn,
return fmt.Errorf("failed to execute sql query: %w", err)
}
defer func() { _ = rows.Close() }()
if rows.Err() != nil {
return fmt.Errorf("failed to execute sql query: %w", rows.Err())
}

columns, err := rows.Columns()
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions runner/sidecar/source/loadbalanced/loadbalanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ func New(ctx context.Context, secretInterface corev1.SecretInterface, r NewReq)
endpoint := "https://" + r.PipelineName + "-" + r.StepName + "/ready"
logger.Info("waiting for HTTP service to be ready", "endpoint", endpoint)
resp, err := httpClient.Get(endpoint)
if err == nil && resp.StatusCode < 300 {
break OUTER
if err == nil {
_ = resp.Body.Close()
if resp.StatusCode < 300 {
break OUTER
}
}
time.Sleep(3 * time.Second)
}
Expand Down
1 change: 1 addition & 0 deletions test/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func SendMessageViaHTTP(msg string) {
panic(err)
} else {
body, _ := ioutil.ReadAll(resp.Body)
_ = resp.Body.Close()
if resp.StatusCode != 204 {
panic(fmt.Errorf("%s: %q", resp.Status, body))
}
Expand Down
11 changes: 6 additions & 5 deletions test/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@ import (
func InvokeTestAPI(format string, args ...interface{}) string {
url := "http://localhost:8378" + fmt.Sprintf(format, args...)
log.Printf("GET %s\n", url)
r, err := http.Get(url)
resp, err := http.Get(url)
if err != nil {
panic(err)
}
log.Printf("> %s\n", r.Status)
log.Printf("> %s\n", resp.Status)
body := ""
for s := bufio.NewScanner(r.Body); s.Scan(); {
defer resp.Body.Close()
for s := bufio.NewScanner(resp.Body); s.Scan(); {
x := s.Text()
if strings.Contains(x, "ERROR") { // hacky way to return an error from an octet-stream
panic(errors.New(x))
}
log.Printf("> %s\n", x)
body += x
}
if r.StatusCode >= 300 {
panic(errors.New(r.Status))
if resp.StatusCode >= 300 {
panic(errors.New(resp.Status))
}
return body
}
4 changes: 3 additions & 1 deletion testapi/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ func init() {
url := r.URL.Query().Get("url")
w.WriteHeader(200)
for {
if _, err := httpClient.Get(url); err != nil {
if resp, err := httpClient.Get(url); err != nil {
_, _ = fmt.Fprintf(w, "%q is not ready: %v\n", url, err)
} else {
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
return
}
time.Sleep(1 * time.Second)
Expand Down

0 comments on commit 7e5ce44

Please sign in to comment.