@@ -15,11 +15,10 @@ import (
15
15
"errors"
16
16
"fmt"
17
17
"io"
18
- "os"
19
18
"testing"
20
19
"time"
21
20
22
- "github.com/fsouza/go-dockerclient"
21
+ docker "github.com/fsouza/go-dockerclient"
23
22
"github.com/spf13/viper"
24
23
"github.com/stretchr/testify/assert"
25
24
"github.com/stretchr/testify/require"
@@ -36,7 +35,7 @@ import (
36
35
func TestIntegrationPath (t * testing.T ) {
37
36
coreutil .SetupTestConfig ()
38
37
ctxt := context .Background ()
39
- dc := NewDockerVM ("" , "" )
38
+ dc := NewDockerVM ("" , util . GenerateUUID () )
40
39
ccid := ccintf.CCID {Name : "simple" }
41
40
42
41
err := dc .Start (ctxt , ccid , nil , nil , nil , InMemBuilder {})
@@ -67,18 +66,16 @@ func TestHostConfig(t *testing.T) {
67
66
}
68
67
69
68
func TestGetDockerHostConfig (t * testing.T ) {
70
- os .Setenv ("CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE" , "overlay" )
71
- os .Setenv ("CORE_VM_DOCKER_HOSTCONFIG_CPUSHARES" , fmt .Sprint (1024 * 1024 * 1024 * 2 ))
72
69
coreutil .SetupTestConfig ()
73
70
hostConfig = nil // There is a cached global singleton for docker host config, the other tests can collide with
74
71
hostConfig := getDockerHostConfig ()
75
72
testutil .AssertNotNil (t , hostConfig )
76
- testutil .AssertEquals (t , hostConfig .NetworkMode , "overlay " )
73
+ testutil .AssertEquals (t , hostConfig .NetworkMode , "host " )
77
74
testutil .AssertEquals (t , hostConfig .LogConfig .Type , "json-file" )
78
75
testutil .AssertEquals (t , hostConfig .LogConfig .Config ["max-size" ], "50m" )
79
76
testutil .AssertEquals (t , hostConfig .LogConfig .Config ["max-file" ], "5" )
80
77
testutil .AssertEquals (t , hostConfig .Memory , int64 (1024 * 1024 * 1024 * 2 ))
81
- testutil .AssertEquals (t , hostConfig .CPUShares , int64 (1024 * 1024 * 1024 * 2 ))
78
+ testutil .AssertEquals (t , hostConfig .CPUShares , int64 (0 ))
82
79
}
83
80
84
81
func Test_Start (t * testing.T ) {
@@ -117,9 +114,11 @@ func Test_Start(t *testing.T) {
117
114
testerr (t , err , false )
118
115
119
116
chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/example01/cmd"
120
- spec := & pb.ChaincodeSpec {Type : pb .ChaincodeSpec_GOLANG ,
117
+ spec := & pb.ChaincodeSpec {
118
+ Type : pb .ChaincodeSpec_GOLANG ,
121
119
ChaincodeId : & pb.ChaincodeID {Name : "ex01" , Path : chaincodePath },
122
- Input : & pb.ChaincodeInput {Args : util .ToChaincodeArgs ("f" )}}
120
+ Input : & pb.ChaincodeInput {Args : util .ToChaincodeArgs ("f" )},
121
+ }
123
122
codePackage , err := platforms .GetDeploymentPayload (spec )
124
123
if err != nil {
125
124
t .Fatal ()
@@ -261,16 +260,22 @@ func TestGetVMName(t *testing.T) {
261
260
type InMemBuilder struct {}
262
261
263
262
func (imb InMemBuilder ) Build () (io.Reader , error ) {
263
+ buf := & bytes.Buffer {}
264
+ fmt .Fprintln (buf , "FROM busybox:latest" )
265
+ fmt .Fprintln (buf , `CMD ["tail", "-f", "/dev/null"]` )
266
+
264
267
startTime := time .Now ()
265
268
inputbuf := bytes .NewBuffer (nil )
266
269
gw := gzip .NewWriter (inputbuf )
267
270
tr := tar .NewWriter (gw )
268
- dockerFileContents := []byte ("FROM busybox:latest\n \n CMD echo hello" )
269
- dockerFileSize := int64 (len ([]byte (dockerFileContents )))
270
-
271
- tr .WriteHeader (& tar.Header {Name : "Dockerfile" , Size : dockerFileSize ,
272
- ModTime : startTime , AccessTime : startTime , ChangeTime : startTime })
273
- tr .Write ([]byte (dockerFileContents ))
271
+ tr .WriteHeader (& tar.Header {
272
+ Name : "Dockerfile" ,
273
+ Size : int64 (buf .Len ()),
274
+ ModTime : startTime ,
275
+ AccessTime : startTime ,
276
+ ChangeTime : startTime ,
277
+ })
278
+ tr .Write (buf .Bytes ())
274
279
tr .Close ()
275
280
gw .Close ()
276
281
return inputbuf , nil
@@ -309,7 +314,8 @@ var getClientErr, createErr, uploadErr, noSuchImgErr, buildErr, removeImgErr,
309
314
func (c * mockClient ) CreateContainer (options docker.CreateContainerOptions ) (* docker.Container , error ) {
310
315
if createErr {
311
316
return nil , errors .New ("Error creating the container" )
312
- } else if noSuchImgErr && ! c .noSuchImgErrReturned {
317
+ }
318
+ if noSuchImgErr && ! c .noSuchImgErrReturned {
313
319
c .noSuchImgErrReturned = true
314
320
return nil , docker .ErrNoSuchImage
315
321
}
0 commit comments