-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_client_test.go
107 lines (92 loc) · 2.83 KB
/
log_client_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
package mtr
import (
"testing"
"context"
"github.com/n-ct/ct-monitor/entitylist"
)
const (
logListPath = "entitylist/log_list.json"
testLogID = "9lyUL9F3MCIUVBgIMJRWjuNNExkzv98MLyALzE7xZOM="
)
func mustCreateLogClient(t *testing.T) (*LogClient, context.Context, error) {
t.Helper()
logList, err := entitylist.NewLogList(logListPath)
if err != nil {
t.Fatalf("failed to create loglist at path (%s): %v", logListPath, err)
}
logInfo := logList.FindLogByLogID(testLogID)
if logInfo == nil {
t.Fatalf("testLogID %s not found in loglist", testLogID)
}
logClient, err := NewLogClient(logInfo)
ctx := context.Background()
return logClient, ctx, err
}
func TestNewLogClient(t *testing.T) {
_, _, err := mustCreateLogClient(t)
if err != nil {
t.Fatalf("%v", err)
}
}
func mustGetSTH(t *testing.T) (*CTObject, error) {
t.Helper()
logClient, ctx, _ := mustCreateLogClient(t)
return logClient.GetSTH(ctx)
}
func TestGetSTH(t *testing.T) {
_, err := mustGetSTH(t)
if err != nil {
t.Fatalf("%v", err)
}
}
func TestGetSTHReturnType(t *testing.T) {
newSTH, _ := mustGetSTH(t)
var sth interface{} = newSTH
if _, ok := sth.(*CTObject); !ok {
t.Fatalf("incorrect data type received from GetSTH: %T", sth)
}
}
func mustGetSTHWithConsistencyProof(t *testing.T, firstTreeSize, secondTreeSize uint64) (*CTObject, error) {
t.Helper()
logClient, ctx, _ := mustCreateLogClient(t)
return logClient.GetSTHWithConsistencyProof(ctx, firstTreeSize, secondTreeSize)
}
func TestGetSTHWithConsistencyProof(t *testing.T) {
validFirstTreeSize := uint64(100)
validSecondTreeSize := uint64(1000)
_, err := mustGetSTHWithConsistencyProof(t, validFirstTreeSize, validSecondTreeSize)
if err != nil {
t.Fatalf("%v", err)
}
}
func TestGetSTHWithConsistencyProofReturnType(t *testing.T) {
validFirstTreeSize := uint64(100)
validSecondTreeSize := uint64(1000)
newSTHPOC, _ := mustGetSTHWithConsistencyProof(t, validFirstTreeSize, validSecondTreeSize)
var sthpoc interface{} = newSTHPOC
if _, ok := sthpoc.(*CTObject); !ok {
t.Fatalf("incorrect data type received from GetSTH: %T", sthpoc)
}
}
func mustGetEntryAndProof(t *testing.T, entryIndex, treeSize uint64) (*InclusionProofData, []byte, error) {
t.Helper()
logClient, ctx, _ := mustCreateLogClient(t)
return logClient.GetEntryAndProof(ctx, entryIndex, treeSize)
}
func TestGetEntryAndProof(t *testing.T) {
validTreeSize := uint64(100)
validEntryIndex := uint64(4)
_, _, err := mustGetEntryAndProof(t, validEntryIndex, validTreeSize)
if err != nil {
t.Fatalf("%v", err)
}
}
func TestGetEntryAndProofReturnType(t *testing.T) {
validTreeSize := uint64(100)
validEntryIndex := uint64(4)
newPOI, _, _ := mustGetEntryAndProof(t, validEntryIndex, validTreeSize)
var poi interface{} = newPOI
if _, ok := poi.(*InclusionProofData); !ok {
t.Fatalf("incorrect data type received from GetSTH: %T", poi)
}
}