Skip to content

Commit db7cd47

Browse files
author
Anil Ambati
committed
[FAB-4049] Add additional tests to core/container pkg
Added additional tests to core/container pkg to bring the coverage to 82% if tests are run with the -run-controller-tests flag. Change-Id: Id42f9b96a2847a04473447aa4220472b3de0b942 Signed-off-by: Anil Ambati <[email protected]>
1 parent 80f4ed2 commit db7cd47

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

core/container/controller_test.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import (
2727
"time"
2828

2929
"github.com/hyperledger/fabric/core/container/ccintf"
30+
"github.com/hyperledger/fabric/core/container/dockercontroller"
31+
"github.com/hyperledger/fabric/core/container/inproccontroller"
3032
pb "github.com/hyperledger/fabric/protos/peer"
31-
33+
"github.com/stretchr/testify/assert"
3234
"golang.org/x/net/context"
3335
)
3436

@@ -270,3 +272,17 @@ func TestVMCStopContainer(t *testing.T) {
270272
fmt.Println("VMCStopContainer-waiting for response")
271273
<-c
272274
}
275+
276+
func TestNewVM(t *testing.T) {
277+
vm := vmcontroller.newVM("Docker")
278+
dvm := vm.(*dockercontroller.DockerVM)
279+
assert.NotNil(t, dvm, "Requested Docker VM but newVM did not return dockercontroller.DockerVM")
280+
281+
vm = vmcontroller.newVM("System")
282+
ivm := vm.(*inproccontroller.InprocVM)
283+
assert.NotNil(t, ivm, "Requested System VM but newVM did not return inproccontroller.InprocVM")
284+
285+
vm = vmcontroller.newVM("")
286+
dvm = vm.(*dockercontroller.DockerVM)
287+
assert.NotNil(t, dvm, "Requested default VM but newVM did not return dockercontroller.DockerVM")
288+
}

core/container/vm_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ import (
2929
)
3030

3131
func TestMain(m *testing.M) {
32-
flag.BoolVar(&runTests, "run-controller-tests", false, "run tests")
32+
flag.BoolVar(&runTests, "run-controller-tests", true, "run tests")
3333
flag.Parse()
3434
testutil.SetupTestConfig()
3535
os.Exit(m.Run())
3636
}
3737

3838
func TestVM_ListImages(t *testing.T) {
39-
t.Skip("No need to invoke list images.")
4039
vm, err := NewVM()
4140
if err != nil {
4241
t.Fail()
@@ -84,14 +83,27 @@ func TestVM_GetChaincodePackageBytes(t *testing.T) {
8483
assert.Error(t, err,
8584
"GetChaincodePackageBytes did not return error when chaincode spec is nil")
8685

87-
spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
86+
spec := &pb.ChaincodeSpec{ChaincodeId: nil}
87+
_, err = GetChaincodePackageBytes(spec)
88+
assert.Error(t, err, "Error expected when GetChaincodePackageBytes is called with nil chaincode ID")
89+
assert.Contains(t, err.Error(), "invalid chaincode spec")
90+
91+
spec = &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG,
8892
ChaincodeId: nil,
8993
Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}}
9094
_, err = GetChaincodePackageBytes(spec)
9195
assert.Error(t, err,
9296
"GetChaincodePackageBytes did not return error when chaincode ID is nil")
9397
}
9498

99+
func TestVM_BuildChaincodeContainer(t *testing.T) {
100+
vm, err := NewVM()
101+
assert.NoError(t, err)
102+
err = vm.BuildChaincodeContainer(nil)
103+
assert.Error(t, err)
104+
assert.Contains(t, err.Error(), "Error getting chaincode package bytes")
105+
}
106+
95107
func TestVM_Chaincode_Compile(t *testing.T) {
96108
// vm, err := NewVM()
97109
// if err != nil {

0 commit comments

Comments
 (0)