-
Notifications
You must be signed in to change notification settings - Fork 0
/
resume_test.go
65 lines (56 loc) · 1.59 KB
/
resume_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
package resume_test
import (
"bytes"
"flag"
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/shurcooL/htmlg"
"github.com/shurcooL/reactions"
"github.com/shurcooL/resume"
"github.com/shurcooL/users"
)
var updateFlag = flag.Bool("update", false, "Update golden files.")
// TestDmitriShuralyov validates that rendering resume.DmitriShuralyov produces expected HTML.
func TestDmitriShuralyov(t *testing.T) {
var (
dmitshur = users.User{
UserSpec: users.UserSpec{ID: 1924134, Domain: "github.com"},
Name: "Dmitri Shuralyov",
Email: "dmitri@shuralyov.com",
}
mockTime = time.Date(2018, time.August, 26, 9, 41, 0, 0, time.UTC)
alice = users.User{UserSpec: users.UserSpec{ID: 1, Domain: "example.org"}, Login: "Alice"}
bob = users.User{UserSpec: users.UserSpec{ID: 2, Domain: "example.org"}, Login: "Bob"}
mockReactions = map[string][]reactions.Reaction{
"Go": {{
Reaction: "smile",
Users: []users.User{alice, bob},
}, {
Reaction: "balloon",
Users: []users.User{bob},
}},
}
)
var buf bytes.Buffer
err := htmlg.RenderComponents(&buf, resume.DmitriShuralyov(dmitshur, mockTime, mockReactions, alice))
if err != nil {
t.Fatal(err)
}
got := buf.Bytes()
if *updateFlag {
err := ioutil.WriteFile(filepath.Join("testdata", "resume.html"), got, 0644)
if err != nil {
t.Fatal(err)
}
return
}
want, err := ioutil.ReadFile(filepath.Join("testdata", "resume.html"))
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(got, want) {
t.Error("rendering resume.DmitriShuralyov produced HTML that doesn't match 'testdata/resume.html'")
}
}