github.com/kaituanwang/hyperledger@v2.0.1+incompatible/internal/peer/node/reset_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 SPDX-License-Identifier: Apache-2.0 4 */ 5 6 package node 7 8 import ( 9 "io/ioutil" 10 "os" 11 "path" 12 "path/filepath" 13 "testing" 14 15 "github.com/hyperledger/fabric/core/config" 16 "github.com/spf13/viper" 17 "github.com/stretchr/testify/assert" 18 ) 19 20 func TestResetCmd(t *testing.T) { 21 testPath := "/tmp/hyperledger/test" 22 os.RemoveAll(testPath) 23 viper.Set("peer.fileSystemPath", testPath) 24 defer os.RemoveAll(testPath) 25 26 viper.Set("logging.ledger", "INFO") 27 rootFSPath := filepath.Join(config.GetPath("peer.fileSystemPath"), "ledgersData") 28 historyDBPath := filepath.Join(rootFSPath, "historyLeveldb") 29 assert.NoError(t, 30 os.MkdirAll(historyDBPath, 0755), 31 ) 32 assert.NoError(t, 33 ioutil.WriteFile(path.Join(historyDBPath, "dummyfile.txt"), []byte("this is a dummy file for test"), 0644), 34 ) 35 cmd := resetCmd() 36 37 _, err := os.Stat(historyDBPath) 38 assert.False(t, os.IsNotExist(err)) 39 assert.NoError(t, cmd.Execute()) 40 _, err = os.Stat(historyDBPath) 41 assert.True(t, os.IsNotExist(err)) 42 }