package tests import ( "git.virtual.blue/tomgracey/template-nest-go" "github.com/stretchr/testify/assert" "io/ioutil" "strings" "testing" ) func TestRenderWithJsExtension(t *testing.T) { ext := "js" nest, err := templatenest.New(templatenest.Option{ TemplateDir: "templates", TemplateExtension: &ext, }) if err != nil { t.Fatalf("Failed to initialize TemplateNest: %+v", err) } page := map[string]interface{}{ "TEMPLATE": "30-main", "var": "Simple Variable", } render := nest.MustRender(page) outputPath := "templates/output/06-main-template-extension.js" outputContents, err := ioutil.ReadFile(outputPath) if err != nil { t.Fatalf("error reading file (`%s`): %+v", outputPath, err) } assert.Equal( t, strings.TrimSpace(string(outputContents)), render, "Rendered output does not match expected output", ) } func TestRenderWithNoExtension(t *testing.T) { ext := "" nest, err := templatenest.New(templatenest.Option{ TemplateDir: "templates", TemplateExtension: &ext, }) if err != nil { t.Fatalf("Failed to initialize TemplateNest: %+v", err) } page := map[string]interface{}{ "TEMPLATE": "00-simple-page.html", "variable": "Simple Variable", "simple_component": []interface{}{ map[string]interface{}{ "TEMPLATE": "01-simple-component.html", "variable": "Simple Variable in Simple Component", }, }, } render := nest.MustRender(page) outputPath := "templates/output/01-simple-page.html" outputContents, err := ioutil.ReadFile(outputPath) if err != nil { t.Fatalf("error reading file (`%s`): %+v", outputPath, err) } assert.Equal( t, strings.TrimSpace(string(outputContents)), render, "Rendered output does not match expected output", ) }