-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection_test.go
88 lines (60 loc) · 1.47 KB
/
connection_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
package main
import (
"testing"
)
var (
testtube = "https://ct.googleapis.com/testtube"
)
func testLSC(lSC *LogServerConnection, bucketSize int64, offset int64, t *testing.T) {
if lSC != nil {
if lSC.start != offset || lSC.end != bucketSize+offset {
t.Errorf("Bucket indices are incorrect")
return
}
} else {
t.Errorf("Couldn't get a new server connection")
return
}
return
}
func TestNew(t *testing.T) {
uri := testtube
bucketSize := int64(1)
lSC := New(uri, bucketSize)
testLSC(lSC, bucketSize, int64(0), t)
}
func TestNewWithOffset0(t *testing.T) {
uri := testtube
bucketSize := int64(1)
offset := int64(0)
lSC := NewWithOffset(uri, bucketSize, offset)
testLSC(lSC, bucketSize, offset, t)
}
func TestNewWithOffset1(t *testing.T) {
bucketSize := int64(1)
offset := int64(1)
lSC := NewWithOffset(testtube, bucketSize, offset)
testLSC(lSC, bucketSize, offset, t)
}
func TestSlideBucket(t *testing.T) {
bucketSize := int64(10)
lSC := New(testtube, bucketSize)
lSC.slideBucket()
if lSC.start != bucketSize+1 || lSC.end != bucketSize*2 {
t.Errorf("Couldn't slide bucket %d, %d", lSC.start, lSC.end)
return
}
}
func TestGetLogEntries(t *testing.T) {
bucketSize := int64(10)
lSC := New(testtube, bucketSize)
entries, err := lSC.GetLogEntries()
if err != nil {
t.Errorf("Couldn't get log entries!")
return
}
if int64(len(entries)) != bucketSize+1 {
t.Errorf("Did not get the right number of entries: %d", len(entries))
return
}
}