Fix 'errcheck' linter warnings (#2093)

This commit is contained in:
Dmitry Kutakov 2019-10-27 06:58:59 +01:00 committed by thinkerou
parent 8a1bfcfd3b
commit 393a63f3b0
5 changed files with 25 additions and 8 deletions

View File

@ -441,7 +441,8 @@ func createFormFilesMultipartRequest(t *testing.T) *http.Request {
defer f.Close() defer f.Close()
fw, err1 := mw.CreateFormFile("file", "form.go") fw, err1 := mw.CreateFormFile("file", "form.go")
assert.NoError(t, err1) 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) req, err2 := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", body)
assert.NoError(t, err2) assert.NoError(t, err2)
@ -465,7 +466,8 @@ func createFormFilesMultipartRequestFail(t *testing.T) *http.Request {
defer f.Close() defer f.Close()
fw, err1 := mw.CreateFormFile("file_foo", "form_foo.go") fw, err1 := mw.CreateFormFile("file_foo", "form_foo.go")
assert.NoError(t, err1) 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) req, err2 := http.NewRequest("POST", "/?foo=getfoo&bar=getbar", body)
assert.NoError(t, err2) assert.NoError(t, err2)
@ -554,7 +556,8 @@ func TestBindingFormPostForMapFail(t *testing.T) {
func TestBindingFormFilesMultipart(t *testing.T) { func TestBindingFormFilesMultipart(t *testing.T) {
req := createFormFilesMultipartRequest(t) req := createFormFilesMultipartRequest(t)
var obj FooBarFileStruct var obj FooBarFileStruct
FormMultipart.Bind(req, &obj) err := FormMultipart.Bind(req, &obj)
assert.NoError(t, err)
// file from os // file from os
f, _ := os.Open("form.go") f, _ := os.Open("form.go")

View File

@ -32,7 +32,10 @@ type structFull struct {
func BenchmarkMapFormFull(b *testing.B) { func BenchmarkMapFormFull(b *testing.B) {
var s structFull var s structFull
for i := 0; i < b.N; i++ { 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() b.StopTimer()
@ -52,7 +55,10 @@ type structName struct {
func BenchmarkMapFormName(b *testing.B) { func BenchmarkMapFormName(b *testing.B) {
var s structName var s structName
for i := 0; i < b.N; i++ { 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() b.StopTimer()

5
gin.go
View File

@ -320,7 +320,10 @@ func (engine *Engine) RunUnix(file string) (err error) {
return return
} }
defer listener.Close() defer listener.Close()
os.Chmod(file, 0777) err = os.Chmod(file, 0777)
if err != nil {
return
}
err = http.Serve(listener, engine) err = http.Serve(listener, engine)
return return
} }

View File

@ -90,7 +90,8 @@ func TestPusher(t *testing.T) {
go func() { go func() {
router.GET("/pusher", func(c *Context) { router.GET("/pusher", func(c *Context) {
if pusher := c.Writer.Pusher(); pusher != nil { 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") c.String(http.StatusOK, "it worked")
}) })
@ -239,6 +240,7 @@ func TestBadListener(t *testing.T) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:10086") addr, err := net.ResolveTCPAddr("tcp", "localhost:10086")
assert.NoError(t, err) assert.NoError(t, err)
listener, err := net.ListenTCP("tcp", addr) listener, err := net.ListenTCP("tcp", addr)
assert.NoError(t, err)
listener.Close() listener.Close()
assert.Error(t, router.RunListener(listener)) assert.Error(t, router.RunListener(listener))
} }

View File

@ -347,7 +347,10 @@ func TestRenderRedirect(t *testing.T) {
} }
w = httptest.NewRecorder() 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{ data3 := Redirect{
Code: http.StatusCreated, Code: http.StatusCreated,