-
Notifications
You must be signed in to change notification settings - Fork 6
/
chunk_test.go
65 lines (59 loc) · 1.88 KB
/
chunk_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 main
import (
"testing"
)
func ReadAllChunks(chunkSize int, channelDirectory string) [][]Message {
reader := NewChunkedHistoryReader(chunkSize, channelDirectory)
var chunks [][]Message
for c := reader.NextChunk(); len(c) > 0; c = reader.NextChunk() {
chunks = append(chunks, c)
}
return chunks
}
func ReadAllChunksAsInfo(chunkSize int, channelDirectory string) []ChunkInfo {
chunks := ReadAllChunks(chunkSize, channelDirectory)
chunkInfos := make([]ChunkInfo, 0, len(chunks))
for _, c := range chunks {
chunkInfos = append(chunkInfos, ToChunkInfo("channel1", c))
}
return chunkInfos
}
func TestChunkedHistoryReader(t *testing.T) {
actual := ReadAllChunks(4, "testdata/channel1")
expectedChunkSizes := []int{4, 2}
if len(expectedChunkSizes) != len(actual) {
t.Errorf("Wrong length: %d, %d", len(expectedChunkSizes), len(actual))
t.FailNow()
}
for i := 0; i < len(expectedChunkSizes); i++ {
if expectedChunkSizes[i] != len(actual[i]) {
t.Errorf("Wrong length: %d, %d", expectedChunkSizes[i], len(actual[i]))
t.FailNow()
}
}
first := actual[0][0]
if first.Text != "<@U00000001|alice> has joined the channel" {
t.Errorf("Wrong first message: %v", first.Text)
}
lastChunk := actual[len(actual)-1]
last := lastChunk[len(lastChunk)-1]
if last.Text != "Hello <@U00000002|bob>" {
t.Errorf("Wrong last message: %v", last.Text)
}
}
func TestToChunkInfo(t *testing.T) {
expectedMessageSizes := []int{3, 3}
expectedYear := 2016
actual := ReadAllChunksAsInfo(3, "testdata/channel1")
for i := 0; i < len(actual); i++ {
if actual[i].NumMessages != expectedMessageSizes[i] {
t.Errorf("Wrong number of messages: %v, %v", actual[i].NumMessages, expectedMessageSizes[i])
}
if actual[i].Start.Year() != expectedYear {
t.Errorf("Wrong start: %v", actual[i].Start)
}
if actual[i].End.Year() != expectedYear {
t.Errorf("Wrong end: %v", actual[i].Start)
}
}
}