Skip to content

Commit

Permalink
Fix 'errcheck' linter warnings (#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkd authored and thinkerou committed Oct 27, 2019
1 parent 8a1bfcf commit 393a63f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
9 changes: 6 additions & 3 deletions binding/binding_test.go
Expand Up @@ -441,7 +441,8 @@ func createFormFilesMultipartRequest(t *testing.T) *http.Request {
defer f.Close()
fw, err1 := mw.CreateFormFile("file", "form.go")
assert.NoError(t, err1)
io.Copy(fw, f)
_, err = io.Copy(fw, f)
assert.NoError(t, err)

req, err2 := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", body)
assert.NoError(t, err2)
Expand All @@ -465,7 +466,8 @@ func createFormFilesMultipartRequestFail(t *testing.T) *http.Request {
defer f.Close()
fw, err1 := mw.CreateFormFile("file_foo", "form_foo.go")
assert.NoError(t, err1)
io.Copy(fw, f)
_, err = io.Copy(fw, f)
assert.NoError(t, err)

req, err2 := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", body)
assert.NoError(t, err2)
Expand Down Expand Up @@ -554,7 +556,8 @@ func TestBindingFormPostForMapFail(t *testing.T) {
func TestBindingFormFilesMultipart(t *testing.T) {
req := createFormFilesMultipartRequest(t)
var obj FooBarFileStruct
FormMultipart.Bind(req, &obj)
err := FormMultipart.Bind(req, &obj)
assert.NoError(t, err)

// file from os
f, _ := os.Open("form.go")
Expand Down
10 changes: 8 additions & 2 deletions binding/form_mapping_benchmark_test.go
Expand Up @@ -32,7 +32,10 @@ type structFull struct {
func BenchmarkMapFormFull(b *testing.B) {
var s structFull
for i := 0; i < b.N; i++ {
mapForm(&s, form)
err := mapForm(&s, form)
if err != nil {
b.Fatalf("Error on a form mapping")
}
}
b.StopTimer()

Expand All @@ -52,7 +55,10 @@ type structName struct {
func BenchmarkMapFormName(b *testing.B) {
var s structName
for i := 0; i < b.N; i++ {
mapForm(&s, form)
err := mapForm(&s, form)
if err != nil {
b.Fatalf("Error on a form mapping")
}
}
b.StopTimer()

Expand Down
5 changes: 4 additions & 1 deletion gin.go
Expand Up @@ -320,7 +320,10 @@ func (engine *Engine) RunUnix(file string) (err error) {
return
}
defer listener.Close()
os.Chmod(file, 0777)
err = os.Chmod(file, 0777)
if err != nil {
return
}
err = http.Serve(listener, engine)
return
}
Expand Down
4 changes: 3 additions & 1 deletion gin_integration_test.go
Expand Up @@ -90,7 +90,8 @@ func TestPusher(t *testing.T) {
go func() {
router.GET("/pusher", func(c *Context) {
if pusher := c.Writer.Pusher(); pusher != nil {
pusher.Push("/assets/app.js", nil)
err := pusher.Push("/assets/app.js", nil)
assert.NoError(t, err)
}
c.String(http.StatusOK, "it worked")
})
Expand Down Expand Up @@ -239,6 +240,7 @@ func TestBadListener(t *testing.T) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:10086")
assert.NoError(t, err)
listener, err := net.ListenTCP("tcp", addr)
assert.NoError(t, err)
listener.Close()
assert.Error(t, router.RunListener(listener))
}
Expand Down
5 changes: 4 additions & 1 deletion render/render_test.go
Expand Up @@ -347,7 +347,10 @@ func TestRenderRedirect(t *testing.T) {
}

w = httptest.NewRecorder()
assert.PanicsWithValue(t, "Cannot redirect with status code 200", func() { data2.Render(w) })
assert.PanicsWithValue(t, "Cannot redirect with status code 200", func() {
err := data2.Render(w)
assert.NoError(t, err)
})

data3 := Redirect{
Code: http.StatusCreated,
Expand Down

0 comments on commit 393a63f

Please sign in to comment.