-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_test.go
79 lines (70 loc) · 2.38 KB
/
main_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
package main
import (
"strings"
"testing"
)
func TestTrimForDisplay(t *testing.T) {
entries := &entries{
Entries: []entry{
{},
{},
{},
},
}
_, err := entries.trimForDisplay(1, 2, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err == nil {
t.Fatal("expected error, got none")
}
if !strings.Contains(err.Error(), "internal inconsistency") {
t.Errorf("expected internal inconsistency error, got %s", err)
}
_, err = entries.trimForDisplay(999, 1000, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err == nil {
t.Fatal("expected error, got none")
}
if !strings.Contains(err.Error(), "internal inconsistency") {
t.Errorf("expected internal inconsistency error, got %s", err)
}
_, err = entries.trimForDisplay(1000, 1000, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err == nil {
t.Fatal("expected error, got none")
}
if !strings.Contains(err.Error(), "internal inconsistency") {
t.Errorf("expected internal inconsistency error, got %s", err)
}
_, err = entries.trimForDisplay(10, 20, tile{start: 10, end: 12, size: 2, logURL: "http://example.com"})
if err == nil {
t.Fatal("expected error, got none")
}
if !strings.Contains(err.Error(), "internal inconsistency") {
t.Errorf("expected internal inconsistency error, got %s", err)
}
_, err = entries.trimForDisplay(15, 20, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err == nil {
t.Fatal("expected error, got none")
}
if !strings.Contains(err.Error(), "past the end of the log") {
t.Errorf("expected 'past the end of the log' error, got %s", err)
}
e, err := entries.trimForDisplay(10, 20, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err != nil {
t.Fatalf("expected success, got %s", err)
}
if len(e.Entries) != 3 {
t.Errorf("expected 3 entries got %d", len(entries.Entries))
}
e, err = entries.trimForDisplay(11, 12, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err != nil {
t.Fatalf("expected success, got %s", err)
}
if len(e.Entries) != 1 {
t.Errorf("expected 1 entry got %d", len(entries.Entries))
}
e, err = entries.trimForDisplay(12, 20, tile{start: 10, end: 20, size: 10, logURL: "http://example.com"})
if err != nil {
t.Fatalf("expected success, got %s", err)
}
if len(e.Entries) != 1 {
t.Errorf("expected 1 entry got %d", len(entries.Entries))
}
}