1package ooapi
2
3import (
4	"strings"
5	"testing"
6)
7
8func TestDefaultTemplateExecutorParseError(t *testing.T) {
9	te := &defaultTemplateExecutor{}
10	out, err := te.Execute("{{ .Foo", nil)
11	if err == nil || !strings.HasSuffix(err.Error(), "unclosed action") {
12		t.Fatal("not the error we expected", err)
13	}
14	if out != "" {
15		t.Fatal("expected empty string")
16	}
17}
18
19func TestDefaultTemplateExecutorExecError(t *testing.T) {
20	te := &defaultTemplateExecutor{}
21	arg := make(chan interface{})
22	out, err := te.Execute("{{ .Foo }}", arg)
23	if err == nil || !strings.Contains(err.Error(), `can't evaluate field Foo`) {
24		t.Fatal("not the error we expected", err)
25	}
26	if out != "" {
27		t.Fatal("expected empty string")
28	}
29}
30
31func TestDefaultGobCodecEncodeError(t *testing.T) {
32	codec := &defaultGobCodec{}
33	arg := make(chan interface{})
34	data, err := codec.Encode(arg)
35	if err == nil || !strings.Contains(err.Error(), "can't handle type") {
36		t.Fatal("not the error we expected", err)
37	}
38	if data != nil {
39		t.Fatal("expected nil data")
40	}
41}
42