Skip to content

Commit

Permalink
[FAB-3485] improve test coverage for msp
Browse files Browse the repository at this point in the history
Test output for msp now is

coverage: 86.1% of statements
ok		github.com/hyperledger/fabric/msp	0.054s

Change-Id: Ic6fb239df31074224bd150d24305cb098dcc13d8
Signed-off-by: Alessandro Sorniotti <ale.linux@sopit.net>
  • Loading branch information
ale-linux committed Apr 29, 2017
1 parent a97886a commit 8670c56
Show file tree
Hide file tree
Showing 4 changed files with 422 additions and 6 deletions.
46 changes: 46 additions & 0 deletions msp/configbuilder_test.go
@@ -0,0 +1,46 @@
/*
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 msp

import (
"testing"

"github.com/hyperledger/fabric/core/config"
"github.com/stretchr/testify/assert"
)

func TestGetLocalMspConfig(t *testing.T) {
mspDir, err := config.GetDevMspDir()
assert.NoError(t, err)
_, err = GetLocalMspConfig(mspDir, nil, "DEFAULT")
assert.NoError(t, err)
}

func TestGetLocalMspConfigFails(t *testing.T) {
_, err := GetLocalMspConfig("/tmp/", nil, "DEFAULT")
assert.Error(t, err)
}

func TestReadFileUtils(t *testing.T) {
// test that reading a file with an empty path doesn't crash
_, err := readPemFile("")
assert.Error(t, err)

// test that reading an existing file which is not a PEM file doesn't crash
_, err = readPemFile("/dev/null")
assert.Error(t, err)
}
10 changes: 5 additions & 5 deletions msp/identities.go
Expand Up @@ -144,12 +144,12 @@ func (id *identity) Verify(msg []byte, sig []byte) error {

func (id *identity) VerifyOpts(msg []byte, sig []byte, opts SignatureOpts) error {
// TODO
return nil
return errors.New("This method is unimplemented")
}

func (id *identity) VerifyAttributes(proof []byte, spec *AttributeProofSpec) error {
// TODO
return nil
return errors.New("This method is unimplemented")
}

// Serialize returns a byte array representation of this identity
Expand Down Expand Up @@ -225,12 +225,12 @@ func (id *signingidentity) Sign(msg []byte) ([]byte, error) {

func (id *signingidentity) SignOpts(msg []byte, opts SignatureOpts) ([]byte, error) {
// TODO
return nil, nil
return nil, errors.New("This method is unimplemented")
}

func (id *signingidentity) GetAttributeProof(spec *AttributeProofSpec) (proof []byte, err error) {
// TODO
return nil, nil
return nil, errors.New("This method is unimplemented")
}

func (id *signingidentity) GetPublicVersion() Identity {
Expand All @@ -239,5 +239,5 @@ func (id *signingidentity) GetPublicVersion() Identity {

func (id *signingidentity) Renew() error {
// TODO
return nil
return errors.New("This method is unimplemented")
}

0 comments on commit 8670c56

Please sign in to comment.