From 5bd68c881f6e266d707bfd9445e4a618f4c183b5 Mon Sep 17 00:00:00 2001 From: Angelo De Caro Date: Thu, 27 Apr 2017 11:19:25 +0200 Subject: [PATCH] [FAB-3441] bccsp/sw/dummyks.go test coverage This change-set improves the test coverage of bccsp/sw/dummyks.go to 100% Change-Id: Ib4b2fc8c3e3e598404f9d5a7a5cd9cdc8855f45d Signed-off-by: Angelo De Caro --- bccsp/mocks/mocks.go | 41 ++++++++++++++++++++++++++++++++++++ bccsp/sw/dummyks_test.go | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 bccsp/mocks/mocks.go create mode 100644 bccsp/sw/dummyks_test.go diff --git a/bccsp/mocks/mocks.go b/bccsp/mocks/mocks.go new file mode 100644 index 00000000000..a3c8fbcf474 --- /dev/null +++ b/bccsp/mocks/mocks.go @@ -0,0 +1,41 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +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 mocks + +import "github.com/hyperledger/fabric/bccsp" + +type MockKey struct{} + +func (*MockKey) Bytes() ([]byte, error) { + panic("implement me") +} + +func (*MockKey) SKI() []byte { + panic("implement me") +} + +func (*MockKey) Symmetric() bool { + panic("implement me") +} + +func (*MockKey) Private() bool { + panic("implement me") +} + +func (*MockKey) PublicKey() (bccsp.Key, error) { + panic("implement me") +} diff --git a/bccsp/sw/dummyks_test.go b/bccsp/sw/dummyks_test.go new file mode 100644 index 00000000000..a7a9c0f1156 --- /dev/null +++ b/bccsp/sw/dummyks_test.go @@ -0,0 +1,45 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +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 sw + +import ( + "testing" + + "github.com/hyperledger/fabric/bccsp/mocks" + "github.com/stretchr/testify/assert" +) + +func TestNewDummyKeyStore(t *testing.T) { + ks := NewDummyKeyStore() + assert.NotNil(t, ks) +} + +func TestDummyKeyStore_GetKey(t *testing.T) { + ks := NewDummyKeyStore() + _, err := ks.GetKey([]byte{0, 1, 2, 3, 4}) + assert.Error(t, err) +} + +func TestDummyKeyStore_ReadOnly(t *testing.T) { + ks := NewDummyKeyStore() + assert.True(t, ks.ReadOnly()) +} + +func TestDummyKeyStore_StoreKey(t *testing.T) { + ks := NewDummyKeyStore() + err := ks.StoreKey(&mocks.MockKey{}) + assert.Error(t, err) +}