github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/internal/peer/node/unjoin_test.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package node
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  
    13  	"github.com/spf13/viper"
    14  	"github.com/stretchr/testify/require"
    15  )
    16  
    17  func TestUnjoinCmd(t *testing.T) {
    18  	t.Run("when the channelID is not specified", func(t *testing.T) {
    19  		cmd := unjoinCmd()
    20  		args := []string{}
    21  		cmd.SetArgs(args)
    22  		err := cmd.Execute()
    23  		require.EqualError(t, err, "Must supply channel ID")
    24  	})
    25  
    26  	t.Run("when the channel does not exist", func(t *testing.T) {
    27  		testPath := "/tmp/hyperledger/test"
    28  		os.RemoveAll(testPath)
    29  		viper.Set("peer.fileSystemPath", testPath)
    30  		defer os.RemoveAll(testPath)
    31  
    32  		cmd := unjoinCmd()
    33  		cmd.SetArgs([]string{"-c", "invalid_channel_does_not_exist"})
    34  		err := cmd.Execute()
    35  		require.EqualError(t, err, "unjoin channel [invalid_channel_does_not_exist]: cannot update ledger status, ledger [invalid_channel_does_not_exist] does not exist")
    36  	})
    37  }