aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/instance/instance.go5
-rw-r--r--pkg/instance/instance_test.go41
2 files changed, 33 insertions, 13 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go
index fbfe4df..dc7f5c5 100644
--- a/pkg/instance/instance.go
+++ b/pkg/instance/instance.go
@@ -64,7 +64,10 @@ func (i *Instance) Handlers() []Handler {
// Path returns a path that should be configured for this handler
func (h Handler) Path() string {
- return h.Endpoint.Path(h.Instance.Prefix, "sigsum", "v0")
+ if len(h.Instance.Prefix) == 0 {
+ return h.Endpoint.Path("", "sigsum", "v0")
+ }
+ return h.Endpoint.Path("", h.Instance.Prefix, "sigsum", "v0")
}
// ServeHTTP is part of the http.Handler interface
diff --git a/pkg/instance/instance_test.go b/pkg/instance/instance_test.go
index 1706e86..9eeee5b 100644
--- a/pkg/instance/instance_test.go
+++ b/pkg/instance/instance_test.go
@@ -62,19 +62,36 @@ func TestServeHTTP(t *testing.T) {
}
}
+// TestPath checks that Path works for an endpoint (add-leaf)
func TestPath(t *testing.T) {
- instance := &Instance{
- Config: Config{
- Prefix: "testonly",
+ for _, table := range []struct {
+ description string
+ prefix string
+ want string
+ }{
+ {
+ description: "no prefix",
+ want: "/sigsum/v0/add-leaf",
},
- }
- handler := Handler{
- Instance: instance,
- Handler: addLeaf,
- Endpoint: types.EndpointAddLeaf,
- Method: http.MethodPost,
- }
- if got, want := handler.Path(), "testonly/sigsum/v0/add-leaf"; got != want {
- t.Errorf("got path %v but wanted %v", got, want)
+ {
+ description: "a prefix",
+ prefix: "test-prefix",
+ want: "/test-prefix/sigsum/v0/add-leaf",
+ },
+ } {
+ instance := &Instance{
+ Config: Config{
+ Prefix: table.prefix,
+ },
+ }
+ handler := Handler{
+ Instance: instance,
+ Handler: addLeaf,
+ Endpoint: types.EndpointAddLeaf,
+ Method: http.MethodPost,
+ }
+ if got, want := handler.Path(), table.want; got != want {
+ t.Errorf("got path %v but wanted %v", got, want)
+ }
}
}