Skip to content

Commit

Permalink
Add lint job in checks workflow (#5)
Browse files Browse the repository at this point in the history
* add linter job

* ignore errors in most lint issues
  • Loading branch information
rsjethani committed Aug 17, 2023
1 parent b30acab commit f81112a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ on:
- main

jobs:
# Reference: https://github.com/golangci/golangci-lint-action
golangci-lint:
name: linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.19'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3

go-test:
name: testing
strategy:
Expand Down
4 changes: 3 additions & 1 deletion sling.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ func (s *Sling) Do(req *http.Request, successV, failureV interface{}) (*http.Res
// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
// not read to completion and closed.
// See: https://golang.org/pkg/net/http/#Response
defer io.Copy(io.Discard, resp.Body)
defer func() {
_, _ = io.Copy(io.Discard, resp.Body)
}()

// Don't try to decode on 204s or Content-Length is 0
if resp.StatusCode == http.StatusNoContent || resp.ContentLength == 0 {
Expand Down
14 changes: 8 additions & 6 deletions sling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func TestRequest_body(t *testing.T) {
for _, c := range cases {
req, _ := c.sling.Request()
buf := new(bytes.Buffer)
buf.ReadFrom(req.Body)
_, _ = buf.ReadFrom(req.Body)
// req.Body should have contained the expectedBody string
if value := buf.String(); value != c.expectedBody {
t.Errorf("expected Request.Body %s, got %s", c.expectedBody, value)
Expand Down Expand Up @@ -622,7 +622,7 @@ func TestAddQueryStructs(t *testing.T) {
}
for _, c := range cases {
reqURL, _ := url.Parse(c.rawurl)
addQueryStructs(reqURL, c.queryStructs)
_ = addQueryStructs(reqURL, c.queryStructs)
if reqURL.String() != c.expected {
t.Errorf("expected %s, got %s", c.expected, reqURL.String())
}
Expand Down Expand Up @@ -820,7 +820,7 @@ func TestReceive_success_nonDefaultDecoder(t *testing.T) {

mux.HandleFunc("/foo/file", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/octet-stream")
w.Write(expectedData)
_, _ = w.Write(expectedData)
})

endpoint := New().Client(client).Base("http://example.com/").Path("foo/").Get("file")
Expand Down Expand Up @@ -1011,7 +1011,9 @@ func TestReuseTcpConnections(t *testing.T) {
},
}

go server.Serve(ln)
go func() {
_ = server.Serve(ln)
}()

endpoint := New().Client(http.DefaultClient).Base(rawURL).Path("foo/").Get("get")

Expand All @@ -1025,7 +1027,7 @@ func TestReuseTcpConnections(t *testing.T) {
}
}

server.Shutdown(context.Background())
_ = server.Shutdown(context.Background())

if count := atomic.LoadInt32(&connCount); count != 1 {
t.Errorf("expected 1, got %v", count)
Expand Down Expand Up @@ -1070,7 +1072,7 @@ func assertQuery(t *testing.T, expected map[string]string, req *http.Request) {
// assertPostForm tests that the Request has the expected key values pairs url
// encoded in its Body
func assertPostForm(t *testing.T, expected map[string]string, req *http.Request) {
req.ParseForm() // parses request Body to put url.Values in r.Form/r.PostForm
_ = req.ParseForm() // parses request Body to put url.Values in r.Form/r.PostForm
expectedValues := url.Values{}
for key, value := range expected {
expectedValues.Add(key, value)
Expand Down

0 comments on commit f81112a

Please sign in to comment.