-
Notifications
You must be signed in to change notification settings - Fork 3
/
statistics_test.go
67 lines (51 loc) · 1.46 KB
/
statistics_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
package main
import (
"strings"
"testing"
)
func Test_getLatestLogMessages_NoMessagesGiven_EmptyArrayIsReturned(t *testing.T) {
messages := []string{}
result, _ := getLatestLogMessages(messages, 3)
if len(result) != 3 {
t.Fail()
t.Logf("getLatestLogMessages([...], 3) should have returned and array of size 3")
}
if result[0] != "" {
t.Fail()
t.Logf("getLatestLogMessages([\"%s\"], 3) returned %q instead of %q", strings.Join(messages, "\",\""), result[0], "")
}
}
func Test_getLatestLogMessages_RequestedCountEqualsNumberOfMessages(t *testing.T) {
messages := []string{
"Line 1",
"Line 2",
"Line 3",
}
result, _ := getLatestLogMessages(messages, 3)
if len(result) != 3 {
t.Fail()
t.Logf("getLatestLogMessages([...], 3) should have returned and array of size 3")
}
if result[2] != "Line 3" {
t.Fail()
t.Logf("getLatestLogMessages([\"%s\"], 3) returned %q instead of %q", strings.Join(messages, "\",\""), result[0], "Line 3")
}
}
func Test_getLatestLogMessages_RequestedCountIsSmallerThanNumberOfMessages(t *testing.T) {
messages := []string{
"Line 1",
"Line 2",
"Line 3",
"Line 4",
"Line 5",
}
result, _ := getLatestLogMessages(messages, 3)
if len(result) != 3 {
t.Fail()
t.Logf("getLatestLogMessages([...], 3) should have returned and array of size 3")
}
if result[0] != "Line 3" {
t.Fail()
t.Logf("getLatestLogMessages([\"%s\"], 3) returned %q instead of %q", strings.Join(messages, "\",\""), result[0], "Line 3")
}
}