mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
fix(backend): add more test coverage
This commit is contained in:
@@ -9,8 +9,9 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
assetfs "github.com/elazarl/go-bindata-assetfs"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
assetfs "github.com/elazarl/go-bindata-assetfs"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/prymitive/karma/internal/config"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type customizationAssetsTest struct {
|
||||
@@ -92,3 +95,46 @@ func TestStaticExpires404(t *testing.T) {
|
||||
t.Errorf("Got Expires: '%s' header on a 404 /static/ response", resp.Result().Header.Get("Expires"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadTemplateChained(t *testing.T) {
|
||||
var tmpl *template.Template
|
||||
tmpl = loadTemplate(tmpl, "ui/build/index.html")
|
||||
if tmpl == nil {
|
||||
t.Errorf("loadTemplate returned nil")
|
||||
}
|
||||
|
||||
tmpl = loadTemplate(tmpl, "ui/build/favicon.ico")
|
||||
if tmpl == nil {
|
||||
t.Errorf("loadTemplate returned nil")
|
||||
}
|
||||
|
||||
if tmpl.Name() != "ui/build/index.html" {
|
||||
t.Errorf("tmpl.Name() returned %q", tmpl.Name())
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadTemplateMissing(t *testing.T) {
|
||||
log.SetLevel(log.PanicLevel)
|
||||
defer func() { log.StandardLogger().ExitFunc = nil }()
|
||||
var wasFatal bool
|
||||
log.StandardLogger().ExitFunc = func(int) { wasFatal = true }
|
||||
|
||||
loadTemplate(nil, "/this/file/does/not/exist")
|
||||
|
||||
if !wasFatal {
|
||||
t.Error("loadTemplate() with invalid path didn't cause log.Fatal()")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadTemplateUnparsable(t *testing.T) {
|
||||
log.SetLevel(log.PanicLevel)
|
||||
defer func() { log.StandardLogger().ExitFunc = nil }()
|
||||
var wasFatal bool
|
||||
log.StandardLogger().ExitFunc = func(int) { wasFatal = true }
|
||||
|
||||
loadTemplate(nil, "ui/build/go-test-invalid.html")
|
||||
|
||||
if !wasFatal {
|
||||
t.Error("loadTemplate() with unparsable file didn't cause log.Fatal()")
|
||||
}
|
||||
}
|
||||
|
||||
1
ui/public/go-test-invalid.html
Normal file
1
ui/public/go-test-invalid.html
Normal file
@@ -0,0 +1 @@
|
||||
hello{{range
|
||||
Reference in New Issue
Block a user