1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-24 08:42:17 +02:00

Fix template does not exists panic

This commit is contained in:
Alireza Ahmadi 2017-03-13 09:01:18 +03:30
parent f5cbe61cc9
commit ea6cb83297
2 changed files with 7 additions and 1 deletions

View File

@ -74,7 +74,7 @@ func LoadTemplates(ab *authboss.Authboss, layout *template.Template, fpath strin
func (t Templates) Render(ctx *authboss.Context, w http.ResponseWriter, r *http.Request, name string, data authboss.HTMLData) error {
tpl, ok := t[name]
if !ok {
return authboss.RenderErr{TemplateName: tpl.Name(), Data: data, Err: ErrTemplateNotFound}
return authboss.RenderErr{TemplateName: name, Data: data, Err: ErrTemplateNotFound}
}
data.MergeKV(

View File

@ -75,6 +75,12 @@ func TestTemplates_Render(t *testing.T) {
"hello": testViewTemplate,
}
// Make sure that we will see an error when template does not exists
errTemplateNotFound := tpls.Render(ctx, w, r, "helloNotExists", authboss.HTMLData{"external": "there"})
if errTemplateNotFound == nil {
t.Error("Expected error when template does not exists")
}
err := tpls.Render(ctx, w, r, "hello", authboss.HTMLData{"external": "there"})
if err != nil {
t.Error(err)