github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/common/configtx/tool/configtxgen/main_test.go (about) 1 /* 2 Copyright IBM Corp. 2017 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 main 18 19 import ( 20 "io/ioutil" 21 "os" 22 "testing" 23 24 "github.com/hyperledger/fabric/bccsp/factory" 25 genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig" 26 27 "github.com/stretchr/testify/assert" 28 ) 29 30 var tmpDir string 31 32 func TestMain(m *testing.M) { 33 dir, err := ioutil.TempDir("", "configtxgen") 34 if err != nil { 35 panic("Error creating temp dir") 36 } 37 tmpDir = dir 38 testResult := m.Run() 39 os.RemoveAll(dir) 40 41 os.Exit(testResult) 42 } 43 44 func TestInspectBlock(t *testing.T) { 45 blockDest := tmpDir + string(os.PathSeparator) + "block" 46 47 factory.InitFactories(nil) 48 config := genesisconfig.Load(genesisconfig.SampleInsecureProfile) 49 50 assert.NoError(t, doOutputBlock(config, "foo", blockDest), "Good block generation request") 51 assert.NoError(t, doInspectBlock(blockDest), "Good block inspection request") 52 } 53 54 func TestInspectConfigTx(t *testing.T) { 55 configTxDest := tmpDir + string(os.PathSeparator) + "configtx" 56 57 factory.InitFactories(nil) 58 config := genesisconfig.Load(genesisconfig.SampleInsecureProfile) 59 60 assert.NoError(t, doOutputChannelCreateTx(config, "foo", configTxDest), "Good outputChannelCreateTx generation request") 61 assert.NoError(t, doInspectChannelCreateTx(configTxDest), "Good configtx inspection request") 62 } 63 64 func TestGenerateAnchorPeersUpdate(t *testing.T) { 65 configTxDest := tmpDir + string(os.PathSeparator) + "anchorPeerUpdate" 66 67 factory.InitFactories(nil) 68 config := genesisconfig.Load(genesisconfig.SampleSingleMSPSoloProfile) 69 70 assert.NoError(t, doOutputAnchorPeersUpdate(config, "foo", configTxDest, genesisconfig.SampleOrgName), "Good anchorPeerUpdate request") 71 }