@@ -26,6 +26,8 @@ import (
26
26
"testing"
27
27
"time"
28
28
29
+ "github.com/google/go-cmp/cmp"
30
+ "github.com/google/go-cmp/cmp/cmpopts"
29
31
"github.com/transparency-dev/static-ct/internal/testdata"
30
32
"github.com/transparency-dev/static-ct/internal/testonly/storage/posix"
31
33
"github.com/transparency-dev/static-ct/internal/types"
@@ -151,6 +153,38 @@ func newPosixStorageFunc(t *testing.T) storage.CreateStorage {
151
153
}
152
154
}
153
155
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
+
154
188
func TestGetRoots (t * testing.T ) {
155
189
log := setupTestLog (t )
156
190
server := setupTestServer (t , log , path .Join (prefix , "ct/v1/get-roots" ))
0 commit comments