diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-10-11 22:48:14 +0200 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2021-10-11 22:48:14 +0200 |
commit | 3d14dcc45ce0f09b8c8d2843492064f5395263e0 (patch) | |
tree | 3843a1ecd6c8a5c832e769b7334c43f71226b881 /pkg/instance/instance_test.go | |
parent | bf1cd0b7e8397cb9006d0f37b6ee3eb1ed566076 (diff) |
fixed bug in handler path constructionv0.3.1
A path is expected to always start with the '/' character.
Diffstat (limited to 'pkg/instance/instance_test.go')
-rw-r--r-- | pkg/instance/instance_test.go | 41 |
1 files changed, 29 insertions, 12 deletions
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) + } } } |