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

refactor: Improve CLI with test suite and builder pattern #928

Merged

Conversation

orpheuslummis
Copy link
Contributor

@orpheuslummis orpheuslummis commented Nov 1, 2022

Relevant issue(s)

Resolves #593

Description

This introduces the builder pattern, unit tests, integration testing, and removes globals.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

CI

Specify the platform(s) on which this was tested:

  • MacOS

@orpheuslummis orpheuslummis added area/testing Related to any test or testing suite area/cli Related to the CLI binary labels Nov 1, 2022
@orpheuslummis orpheuslummis added this to the DefraDB v0.4 milestone Nov 1, 2022
@orpheuslummis orpheuslummis self-assigned this Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #928 (8cecd52) into develop (75f6da8) will increase coverage by 2.57%.
The diff coverage is 45.29%.

❗ Current head 8cecd52 differs from pull request most recent head 0983d4f. Consider uploading reports for the commit 0983d4f to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #928      +/-   ##
===========================================
+ Coverage    70.57%   73.15%   +2.57%     
===========================================
  Files          185      185              
  Lines        17934    18674     +740     
===========================================
+ Hits         12657    13661    +1004     
+ Misses        4315     3976     -339     
- Partials       962     1037      +75     
Impacted Files Coverage Δ
config/errors.go 43.75% <0.00%> (-1.42%) ⬇️
cli/dump.go 11.11% <11.90%> (+6.34%) ⬆️
cli/p2p_collection_getall.go 16.21% <17.14%> (+10.15%) ⬆️
cli/p2p_collection_add.go 20.00% <20.00%> (+12.30%) ⬆️
cli/p2p_collection_remove.go 20.00% <20.00%> (+12.30%) ⬆️
cli/replicator_delete.go 23.80% <23.72%> (+12.69%) ⬆️
cli/replicator_set.go 24.59% <23.72%> (+13.05%) ⬆️
cli/schema_patch.go 32.14% <25.28%> (+28.91%) ⬆️
cli/schema_add.go 29.72% <25.55%> (+26.57%) ⬆️
cli/request.go 36.73% <28.94%> (+34.32%) ⬆️
... and 17 more

... and 20 files with indirect coverage changes

@orpheuslummis orpheuslummis changed the title refactor: Add test suite and builder pattern to CLI refactor: Improve CLI with test suite and builder pattern Nov 4, 2022
@orpheuslummis orpheuslummis added the action/no-benchmark Skips the action that runs the benchmark. label Nov 4, 2022
@sourcenetwork sourcenetwork deleted a comment from source-devs Nov 4, 2022
@orpheuslummis orpheuslummis force-pushed the orpheus/refactor/cli-builder-pattern-and-test-suite branch from bacf80f to 6334854 Compare December 16, 2022 17:41
@jsimnz jsimnz modified the milestones: DefraDB v0.4, DefraDB v0.5 Jan 20, 2023
@orpheuslummis orpheuslummis force-pushed the orpheus/refactor/cli-builder-pattern-and-test-suite branch from 6334854 to 9be4ae4 Compare March 23, 2023 01:31
@orpheuslummis orpheuslummis force-pushed the orpheus/refactor/cli-builder-pattern-and-test-suite branch 2 times, most recently from 73dbdbf to 5adb176 Compare March 30, 2023 19:49
@orpheuslummis orpheuslummis marked this pull request as ready for review March 30, 2023 19:52
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

I gave this a quick look over, skimming over the function internals (will do once mentioned bugs are fixed etc) - I like the structural changes quite a lot and it looks like a nice change overall. Is much much nicer than relying on init calls.

I am a bit nervous about merging a refactor of the CLI code so much right before the release though, especially given that it is not very well tested compared to stuff like the GQL query system. But I hope we can get this in soon :)

@jsimnz jsimnz modified the milestones: DefraDB v0.5, DefraDB v0.5.1 Apr 5, 2023
@jsimnz jsimnz added the refactor This issue specific to or requires *notable* refactoring of existing codebases and components label Apr 5, 2023
Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

