github.com/true-sqn/fabric@v2.1.1+incompatible/internal/peer/node/reset_test.go (about)

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