Browse Source

Improve debug code coverage (#963)

* Improve debug.go code coverage

* lint code
Eason Lin 8 years ago
parent
commit
76a63b257d
1 changed files with 20 additions and 0 deletions
  1. 20 0
      debug_test.go

+ 20 - 0
debug_test.go

@@ -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)