-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming_errors_test.go
More file actions
74 lines (68 loc) · 1.94 KB
/
Copy pathstreaming_errors_test.go
File metadata and controls
74 lines (68 loc) · 1.94 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package gottp
import (
"errors"
"strings"
"testing"
)
func TestTemplateNotStreamableError_Is(t *testing.T) {
err := &TemplateNotStreamableError{Reasons: []string{"because reasons"}}
if !errors.Is(err, ErrTemplateNotStreamable) {
t.Errorf("errors.Is should match ErrTemplateNotStreamable")
}
}
func TestTemplateNotStreamableError_Message(t *testing.T) {
err := &TemplateNotStreamableError{Reasons: []string{"a", "b"}}
got := err.Error()
if !strings.Contains(got, "a") || !strings.Contains(got, "b") {
t.Errorf("error message %q should contain both reasons", got)
}
if !strings.Contains(got, ";") {
t.Errorf("error message %q should join reasons with semicolon", got)
}
}
func TestTemplateNotStreamableError_EmptyReasons(t *testing.T) {
err := &TemplateNotStreamableError{}
got := err.Error()
if got == "" {
t.Errorf("error message should not be empty even with no reasons")
}
}
func TestWhyNotStreamable_Streamable(t *testing.T) {
// Use a template that we know is streamable.
tmpl := `<group name="entry*">
mac {{ mac | _start_ }}
ip {{ ip }}
</group>`
c, err := CompileTemplate(tmpl)
if err != nil {
t.Fatalf("compile: %v", err)
}
streamable, reasons := WhyNotStreamable(c)
if !streamable {
t.Errorf("expected streamable=true, got false; reasons: %v", reasons)
}
if len(reasons) != 0 {
t.Errorf("expected no reasons when streamable, got: %v", reasons)
}
}
func TestWhyNotStreamable_NotStreamable(t *testing.T) {
// joinmatches makes it non-streamable.
tmpl := `<group name="entry*">
desc {{ desc | joinmatches }}
</group>`
c, err := CompileTemplate(tmpl)
if err != nil {
t.Fatalf("compile: %v", err)
}
streamable, reasons := WhyNotStreamable(c)
if streamable {
t.Errorf("expected streamable=false")
}
if len(reasons) == 0 {
t.Errorf("expected at least one reason")
}
joined := strings.Join(reasons, " ")
if !strings.Contains(joined, "joinmatches") {
t.Errorf("expected reason to mention joinmatches; got: %v", reasons)
}
}