-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash_test.go
70 lines (58 loc) · 1.58 KB
/
flash_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package contour_test
import (
"bytes"
"testing"
)
func TestRenderWithFlash(t *testing.T) {
engine, err := makeFSEngine()
if err != nil {
t.Fatalf("load: %v\n", err)
}
defer func() {
if len(engine.Flashes.Get("info")) > 0 {
t.Fatalf("success flash messages did not clear out")
}
}()
engine.Flashes.Push("File has been saved")
var buf bytes.Buffer
engine.Render(&buf, "flash", map[string]interface{}{
"Title": "Hello, Bob!",
})
expect := `<div class="alert">File has been saved</div>`
result := trim(buf.String())
if expect != result {
t.Fatalf("Expected:\n%s\nResult:\n%s\n", expect, result)
}
buf.Reset()
engine.Flashes.Push("Processing failed")
engine.Render(&buf, "flash", map[string]interface{}{
"Title": "Hello, Bob!",
})
expect = `<div class="alert">Processing failed</div>`
result = trim(buf.String())
if expect != result {
t.Fatalf("Expected:\n%s\nResult:\n%s\n", expect, result)
}
}
func TestRenderWithAllFlash(t *testing.T) {
engine, err := makeFSEngine()
if err != nil {
t.Fatalf("load: %v\n", err)
}
defer func() {
if len(engine.Flashes.All()) > 0 {
t.Fatalf("flash messages did not clear out")
}
}()
engine.Flashes.PushTo("success", "File has been saved")
engine.Flashes.PushTo("error", "Processing failed")
var buf bytes.Buffer
engine.Render(&buf, "flash-all", map[string]interface{}{
"Title": "Hello, Bob!",
})
expect := `<div class="alert">File has been saved</div><div class="alert">Processing failed</div>`
result := trim(buf.String())
if expect != result {
t.Fatalf("Expected:\n%s\nResult:\n%s\n", expect, result)
}
}