-
Notifications
You must be signed in to change notification settings - Fork 72
test: Add example CLI integration tests #3550
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
test: Add example CLI integration tests #3550
Conversation
ebe5d14 to
d78645e
Compare
816afa2 to
6d510ab
Compare
islamaliev
left a comment
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.
Look very nice, Andy! I'm happy with the changes in general. Have some suggestions and questions.
cli/test/action/action.go
Outdated
| // | ||
| // It is typically used by multipliers in order to provide additional args to Actions | ||
| // implementing this interface. | ||
| type Argmented interface { |
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.
question: is it a word? Didn't you want to write "Augmented"?
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 guess I did 😁
- Use correct spelling
| func execute(ctx context.Context, args []string) error { | ||
| stdOut, stdErr, err := executeStream(ctx, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = io.ReadAll(stdOut) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| stdErrData, err := io.ReadAll(stdErr) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if len(stdErrData) != 0 { | ||
| return fmt.Errorf("%s", stdErrData) | ||
| } | ||
| return nil | ||
| } |
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.
suggestion: this block is almost identical to the executeBytes. I would strongly suggest wrap it:
func execute(ctx context.Context, args []string) error {
_, err := executeBytes(ctx, args)
return 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.
Ah of course, thanks Islam, is a silly mistake of mine :)
- Cleanup
execute
| result, err := executeJson[[]client.CollectionDefinition](a.s.Ctx, args) | ||
| require.NoError(a.s.T, err) | ||
|
|
||
| require.Equal(a.s.T, len(a.Expected), len(result)) |
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.
note: these assets won't make it easy to spot the failing action (if there are several, like create doc).
Would be nice add something like CodeLocation in ginkgo. But it's probably for a later ticket.
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 agree, we use something similar in the main integration test framework (assertStack), I'd like to use that here but didn't want to spend the time right now.
cli/test/action/start.go
Outdated
| listener, err := net.Listen("tcp", "127.0.0.1:0") | ||
| require.NoError(a.s.T, err) | ||
|
|
||
| args := []string{"start", "--no-keyring", "--store=memory"} |
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.
question: why are these args hard-coded? What if want to play around with keyring cli tests?
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.
Just a temporary thing, I didn't want to setup whatever would be needed (multipliers) to allow these to change without code changes.
cli/test/multiplier/txn.go
Outdated
| if argumentedAction, ok := a.(action.ArgmentedAction); ok && i > lastStartIndex { | ||
| result = append(result, action.WithTxn(argumentedAction)) | ||
| } else { | ||
| result = append(result, a) | ||
| } |
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.
todo: I believe we should document this not quite explicit behaviour: wrapping only action.ArgmentedAction-compliant actions with transaction and skipping the rest.
And also the fact that the transaction is being created after Start command and commit is added to the end. Would be nice to have a general comment for the multiplier that mentions all that.
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 thought I added documentation, but I guess I only intended too... Thanks for flagging Islam :)
- Document txn multiplier
cli/test/multiplier/txn.go
Outdated
|
|
||
| switch a.(type) { | ||
| // Append orginal, read-only actions that occured after the last write action, | ||
| // after the transaction has been commited. This allows the automatic of whether |
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.
nitpick: I think a work is missing after "automatic"
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.
yes :) Thanks
- Add missing word(s?)
| case *action.SchemaAdd: | ||
| lastWriteIndex = i |
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.
suggestion: this part, I guess, check if the current action is read-only or not and the list will grow when we add more write actions, right? Would be nice to have a comment here mentioning that.
Better yet, to have a ticket about some proper handling of read-only action and linking it here.
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.
Will add
- Document
lastWriteIndex
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.
This documentation has been added to the multiplier-level documentation, not the internal implementation/variable
cli/test/multiplier/txn.go
Outdated
| switch a.(type) { | ||
| // Append orginal, read-only actions that occured after the last write action, | ||
| // after the transaction has been commited. This allows the automatic of whether | ||
| // or not the transaction-state has been persisted. |
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.
suggestion: very helpful comment. Please include this also in the documentation for the multiplier.
cli/test/state/state.go
Outdated
|
|
||
| type State struct { | ||
| Ctx context.Context | ||
| Cancels []context.CancelFunc |
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.
suggestion: this term feel a bit unnatural for the testing. I think it would be better to all is something like Cleanup or TearDown. And maybe it can be of type []func() to make it more generic.
Anyway a comment also would be nice here.
question: does it need to be public? Maybe it's would be better to add a public append-only method?
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.
does it need to be public? Maybe it's would be better to add a public append-only method?
At the moment it only really gets added here because the linter demands that the timeout cancel is referenced, and while I was building this at somepoint it was used.
I think I'll remove it and add a //nolint instead
- Remove Cancels
80d40ed to
61dc9d1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3550 +/- ##
===========================================
+ Coverage 78.62% 78.64% +0.02%
===========================================
Files 396 405 +9
Lines 36722 37019 +297
===========================================
+ Hits 28872 29112 +240
- Misses 6151 6177 +26
- Partials 1699 1730 +31
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 21 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
7b33d47 to
a0581fb
Compare
The default is 'none' as that is what the docs/config.md says it should be.
CrossLock only works when everything else is using it, and other test suites do not - this meant they were occassionally clashing with the CLI tests.
I have failed to find out why, but somehow, when the source-hub test job executes the cli tests it manages to change the default behaviour and start up defra with source-hub acp, which doesn't work as the keyring is disabled.
f1d6163 to
bb215b0
Compare
bb215b0 to
16c02c4
Compare
## Relevant issue(s) Resolves sourcenetwork#3551 ## Description Only give badger a path if not in-memory. Credit for fix belongs to Keenan not me. I broke this bringing corekv in. Keenan fixed this, I'm just doing the typing. This is tested in sourcenetwork#3550
## Relevant issue(s) Resolves sourcenetwork#3569 ## Description Adds the example CLI integration tests using new test framework. Largely as seen in the demo last week, but with a little more polish. I think it is good to commit these now and then we can expand them as/when we feel like, and use it as an example for other user-facing stuff (like http). I have not added the txn-commit multiplier to the CI, as the workflow test files are fairly coupled to executing all tests in the entire repository and I wanted to limit scope here. ## Tasks - [x] The testing repo dependency is currently a local, relative, path and needs to be pointed at https://github.com/sourcenetwork/testing when sourcenetwork/testo#1 gets merged. - [x] Link this to a proper issue if/when sourcenetwork/testo#1 is merged
Relevant issue(s)
Resolves #3569
Description
Adds the example CLI integration tests using new test framework.
Largely as seen in the demo last week, but with a little more polish. I think it is good to commit these now and then we can expand them as/when we feel like, and use it as an example for other user-facing stuff (like http).
I have not added the txn-commit multiplier to the CI, as the workflow test files are fairly coupled to executing all tests in the entire repository and I wanted to limit scope here.
Tasks