@@ -44,16 +44,26 @@ import (
44
44
"k8s.io/klog/v2"
45
45
)
46
46
47
- // Test root
48
- var testRootPath = "../testdata/test_root_ca_cert.pem"
47
+ var (
48
+ // Test root
49
+ testRootPath = "../testdata/test_root_ca_cert.pem"
49
50
50
- // Arbitrary time for use in tests
51
- var fakeTime = time .Date (2016 , 7 , 22 , 11 , 01 , 13 , 0 , time .UTC )
52
- var fakeTimeMillis = uint64 (fakeTime .UnixNano () / nanosPerMilli )
51
+ // Arbitrary time for use in tests
52
+ fakeTime = time .Date (2016 , 7 , 22 , 11 , 01 , 13 , 0 , time .UTC )
53
+ fakeTimeMillis = uint64 (fakeTime .UnixNano () / nanosPerMilli )
53
54
54
- // Arbitrary origin for tests
55
- var origin = "example.com"
56
- var prefix = "/" + origin
55
+ // Arbitrary origin for tests
56
+ origin = "example.com"
57
+ prefix = "/" + origin
58
+
59
+ // Default handler options for tests
60
+ hOpts = HandlerOptions {
61
+ Deadline : time .Millisecond * 500 ,
62
+ RequestLog : & DefaultRequestLog {},
63
+ MaskInternalErrors : false ,
64
+ TimeSource : newFixedTimeSource (fakeTime ),
65
+ }
66
+ )
57
67
58
68
type fixedTimeSource struct {
59
69
fakeTime time.Time
@@ -100,14 +110,8 @@ func setupTestLog(t *testing.T) *log {
100
110
// setupTestServer creates a test TesseraCT server with a single endpoint at path.
101
111
func setupTestServer (t * testing.T , log * log , path string ) * httptest.Server {
102
112
t .Helper ()
103
- opts := & HandlerOptions {
104
- Deadline : time .Millisecond * 500 ,
105
- RequestLog : & DefaultRequestLog {},
106
- MaskInternalErrors : false ,
107
- TimeSource : newFixedTimeSource (fakeTime ),
108
- }
109
113
110
- handlers := NewPathHandlers (opts , log )
114
+ handlers := NewPathHandlers (& hOpts , log )
111
115
handler , ok := handlers [path ]
112
116
if ! ok {
113
117
t .Fatalf ("Handler not found: %s" , path )
@@ -189,13 +193,7 @@ func postHandlers(t *testing.T, handlers pathHandlers) pathHandlers {
189
193
190
194
func TestPostHandlersRejectGet (t * testing.T ) {
191
195
log := setupTestLog (t )
192
- opts := & HandlerOptions {
193
- Deadline : time .Millisecond * 500 ,
194
- RequestLog : & DefaultRequestLog {},
195
- MaskInternalErrors : false ,
196
- TimeSource : newFixedTimeSource (fakeTime ),
197
- }
198
- handlers := NewPathHandlers (opts , log )
196
+ handlers := NewPathHandlers (& hOpts , log )
199
197
200
198
// Anything in the post handler list should reject GET
201
199
for path , handler := range postHandlers (t , handlers ) {
@@ -216,13 +214,7 @@ func TestPostHandlersRejectGet(t *testing.T) {
216
214
217
215
func TestGetHandlersRejectPost (t * testing.T ) {
218
216
log := setupTestLog (t )
219
- opts := & HandlerOptions {
220
- Deadline : time .Millisecond * 500 ,
221
- RequestLog : & DefaultRequestLog {},
222
- MaskInternalErrors : false ,
223
- TimeSource : newFixedTimeSource (fakeTime ),
224
- }
225
- handlers := NewPathHandlers (opts , log )
217
+ handlers := NewPathHandlers (& hOpts , log )
226
218
227
219
// Anything in the get handler list should reject POST.
228
220
for path , handler := range getHandlers (t , handlers ) {
@@ -255,13 +247,7 @@ func TestPostHandlersFailure(t *testing.T) {
255
247
}
256
248
257
249
log := setupTestLog (t )
258
- opts := & HandlerOptions {
259
- Deadline : time .Millisecond * 500 ,
260
- RequestLog : & DefaultRequestLog {},
261
- MaskInternalErrors : false ,
262
- TimeSource : newFixedTimeSource (fakeTime ),
263
- }
264
- handlers := NewPathHandlers (opts , log )
250
+ handlers := NewPathHandlers (& hOpts , log )
265
251
266
252
for path , handler := range postHandlers (t , handlers ) {
267
253
t .Run (path , func (t * testing.T ) {
0 commit comments