Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'errcheck' linter warnings #2093

Merged
merged 2 commits into from Oct 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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