github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/root_test.go (about)

     1  // Copyright (c) 2022 IoTeX Foundation
     2  // This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
     3  // or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
     4  // This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
     5  
     6  package newcmd
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/golang/mock/gomock"
    12  	"github.com/spf13/cobra"
    13  	"github.com/stretchr/testify/require"
    14  
    15  	"github.com/iotexproject/iotex-core/ioctl/config"
    16  	"github.com/iotexproject/iotex-core/ioctl/util"
    17  	"github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient"
    18  )
    19  
    20  func TestNew(t *testing.T) {
    21  	require := require.New(t)
    22  	ctrl := gomock.NewController(t)
    23  	defer ctrl.Finish()
    24  	client := mock_ioctlclient.NewMockClient(ctrl)
    25  	client.EXPECT().SelectTranslation(gomock.Any()).Return("mockTranslationString", config.English).AnyTimes()
    26  	client.EXPECT().SetEndpointWithFlag(gomock.Any()).Do(func(_ func(*string, string, string, string)) {}).AnyTimes()
    27  	client.EXPECT().SetInsecureWithFlag(gomock.Any()).Do(func(_ func(*bool, string, bool, string)) {}).AnyTimes()
    28  
    29  	cmds := []*cobra.Command{
    30  		NewIoctl(client),
    31  		NewXctl(client),
    32  	}
    33  	for _, cmd := range cmds {
    34  		result, err := util.ExecuteCmd(cmd)
    35  		require.NoError(err)
    36  		require.Contains(result, "Available Commands")
    37  		require.Contains(result, "Flags")
    38  	}
    39  }