fix errcheck warnings (#1739)
This commit is contained in:
committed by
thinkerou
parent
29a145c85d
commit
b056a34bdc
+10
-9
@@ -32,7 +32,7 @@ func TestIsDebugging(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrint(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
SetMode(ReleaseMode)
|
||||
debugPrint("DEBUG this!")
|
||||
@@ -46,7 +46,7 @@ func TestDebugPrint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintError(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintError(nil)
|
||||
debugPrintError(errors.New("this is an error"))
|
||||
@@ -56,7 +56,7 @@ func TestDebugPrintError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintRoutes(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintRoute("GET", "/path/to/route/:param", HandlersChain{func(c *Context) {}, handlerNameTest})
|
||||
SetMode(TestMode)
|
||||
@@ -65,7 +65,7 @@ func TestDebugPrintRoutes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintLoadTemplate(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
templ := template.Must(template.New("").Delims("{[{", "}]}").ParseGlob("./testdata/template/hello.tmpl"))
|
||||
debugPrintLoadTemplate(templ)
|
||||
@@ -75,7 +75,7 @@ func TestDebugPrintLoadTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintWARNINGSetHTMLTemplate(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintWARNINGSetHTMLTemplate()
|
||||
SetMode(TestMode)
|
||||
@@ -84,7 +84,7 @@ func TestDebugPrintWARNINGSetHTMLTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintWARNINGDefault(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintWARNINGDefault()
|
||||
SetMode(TestMode)
|
||||
@@ -98,7 +98,7 @@ func TestDebugPrintWARNINGDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDebugPrintWARNINGNew(t *testing.T) {
|
||||
re := captureOutput(func() {
|
||||
re := captureOutput(t, func() {
|
||||
SetMode(DebugMode)
|
||||
debugPrintWARNINGNew()
|
||||
SetMode(TestMode)
|
||||
@@ -106,7 +106,7 @@ func TestDebugPrintWARNINGNew(t *testing.T) {
|
||||
assert.Equal(t, "[GIN-debug] [WARNING] Running in \"debug\" mode. Switch to \"release\" mode in production.\n - using env:\texport GIN_MODE=release\n - using code:\tgin.SetMode(gin.ReleaseMode)\n\n", re)
|
||||
}
|
||||
|
||||
func captureOutput(f func()) string {
|
||||
func captureOutput(t *testing.T, f func()) string {
|
||||
reader, writer, err := os.Pipe()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -127,7 +127,8 @@ func captureOutput(f func()) string {
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
wg.Done()
|
||||
io.Copy(&buf, reader)
|
||||
_, err := io.Copy(&buf, reader)
|
||||
assert.NoError(t, err)
|
||||
out <- buf.String()
|
||||
}()
|
||||
wg.Wait()
|
||||
|
||||
Reference in New Issue
Block a user