github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/core/container/vm_test.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package container 18 19 import ( 20 "archive/tar" 21 "bytes" 22 "flag" 23 "io/ioutil" 24 "os" 25 "testing" 26 27 "github.com/hyperledger/fabric/common/util" 28 cutil "github.com/hyperledger/fabric/core/container/util" 29 pb "github.com/hyperledger/fabric/protos/peer" 30 "golang.org/x/net/context" 31 ) 32 33 func TestMain(m *testing.M) { 34 flag.BoolVar(&runTests, "run-controller-tests", false, "run tests") 35 flag.Parse() 36 SetupTestConfig() 37 os.Exit(m.Run()) 38 } 39 40 func TestVM_ListImages(t *testing.T) { 41 t.Skip("No need to invoke list images.") 42 vm, err := NewVM() 43 if err != nil { 44 t.Fail() 45 t.Logf("Error getting VM: %s", err) 46 } 47 err = vm.ListImages(context.TODO()) 48 if err != nil { 49 t.Fail() 50 t.Logf("Error listing images: %s", err) 51 } 52 } 53 54 func TestVM_BuildImage_WritingGopathSource(t *testing.T) { 55 t.Skip("This can be re-enabled if testing GOPATH writing to tar image.") 56 inputbuf := bytes.NewBuffer(nil) 57 tw := tar.NewWriter(inputbuf) 58 59 err := cutil.WriteGopathSrc(tw, "") 60 if err != nil { 61 t.Fail() 62 t.Logf("Error writing gopath src: %s", err) 63 } 64 ioutil.WriteFile("/tmp/chaincode_deployment.tar", inputbuf.Bytes(), 0644) 65 66 } 67 68 func TestVM_BuildImage_ChaincodeLocal(t *testing.T) { 69 vm, err := NewVM() 70 if err != nil { 71 t.Fail() 72 t.Logf("Error getting VM: %s", err) 73 return 74 } 75 // Build the spec 76 chaincodePath := "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example01" 77 spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "ex01", Path: chaincodePath}, Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}} 78 if err := vm.BuildChaincodeContainer(spec); err != nil { 79 t.Fail() 80 t.Log(err) 81 } 82 } 83 84 func TestVM_BuildImage_ChaincodeRemote(t *testing.T) { 85 t.Skip("Works but needs user credentials. Not suitable for automated unit tests as is") 86 vm, err := NewVM() 87 if err != nil { 88 t.Fail() 89 t.Logf("Error getting VM: %s", err) 90 return 91 } 92 // Build the spec 93 chaincodePath := "https://github.com/prjayach/chaincode_examples/chaincode_example02" 94 spec := &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: "ex02", Path: chaincodePath}, Input: &pb.ChaincodeInput{Args: util.ToChaincodeArgs("f")}} 95 if err := vm.BuildChaincodeContainer(spec); err != nil { 96 t.Fail() 97 t.Log(err) 98 } 99 } 100 101 func TestVM_Chaincode_Compile(t *testing.T) { 102 // vm, err := NewVM() 103 // if err != nil { 104 // t.Fail() 105 // t.Logf("Error getting VM: %s", err) 106 // return 107 // } 108 109 // if err := vm.BuildPeerContainer(); err != nil { 110 // t.Fail() 111 // t.Log(err) 112 // } 113 t.Skip("NOT IMPLEMENTED") 114 }