forked from mirror/gin
Improve debug code coverage (#963)
* Improve debug.go code coverage * lint code
This commit is contained in:
parent
470fe62637
commit
76a63b257d
|
@ -7,6 +7,7 @@ package gin
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"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())
|
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) {
|
func setup(w io.Writer) {
|
||||||
SetMode(DebugMode)
|
SetMode(DebugMode)
|
||||||
log.SetOutput(w)
|
log.SetOutput(w)
|
||||||
|
|
Loading…
Reference in New Issue