Skip to content
Permalink
Browse files

Add template execute function test

  • Loading branch information...
Raggaer committed Jun 6, 2019
1 parent 9770c53 commit 6b7f975c65373d0f346edd5041ba4d0a5c27e071
@@ -0,0 +1,4 @@
local tpl = require('template')
tpl.render('execute.html', {
author = 'Raggaer'
})
@@ -0,0 +1 @@
return "Bison"
@@ -1,4 +1,4 @@
local tpl = require('template')
tpl.render('test.html', {
author = 'Raggaer'
})
})
@@ -32,6 +32,9 @@ local router = {
['/template/render'] = {
get = 'template/render.lua'
},
['/template/execute'] = {
get = 'template/execute.lua'
},
['/url/query_escape'] = {
get = 'url/query_escape.lua'
},
@@ -9,13 +9,13 @@ import (
"testing"
"time"

"github.com/buaazp/fasthttprouter"
"github.com/patrickmn/go-cache"
"github.com/Raggaer/bison/app/config"
"github.com/Raggaer/bison/app/controllers"
"github.com/Raggaer/bison/app/lua"
"github.com/Raggaer/bison/app/router"
"github.com/Raggaer/bison/app/template"
"github.com/buaazp/fasthttprouter"
cache "github.com/patrickmn/go-cache"
"github.com/valyala/fasthttp"
)

@@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"testing"
)

@@ -25,3 +26,23 @@ func TestTemplateRender(t *testing.T) {
t.Fatalf("Wrong template.render content. Expected '<p>Author: Raggaer</p>' but got '%s'", string(bodyContent))
}
}

// TestTemplateExecute test the template execute function
func TestTemplateExecute(t *testing.T) {
port := make(chan int, 1)
defer createTestServer(port, t).Close()
addr := <-port
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/template/execute", addr))
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
bodyContent, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
bodyStr := strings.TrimSpace(string(bodyContent))
if bodyStr != "<p>Framework: Bison</p><p>Author: Raggaer</p>" {
t.Fatalf("Wrong template.execute content. Expected '<p>Framework: Bison</p><p>Author: Raggaer</p>' but got '%s'", bodyStr)
}
}
@@ -0,0 +1 @@
<p>Framework: {{ execute "template/execute_tpl.lua" }}</p><p>Author: {{ .author }}</p>

0 comments on commit 6b7f975

Please sign in to comment.
You can’t perform that action at this time.