-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task: Reset config cmd #3496
Task: Reset config cmd #3496
Conversation
* upstream/master: (24 commits) account type with zero init nonce (iotexproject#3387) [api] Separate Server and Server Handler (iotexproject#3485) [ioctl] Build hdwallet derive command line into new ioctl (iotexproject#3418) [ioctl] Build hdwallet create command line into new ioctl (iotexproject#3470) [makefile] add go mod tidy (iotexproject#3471) [api] update chain metrics (iotexproject#3484) remove config.EVMNetworkID() (iotexproject#3460) [filedao] remove checkMasterChainDBFile() (iotexproject#3463) [api] add crashlog (iotexproject#3456) [api] Move generateBlockMeta to grpcserver.go (iotexproject#3303) [ioctl] Build action hash command line into new ioctl (iotexproject#3425) [ioctl] Build hdwallet export command line into new ioctl (iotexproject#3423) [ioctl] Refactor nodereward command in new ioctl (iotexproject#3416) [ioctl] Cleanup TestNewNodeDelegateCmd (iotexproject#3421) [blockchain] Remove BoltDBDaoOption (iotexproject#3465) remove InMemDaoOption (iotexproject#3464) [action] add evm london test (iotexproject#3402) [ioctl] create main for ioctl/newcmd (iotexproject#3296) [ioctl] Build block bucket command line into new ioctl (iotexproject#3386) [ioctl] Build hdwallet import command line into new ioctl (iotexproject#3419) ...
Codecov Report
@@ Coverage Diff @@
## master #3496 +/- ##
==========================================
- Coverage 75.43% 74.59% -0.85%
==========================================
Files 247 252 +5
Lines 22845 23133 +288
==========================================
+ Hits 17233 17255 +22
- Misses 4685 4951 +266
Partials 927 927
Continue to review full report at Codecov.
|
client.EXPECT().Config().Return(config.Config{}) | ||
apiServiceClient := mock_iotexapi.NewMockAPIServiceClient(ctrl) | ||
|
||
client.EXPECT().APIServiceClient().Return(apiServiceClient, nil).Times(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
client.EXPECT().APIServiceClient().Return(apiServiceClient, nil).Times(1) | ||
|
||
cmd := NewConfigReset(client) | ||
result, err := util.ExecuteCmd(cmd, "reset") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the failure case with returning error is not simulated or covered
- unit test for
config.reset
should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a failure case for the command and a unit test for the reset. I had to pass in the config file name into the command to be able to simulate an error, let me know what you think. Cheers
ioctl/newcmd/config/config_reset.go
Outdated
) | ||
|
||
// NewConfigReset resets the config to the default values | ||
func NewConfigReset(client ioctl.Client, defaultConfigFileName string) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete argument because user can't know file name and path of defaultConfigFileName
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can get it from client.
- add client.ConfigFilePath() in client.go
- call it in line23
ioctl/newcmd/config/config_reset.go
Outdated
Use: "reset", | ||
Short: "Reset config to default", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add Chinese translation like
iotex-core/ioctl/newcmd/node/node.go
Lines 16 to 19 in 99f0663
_nodeCmdShorts = map[config.Language]string{ | |
config.English: "Deal with nodes of IoTeX blockchain", | |
config.Chinese: "处理IoTeX区块链的节点", | |
} |
then use client.SelectTranslation()
ioctl/newcmd/config/config_reset.go
Outdated
if err != nil { | ||
return errors.Wrap(err, "failed to reset config") | ||
} | ||
cmd.Print("successfully reset config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmd.Println
ioctl/newcmd/config/config_reset.go
Outdated
info := newInfo(client.Config(), defaultConfigFileName) | ||
err := info.reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
combine in one line: newInfo(client.Config(), defaultConfigFileName).reset()
-
add unit test TestReset in config_test.go
client.EXPECT().Config().Return(config.Config{}).Times(2) | ||
|
||
t.Run("successful config reset", func(t *testing.T) { | ||
cmd := NewConfigReset(client, _defaultConfigFileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use the true file in test because it can delete the real file and can't revert. you can create temp dir using t.TempDir(), then create file under it
// use invalid file name to force error | ||
cmd := NewConfigReset(client, "\x00") | ||
_, err := util.ExecuteCmd(cmd, "reset") | ||
require.Error(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check err with expected error can be better like require.Contains(err.Error(), "expect error")
}) | ||
} | ||
|
||
func TestConfigReset(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put into config_test.go because reset() is in config.go
assert.Equal(t, ".", cfg.Wallet) | ||
assert.Equal(t, "", cfg.Endpoint) | ||
assert.Equal(t, true, cfg.SecureConnect) | ||
assert.Equal(t, "English", cfg.Language) | ||
assert.Equal(t, _defaultAnalyserEndpoint, cfg.AnalyserEndpoint) | ||
assert.Equal(t, "iotexscan", cfg.Explorer) | ||
assert.Equal(t, *new(config.Context), cfg.DefaultAccount) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.Equal
config.DefaultConfigFile = _defaultConfigFileName | ||
cfg, err := config.LoadConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Don't use global because it may modify the true config data.
- use info.loadConfig() and check data with set before by line43~49. I think this should put into TestLoadConfig. it's just unit test.
…o task/config-reset * 'task/config-reset' of github.com:pocockn/iotex-core: [consensus] remove config.EVMNetworkID() (iotexproject#3491)
ioctl/newcmd/config/config_test.go
Outdated
config.DefaultConfigFile = _defaultConfigFileName | ||
cfg, err := config.LoadConfig() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use global because it may modify the true config data.
use info.loadConfig() and check data with set data lin40~46. I think this can put into TestLoadConfig. it's just unit test.
require.NoError(err) | ||
require.Contains(result, "successfully reset config") | ||
|
||
defer testutil.CleanupPath("config.default") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for the review, I've made the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for the review, I've made the changes
Welcome! 👍
ioctl/newcmd/config/config_reset.go
Outdated
) | ||
|
||
// NewConfigReset resets the config to the default values | ||
func NewConfigReset(client ioctl.Client) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use NewConfigResetCmd
to be consistent with others
* upstream/master: (28 commits) [ioctl] Incorrect conversion between integer types (iotexproject#3522) [action] fix incorrect conversion between integer types (iotexproject#3545) [test] fix TestLoadBlockchainfromDB (iotexproject#3521) [ioctl] correct Chinese usage message (iotexproject#3510) fix err not hanled (iotexproject#3509) add ReadHeaderTimeout (iotexproject#3539) [iotcl] Reset config cmd (iotexproject#3496) Update gosec.yaml Update ci.yaml Update analysis.yaml Delete gosec.yaml.bak Create gosec.yaml [config] move config.ActPool to actpool package refactor (iotexproject#3514) Update ci.yaml Update analysis.yaml Update analysis.yaml [config] move config.Chain to blockchain package (iotexproject#3511) remove circleci (iotexproject#3498) [ioctl] Build block bucketlist command line into new ioctl (iotexproject#3469) [config] remove EVMNetworkID() and SetEVMNetworkID() (iotexproject#3503) ...
Description
Step 1: refactor command _configResetCmd into ./ioctl/newcmd/config/config_reset.go
Step 2: create ./ioctl/newcmd/config/config_reset_test.go to add unit test
Fixes #3468
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration