From a093ceed5be5a4390e222b6be105a3f4289afc1c Mon Sep 17 00:00:00 2001 From: Andrew Richardson Date: Tue, 30 May 2023 13:20:06 -0400 Subject: [PATCH] Add unit test for "delete contract API" route Signed-off-by: Andrew Richardson --- .../route_delete_contract_api_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 internal/apiserver/route_delete_contract_api_test.go diff --git a/internal/apiserver/route_delete_contract_api_test.go b/internal/apiserver/route_delete_contract_api_test.go new file mode 100644 index 0000000000..ec594686f7 --- /dev/null +++ b/internal/apiserver/route_delete_contract_api_test.go @@ -0,0 +1,41 @@ +// Copyright © 2021 Kaleido, Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package apiserver + +import ( + "net/http/httptest" + "testing" + + "github.com/hyperledger/firefly/mocks/contractmocks" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestDeleteContractAPI(t *testing.T) { + o, r := newTestAPIServer() + o.On("Authorize", mock.Anything, mock.Anything).Return(nil) + mcm := &contractmocks.Manager{} + o.On("Contracts").Return(mcm) + req := httptest.NewRequest("DELETE", "/api/v1/namespaces/ns1/apis/banana", nil) + req.Header.Set("Content-Type", "application/json; charset=utf-8") + res := httptest.NewRecorder() + + mcm.On("DeleteContractAPI", mock.Anything, "banana").Return(nil) + r.ServeHTTP(res, req) + + assert.Equal(t, 204, res.Result().StatusCode) +}