fix(backend): add more test coverage

This commit is contained in:
Łukasz Mierzwa
2020-02-10 18:59:53 +00:00
parent 55498fa73e
commit 89dbee85f8
3 changed files with 49 additions and 1 deletions

View File

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

View File

@@ -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()")
}
}

View File

@@ -0,0 +1 @@
hello{{range