-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.go
50 lines (39 loc) · 1.1 KB
/
template_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package embdr_test
import (
"io/ioutil"
"log"
"os"
"testing"
"text/template"
"github.com/heppu/embdr"
)
func TestTemplate(t *testing.T) {
filename := "template.tmpl"
expected, err := ioutil.ReadFile(filename)
noErrorf(t, err, "failed to read %s", filename)
got, err := embdr.Load(filename)
noErrorf(t, err, "failed get template for %s", filename)
isTruef(t, string(expected) == got, "content of file %s doesn't match stored data", filename)
}
func TestTemplateNotFound(t *testing.T) {
_, err := embdr.Load("foo")
isTruef(t, err == embdr.ErrTemplateDoesNotExist, "expected 'embdr.ErrTemplateDoesNotExist' error, got '%s'", err)
}
func ExampleTemplate() {
const name = "template.tmpl"
tmpl, err := embdr.Load(name)
if err != nil {
log.Fatalf("Couldn't get template with name: %s", err)
}
t, err := template.New(name).Parse(tmpl)
if err != nil {
log.Fatalf("Couldn't load internal templates: %s", err)
}
type GenParams struct {
Package string
Templates map[string]string
}
if err := t.Execute(os.Stdout, GenParams{}); err != nil {
log.Fatalf("Couldn't generate output: %s", err)
}
}