-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparakeet_test.go
112 lines (96 loc) · 3.07 KB
/
parakeet_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
import (
"strings"
"testing"
)
const file = `
[2021-03-01T10:29:59.215Z] *** creekorful (~creekorfu@static.8.8.8.8.clients.example.org) joined
[2021-03-01T10:29:59.215Z] *** hentiphase (~hentiphase@static.4.4.4.4.clients.example.org) joined
[2021-03-01T11:59:42.847Z] *** creekorful changed nick to creekorful_
[2021-03-01T11:59:43.847Z] *** creekorful_ changed nick to creekorful
[2021-03-01T12:00:43.164Z] *** hentiphase (~hentiphase@static.4.4.4.4.clients.example.org) quit (Ping timeout: 480 seconds)
[2021-03-01T13:00:59.215Z] *** hentiphase (~hentiphase@static.4.4.4.4.clients.example.org) joined
[2021-03-01T13:25:17.928Z] <hentiphase> creekorful: when in doubt, take it to mail. -> unblock
[2021-03-01T13:37:14.974Z] <creekorful> thanks for your feedback :)
[2021-03-01T13:59:00.732Z] <hentiphase> creekorful: https://example.org/manual :)
[2021-03-01T20:38:26.113Z] *** creekorful (~creekorfu@static.8.8.8.8.clients.example.org) quit ()
[2021-03-01T21:24:49.669Z] *** hentiphase (~hentiphase@static.4.4.4.4.clients.example.org) quit (Remote host closed the connection)
[2021-03-23T10:29:59.215Z] *** creekorful (~creekorfu@static.8.8.8.8.clients.example.org) joined
[2021-03-23T10:46:21.525Z] * creekorful sent a long message: < something >
`
func TestParseLog(t *testing.T) {
ch, err := parseLog("#test-channel", strings.NewReader(file))
if err != nil {
t.Fatal(err)
}
if ch.Name != "#test-channel" {
t.Fail()
}
if len(ch.Messages) != 3 {
t.Fail()
}
msg := ch.Messages[0]
if msg.Sender != "hentiphase" {
t.Fail()
}
if msg.Content != "creekorful: when in doubt, take it to mail. -> unblock" {
t.Fail()
}
msg = ch.Messages[1]
if msg.Sender != "creekorful" {
t.Fail()
}
if msg.Content != "thanks for your feedback :)" {
t.Fail()
}
msg = ch.Messages[2]
if msg.Sender != "hentiphase" {
t.Fail()
}
if msg.Content != "creekorful: <a href=\"https://example.org/manual\">https://example.org/manual</a> :)" {
t.Fail()
}
}
func TestGenerateHTML(t *testing.T) {
w := &strings.Builder{}
ch, err := parseLog("#test-channel", strings.NewReader(file))
if err != nil {
t.Fatal(err)
}
if err := generateHTML(ch, w); err != nil {
t.Fatal(err)
}
val := w.String()
if !strings.Contains(val, "<title>#test-channel</title>") {
t.Fail()
}
if !strings.Contains(val, "; font-weight: bold;\">creekorful</span>>") {
t.Fail()
}
if !strings.Contains(val, "; font-weight: bold;\">hentiphase</span>>") {
t.Fail()
}
}
func BenchmarkGenerateHTML(b *testing.B) {
w := &strings.Builder{}
for n := 0; n < b.N; n++ {
ch, err := parseLog("#test-channel", strings.NewReader(file))
if err != nil {
b.Fatal(err)
}
if err := generateHTML(ch, w); err != nil {
b.Fatal(err)
}
}
}
func TestTrimSuffixes(t *testing.T) {
if val := trimSuffixes("#test-channel.txt", []string{".txt", ".log"}); val != "#test-channel" {
t.Fail()
}
if val := trimSuffixes("#test-channel.log", []string{".txt", ".log"}); val != "#test-channel" {
t.Fail()
}
if val := trimSuffixes("#test-channel.bin", []string{".txt", ".log"}); val != "#test-channel.bin" {
t.Fail()
}
}