Skip to content

Commit f52b447

Browse files
committed
clean var definition
1 parent f4e6384 commit f52b447

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

internal/scti/handlers_test.go

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,26 @@ import (
4444
"k8s.io/klog/v2"
4545
)
4646

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"
4950

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)
5354

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+
)
5767

5868
type fixedTimeSource struct {
5969
fakeTime time.Time
@@ -100,14 +110,8 @@ func setupTestLog(t *testing.T) *log {
100110
// setupTestServer creates a test TesseraCT server with a single endpoint at path.
101111
func setupTestServer(t *testing.T, log *log, path string) *httptest.Server {
102112
t.Helper()
103-
opts := &HandlerOptions{
104-
Deadline: time.Millisecond * 500,
105-
RequestLog: &DefaultRequestLog{},
106-
MaskInternalErrors: false,
107-
TimeSource: newFixedTimeSource(fakeTime),
108-
}
109113

110-
handlers := NewPathHandlers(opts, log)
114+
handlers := NewPathHandlers(&hOpts, log)
111115
handler, ok := handlers[path]
112116
if !ok {
113117
t.Fatalf("Handler not found: %s", path)
@@ -189,13 +193,7 @@ func postHandlers(t *testing.T, handlers pathHandlers) pathHandlers {
189193

190194
func TestPostHandlersRejectGet(t *testing.T) {
191195
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)
199197

200198
// Anything in the post handler list should reject GET
201199
for path, handler := range postHandlers(t, handlers) {
@@ -216,13 +214,7 @@ func TestPostHandlersRejectGet(t *testing.T) {
216214

217215
func TestGetHandlersRejectPost(t *testing.T) {
218216
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)
226218

227219
// Anything in the get handler list should reject POST.
228220
for path, handler := range getHandlers(t, handlers) {
@@ -255,13 +247,7 @@ func TestPostHandlersFailure(t *testing.T) {
255247
}
256248

257249
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)
265251

266252
for path, handler := range postHandlers(t, handlers) {
267253
t.Run(path, func(t *testing.T) {

0 commit comments

Comments
 (0)