Skip to content

Commit

Permalink
Merge pull request #1327 from kaleido-io/contractapitest
Browse files Browse the repository at this point in the history
Add unit test for "delete contract API" route
  • Loading branch information
nguyer authored May 31, 2023
2 parents 7a99e9b + a093cee commit 04ed0e2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/apiserver/route_delete_contract_api_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 04ed0e2

Please # to comment.