Skip to content
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: Get config cmd #3552

Merged
merged 24 commits into from
Jul 21, 2022
Merged

Task: Get config cmd #3552

merged 24 commits into from
Jul 21, 2022

Conversation

pocockn
Copy link
Contributor

@pocockn pocockn commented Jul 15, 2022

Description

Step 1: refactor command _configGetCmd into ./ioctl/newcmd/config/config_get.go
Step 2: create ./ioctl/newcmd/config/config_get_test.go to add unit test

Fixes #3467

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

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

  • make test

pocockn and others added 8 commits June 9, 2022 15:18
* 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)
  ...
@pocockn pocockn requested a review from a team as a code owner July 15, 2022 10:26
@huof6829
Copy link
Contributor

@pocockn Thanks!

@huof6829
Copy link
Contributor

Pls fix ci fail, thx.

long, _ := client.SelectTranslation(_configGetUseCmdLong)

return &cobra.Command{
Use: "VARIABLE",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"get VARIABLE" , add translate get 变量

}

func (m *endpointMessage) String() string {
if output.Format == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete output package


func (m *endpointMessage) String() string {
if output.Format == "" {
message := fmt.Sprint(m.Endpoint, " secure connect(TLS):", m.SecureConnect)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directly move to line142

defer func() {
testutil.CleanupPath(testPath)
}()
_configDir = testPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_configDir = os.TempDir()

defer func() {
testutil.CleanupPath(testPath)
}()
_configDir = testPath
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_configDir = os.TempDir()

for _, tc := range tcs {
cfgItem, err := info.get(tc.arg)
require.NoError(err)
require.Contains(cfgItem, tc.expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected data should be set before checking if no error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth implementing the config set PR before this to use that functionality here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need, here just test function get()

cfg, cfgFilePath, err := InitConfig()
info := newInfo(cfg, cfgFilePath)

tcs := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine into line50
if err!=nil {require.Contains(err.Error() }

}
}

func TestConfigGetError(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

// get retrieves a config item from its key.
func (c *info) get(arg string) (string, error) {
switch arg {
default:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to end

…task/config-get

* 'task/config-get' of github.com:pocockn/iotex-core:
  [ioctl] Build action command line into new ioctl (iotexproject#3472)
  fix potential file inclusion via variable (iotexproject#3549)
@codecov
Copy link

codecov bot commented Jul 16, 2022

Codecov Report

Merging #3552 (dc6c903) into master (a20e489) will decrease coverage by 1.34%.
The diff coverage is 51.50%.

@@            Coverage Diff             @@
##           master    #3552      +/-   ##
==========================================
- Coverage   75.43%   74.09%   -1.35%     
==========================================
  Files         247      254       +7     
  Lines       22845    23385     +540     
==========================================
+ Hits        17233    17326      +93     
- Misses       4685     5133     +448     
+ Partials      927      926       -1     
Impacted Files Coverage Δ
action/protocol/staking/read_state.go 15.38% <0.00%> (ø)
api/grpcserver.go 79.49% <ø> (+0.55%) ⬆️
blockchain/blockchain.go 0.89% <0.00%> (ø)
blockchain/filedao/filedao_legacy.go 85.80% <ø> (ø)
blockchain/filedao/filedao_v2.go 98.51% <ø> (ø)
blockchain/pubsubmanager.go 0.00% <0.00%> (ø)
config/config.go 94.06% <ø> (+9.31%) ⬆️
consensus/scheme/rolldpos/rolldposctx.go 73.47% <0.00%> (-0.18%) ⬇️
db/kvstore_impl.go 61.64% <ø> (ø)
db/kvstorewithcache.go 0.00% <0.00%> (ø)
... and 59 more

@huof6829
Copy link
Contributor

huof6829 commented Jul 19, 2022

@pocockn I set endpoint="", so line85 require.Contains(err.Error(), tc.expected) can be checked. InitConfig is done by TestInitConfig, so directly use test datas to check.

@pocockn
Copy link
Contributor Author

pocockn commented Jul 19, 2022

@pocockn I set endpoint="", so line85 require.Contains(err.Error(), tc.expected) can be checked. InitConfig is done by TestInitConfig, so directly use test datas to check.

I see what you mean now, thank you! Are there any more changes?

case "analyserEndpoint":
return c.readConfig.AnalyserEndpoint, nil
case "all":
return c.readConfig.String(), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line146 and line156 calls output's function.

func JSONString(out interface{}) string {

directly refactor it here and call. don't use output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help, done.

…task/config-get

* 'task/config-get' of github.com:pocockn/iotex-core:
  modify test
  move chanid metrics to chainservice (iotexproject#3544)
  [ioctl] fix log entries created from user input (iotexproject#3546)
  add log in rolldposctx (iotexproject#3553)
  fix uncontrolled data used in path expression (iotexproject#3547)
  [api] impl. TestGrpcServer_GetServerMeta (iotexproject#3559)
Comment on lines 140 to 141
message := endpointMessage{Endpoint: c.readConfig.Endpoint, SecureConnect: c.readConfig.SecureConnect}
return fmt.Sprint(message.Endpoint, " secure connect(TLS):", message.SecureConnect), nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete endpointMessage, directly use value in line141

}
}

type endpointMessage struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

func jsonString(out interface{}) string {
byteAsJSON, err := json.MarshalIndent(out, "", " ")
if err != nil {
log.Panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return err

@huof6829 huof6829 requested a review from Liuhaai July 20, 2022 09:02
@huof6829
Copy link
Contributor

@pocockn Thanks for your help!

Short: short,
Long: long,
ValidArgs: _validGetArgs,
Args: func(cmd *cobra.Command, args []string) error {
Copy link
Member

@Liuhaai Liuhaai Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huof6829 pls help fix args issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed. use cobra.ExactValidArgs(1)

@huof6829 huof6829 merged commit 23c6de5 into iotexproject:master Jul 21, 2022
pocockn added a commit to pocockn/iotex-core that referenced this pull request Jun 3, 2023
* upstream/master: (45 commits)
  Task: Get config cmd (iotexproject#3552)
  [ioctl] fix  Errors unhandled (iotexproject#3567)
  fix dir permission and file inclusion (iotexproject#3566)
  [test] Disable workingset cache in the benchmark test (iotexproject#3558)
  [pkg] fix  deferring unsafe method "Close" on type "*os.File" (iotexproject#3548)
  [action] Refactor handleTransfer() (iotexproject#3557)
  Add MinVersion in tls.Config (iotexproject#3562)
  [ioctl] Modify file permission as 0600 (iotexproject#3563)
  [httputil] add ReadHeaderTimeout (iotexproject#3550)
  [staking] unexport namespace (iotexproject#3551)
  move chanid metrics to chainservice (iotexproject#3544)
  [ioctl] fix log entries created from user input (iotexproject#3546)
  add log in rolldposctx (iotexproject#3553)
  fix uncontrolled data used in path expression (iotexproject#3547)
  [api] impl. TestGrpcServer_GetServerMeta (iotexproject#3559)
  [ioctl] Build action command line into new ioctl (iotexproject#3472)
  fix potential file inclusion via variable (iotexproject#3549)
  [ioctl] Incorrect conversion between integer types (iotexproject#3522)
  [action] fix incorrect conversion between integer types (iotexproject#3545)
  [test] fix TestLoadBlockchainfromDB (iotexproject#3521)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ioctl] build config get command line into new ioctl
4 participants