Big fan of the new changes pattern. Will make things much nicer/easier moving forward.

Reviewing this PR highlighted how brittle/poor our client flow is for consuming. Really need to put together a proper HTTP and GRPC client package, that this can easily consume, instead defining/building everything inline.

But that is entirely independant of this PR work.

Leaving as a comment for now without explicit approve/request change, we can get this merged for 0.5.1 👍

cli/cli.go Show resolved Hide resolved
cli/cli.go Show resolved Hide resolved
Comment on lines +38 to +50
cred := insecure.NewCredentials()
client, err := netclient.NewClient(cfg.Net.RPCAddress, grpc.WithTransportCredentials(cred))
if err != nil {
return errors.Wrap("failed to create RPC client", err)
}

rpcTimeoutDuration, err := cfg.Net.RPCTimeoutDuration()
if err != nil {
return errors.Wrap("failed to parse RPC timeout duration", err)
}

ctx, cancel := context.WithTimeout(cmd.Context(), rpcTimeoutDuration)
defer cancel()
Copy link
Member

Choose a reason for hiding this comment

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

thought(out of scope): Just adding here to write it down. We should probably pull out the RPC client setup stuff to the root rpc command and pass the built client over the command.Context object. Will create a followup issue for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reminder of this, in case you still want to open the issue

assertContainsSubstring(t, stdout2, `schema type already exists. Name: Post`)
}

/* disabled because current implementation doesn't support this currently
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: remove commented code

Not sure what convention Source is sticking to in terms of commented code but usually it's not a good practice

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also think this should be removed if not used.

Copy link
Contributor

@islamaliev islamaliev left a comment

Choose a reason for hiding this comment

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

Change look good, but I kinda missed the "builder pattern" part

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

LGTM

@orpheuslummis
Copy link
Contributor Author

LGTM

Im rebasing, resolving conflicts, then I'll merge tomorrow

@orpheuslummis orpheuslummis force-pushed the orpheus/refactor/cli-builder-pattern-and-test-suite branch from 5dfb279 to 226ab35 Compare April 24, 2023 04:23
@orpheuslummis
Copy link
Contributor Author

There was a few issues, related to the rootdir, and test commands to run a defradb node goroutine or to run a defra command, which I've fixed in the latest rebase. I suggest this has a last round of review before being merged.

@fredcarle
Copy link
Collaborator

There was a few issues, related to the rootdir, and test commands to run a defradb node goroutine or to run a defra command, which I've fixed in the latest rebase. I suggest this has a last round of review before being merged.

Is there a specific commit that has those?

@orpheuslummis
Copy link
Contributor Author

orpheuslummis commented Apr 24, 2023

There was a few issues, related to the rootdir, and test commands to run a defradb node goroutine or to run a defra command, which I've fixed in the latest rebase. I suggest this has a last round of review before being merged.

Is there a specific commit that has those?

this commit orpheuslummis@ec46190
and resolving some merge conflicts in earlier commits..

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few comments that I'd suggest resolving before merge.

cli/root.go Show resolved Hide resolved
tests/integration/cli/client_rpc_replicator_test.go Outdated Show resolved Hide resolved
assertContainsSubstring(t, stdout2, `schema type already exists. Name: Post`)
}

/* disabled because current implementation doesn't support this currently
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also think this should be removed if not used.

@orpheuslummis
Copy link
Contributor Author

orpheuslummis commented Apr 25, 2023

I also think this should be removed if not used.

oops, I thought I had removed it.

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

LGTM, good work Orpheus :)

@orpheuslummis orpheuslummis force-pushed the orpheus/refactor/cli-builder-pattern-and-test-suite branch from 8cecd52 to 0983d4f Compare April 25, 2023 18:15
@orpheuslummis orpheuslummis merged commit df0d323 into develop Apr 25, 2023
@orpheuslummis orpheuslummis deleted the orpheus/refactor/cli-builder-pattern-and-test-suite branch April 25, 2023 18:24
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary area/testing Related to any test or testing suite refactor This issue specific to or requires *notable* refactoring of existing codebases and components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI: test suite
5 participants