github.com/iotexproject/iotex-core@v1.14.1-rc1/ioctl/newcmd/alias/aliaslist_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 package alias 6 7 import ( 8 "testing" 9 10 "github.com/golang/mock/gomock" 11 "github.com/iotexproject/iotex-core/ioctl/config" 12 "github.com/iotexproject/iotex-core/ioctl/util" 13 "github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" 14 "github.com/stretchr/testify/require" 15 ) 16 17 // test for alias list command 18 func TestNewAliasListCmd(t *testing.T) { 19 require := require.New(t) 20 ctrl := gomock.NewController(t) 21 client := mock_ioctlclient.NewMockClient(ctrl) 22 client.EXPECT().SelectTranslation(gomock.Any()).Return("", config.English).AnyTimes() 23 cfg := config.Config{ 24 Aliases: map[string]string{ 25 "a": "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542sx", 26 "b": "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542sx", 27 "c": "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542s1", 28 }, 29 } 30 client.EXPECT().Config().Return(cfg).AnyTimes() 31 32 t.Run("list aliases", func(t *testing.T) { 33 expectedValue := "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542sx - a\n" + 34 "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542sx - b\n" + 35 "io1uwnr55vqmhf3xeg5phgurlyl702af6eju542s1 - c\n" 36 cmd := NewAliasListCmd(client) 37 result, err := util.ExecuteCmd(cmd) 38 require.NoError(err) 39 require.Equal(expectedValue, result) 40 }) 41 }