Improve debug code coverage (#963)

* Improve debug.go code coverage

* lint code
This commit is contained in:
Eason Lin 2017-07-02 15:29:29 +08:00 committed by Bo-Yi Wu
parent 470fe62637
commit 76a63b257d
1 changed files with 20 additions and 0 deletions

View File

@ -7,6 +7,7 @@ package gin
import (
"bytes"
"errors"
"html/template"
"io"
"log"
"os"
@ -66,6 +67,25 @@ func TestDebugPrintRoutes(t *testing.T) {
assert.Regexp(t, `^\[GIN-debug\] GET /path/to/route/:param --> (.*/vendor/)?github.com/gin-gonic/gin.handlerNameTest \(2 handlers\)\n$`, w.String())
}
func TestDebugPrintLoadTemplate(t *testing.T) {
var w bytes.Buffer
setup(&w)
defer teardown()
templ := template.Must(template.New("").Delims("{[{", "}]}").ParseGlob("./fixtures/basic/*"))
debugPrintLoadTemplate(templ)
assert.Equal(t, w.String(), "[GIN-debug] Loaded HTML Templates (2): \n\t- \n\t- hello.tmpl\n\n")
}
func TestDebugPrintWARNINGSetHTMLTemplate(t *testing.T) {
var w bytes.Buffer
setup(&w)
defer teardown()
debugPrintWARNINGSetHTMLTemplate()
assert.Equal(t, w.String(), "[GIN-debug] [WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called\nat initialization. ie. before any route is registered or the router is listening in a socket:\n\n\trouter := gin.Default()\n\trouter.SetHTMLTemplate(template) // << good place\n\n")
}
func setup(w io.Writer) {
SetMode(DebugMode)
log.SetOutput(w)