Skip to content

Commit 127a8b6

Browse files
committed
NewPathHandlers test
# Conflicts: # internal/scti/handlers_test.go
1 parent 040ad99 commit 127a8b6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

internal/scti/handlers_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"testing"
2727
"time"
2828

29+
"github.com/google/go-cmp/cmp"
30+
"github.com/google/go-cmp/cmp/cmpopts"
2931
"github.com/transparency-dev/static-ct/internal/testdata"
3032
"github.com/transparency-dev/static-ct/internal/testonly/storage/posix"
3133
"github.com/transparency-dev/static-ct/internal/types"
@@ -151,6 +153,38 @@ func newPosixStorageFunc(t *testing.T) storage.CreateStorage {
151153
}
152154
}
153155

156+
func TestNewPathHandlers(t *testing.T) {
157+
log := setupTestLog(t)
158+
t.Run("Handlers", func(t *testing.T) {
159+
handlers := NewPathHandlers(&HandlerOptions{}, log)
160+
// Check each entrypoint has a handler
161+
if got, want := len(handlers), len(entrypoints); got != want {
162+
t.Fatalf("len(info.handler)=%d; want %d", got, want)
163+
}
164+
165+
// We want to see the same set of handler names and paths that we think we registered.
166+
var hNames []entrypointName
167+
var hPaths []string
168+
for p, v := range handlers {
169+
hNames = append(hNames, v.name)
170+
hPaths = append(hPaths, p)
171+
}
172+
173+
if !cmp.Equal(entrypoints, hNames, cmpopts.SortSlices(func(n1, n2 entrypointName) bool {
174+
return n1 < n2
175+
})) {
176+
t.Errorf("Handler names mismatch got: %v, want: %v", hNames, entrypoints)
177+
}
178+
179+
entrypaths := []string{prefix + types.AddChainPath, prefix + types.AddPreChainPath, prefix + types.GetRootsPath}
180+
if !cmp.Equal(entrypaths, hPaths, cmpopts.SortSlices(func(n1, n2 string) bool {
181+
return n1 < n2
182+
})) {
183+
t.Errorf("Handler paths mismatch got: %v, want: %v", hPaths, entrypaths)
184+
}
185+
})
186+
}
187+
154188
func TestGetRoots(t *testing.T) {
155189
log := setupTestLog(t)
156190
server := setupTestServer(t, log, path.Join(prefix, "ct/v1/get-roots"))

0 commit comments

Comments
 (0)