aboutsummaryrefslogtreecommitdiff
path: root/pkg/instance/handler_test.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus@mullvad.net>2022-01-25 01:06:54 +0100
committerRasmus Dahlberg <rasmus@mullvad.net>2022-01-26 01:17:24 +0100
commitdf8455a97090cb06e26a881162b86887c4dfcca5 (patch)
tree3e1b9a66736a693f2da9f5cdbb581620e77d7687 /pkg/instance/handler_test.go
parenta8df88efdb0adf014e524c813193228d06e9ac6a (diff)
instance: Use the new tree-head endpoints
Diffstat (limited to 'pkg/instance/handler_test.go')
-rw-r--r--pkg/instance/handler_test.go56
1 files changed, 2 insertions, 54 deletions
diff --git a/pkg/instance/handler_test.go b/pkg/instance/handler_test.go
index ba5b60c..f8817dc 100644
--- a/pkg/instance/handler_test.go
+++ b/pkg/instance/handler_test.go
@@ -53,7 +53,6 @@ func TestHandlers(t *testing.T) {
endpoints := map[types.Endpoint]bool{
types.EndpointAddLeaf: false,
types.EndpointAddCosignature: false,
- types.EndpointGetTreeHeadLatest: false,
types.EndpointGetTreeHeadToSign: false,
types.EndpointGetTreeHeadCosigned: false,
types.EndpointGetConsistencyProof: false,
@@ -296,57 +295,6 @@ func TestAddCosignature(t *testing.T) {
}
}
-func TestGetTreeHeadLatest(t *testing.T) {
- for _, table := range []struct {
- description string
- expect bool // set if a mock answer is expected
- rsp *types.SignedTreeHead // signed tree head from Trillian client
- err error // error from Trillian client
- wantCode int // HTTP status ok
- }{
- {
- description: "invalid: backend failure",
- expect: true,
- err: fmt.Errorf("something went wrong"),
- wantCode: http.StatusInternalServerError,
- },
- {
- description: "valid",
- expect: true,
- rsp: testSTH,
- wantCode: http.StatusOK,
- },
- } {
- // Run deferred functions at the end of each iteration
- func() {
- ctrl := gomock.NewController(t)
- defer ctrl.Finish()
- stateman := mocksState.NewMockStateManager(ctrl)
- if table.expect {
- stateman.EXPECT().Latest(gomock.Any()).Return(table.rsp, table.err)
- }
- i := Instance{
- Config: testConfig,
- Stateman: stateman,
- }
-
- // Create HTTP request
- url := types.EndpointGetTreeHeadLatest.Path("http://example.com", i.Prefix)
- req, err := http.NewRequest("GET", url, nil)
- if err != nil {
- t.Fatalf("must create http request: %v", err)
- }
-
- // Run HTTP request
- w := httptest.NewRecorder()
- mustHandle(t, i, types.EndpointGetTreeHeadLatest).ServeHTTP(w, req)
- if got, want := w.Code, table.wantCode; got != want {
- t.Errorf("got HTTP status code %v but wanted %v in test %q", got, want, table.description)
- }
- }()
- }
-}
-
func TestGetTreeToSign(t *testing.T) {
for _, table := range []struct {
description string
@@ -374,7 +322,7 @@ func TestGetTreeToSign(t *testing.T) {
defer ctrl.Finish()
stateman := mocksState.NewMockStateManager(ctrl)
if table.expect {
- stateman.EXPECT().ToSign(gomock.Any()).Return(table.rsp, table.err)
+ stateman.EXPECT().ToCosignTreeHead(gomock.Any()).Return(table.rsp, table.err)
}
i := Instance{
Config: testConfig,
@@ -425,7 +373,7 @@ func TestGetTreeCosigned(t *testing.T) {
defer ctrl.Finish()
stateman := mocksState.NewMockStateManager(ctrl)
if table.expect {
- stateman.EXPECT().Cosigned(gomock.Any()).Return(table.rsp, table.err)
+ stateman.EXPECT().CosignedTreeHead(gomock.Any()).Return(table.rsp, table.err)
}
i := Instance{
Config: testConfig,