-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Task: Return error from keep alive methods within httputil pkg * Initial commit for get config task * Add unit tests * Remove output package, change case default to last statement within switch, improve test setup * modify test * Add jsonString method * make json string unexported * Remove message struct and return endpoint data directly * Add wrapped erorr * use ExactValidArgs() Co-authored-by: dustinxie <[email protected]> Co-authored-by: huof6890 <[email protected]>
- Loading branch information
1 parent
bc03a0e
commit 23c6de5
Showing
5 changed files
with
207 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/config" | ||
"github.com/iotexproject/iotex-core/ioctl/util" | ||
"github.com/iotexproject/iotex-core/test/mock/mock_ioctlclient" | ||
) | ||
|
||
func TestNewConfigGetCmd(t *testing.T) { | ||
require := require.New(t) | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
client := mock_ioctlclient.NewMockClient(ctrl) | ||
client.EXPECT().Config().Return(config.Config{Endpoint: "test"}).AnyTimes() | ||
client.EXPECT().SelectTranslation(gomock.Any()).Return("config reset", config.English).AnyTimes() | ||
|
||
t.Run("get config value", func(t *testing.T) { | ||
client.EXPECT().ConfigFilePath().Return(fmt.Sprintf("%s/%s", t.TempDir(), "config.file")) | ||
cmd := NewConfigGetCmd(client) | ||
result, err := util.ExecuteCmd(cmd, "endpoint") | ||
require.NoError(err) | ||
require.Contains(result, "test") | ||
}) | ||
|
||
t.Run("get unknown config value", func(t *testing.T) { | ||
cmd := NewConfigGetCmd(client) | ||
_, err := util.ExecuteCmd(cmd, "random-args") | ||
require.Contains(err.Error(), "invalid argument \"random-args\"") | ||
}) | ||
|
||
t.Run("config value error", func(t *testing.T) { | ||
client.EXPECT().ConfigFilePath().Return(fmt.Sprintf("%s/%s", t.TempDir(), "config.file")) | ||
cmd := NewConfigGetCmd(client) | ||
_, err := util.ExecuteCmd(cmd, "defaultacc") | ||
require.Contains(err.Error(), "issue fetching config value defaultacc: default account not set") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters