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

Add a mock client to the cli test for Use #5203

Merged
merged 1 commit into from
Jan 4, 2016
Merged

Conversation

jsternberg
Copy link
Contributor

PR #5183 added a validation for use to only be able to select public
databases so _internal couldn't be chosen. To implement this, the
SHOW DATABASES command was used by the internal client.

Some of the unit tests in cli_test.go don't set the client to
anything. TestParseCommand_Use previous didn't, but now it needs to
have a client in the unit test with an empty test server.

@jsternberg
Copy link
Contributor Author

@otoolep @corylanou

@jsternberg
Copy link
Contributor Author

Weirdly, the panic I ran into that caused me to create this PR does not seem to happen on Circle CI.

@jsternberg
Copy link
Contributor Author

After digging deeper, I found that the unit tests on circle do not run with parallelism. If you run them seriously, the tests don't break. After trying to find out what global state was getting shared, I found that the first unit tests called os.Exit(0). I am working on a PR that removes this so the tests in this package don't get skipped.

@jsternberg jsternberg force-pushed the js-fix-use-test-panic branch from 1919011 to 2d3342f Compare December 23, 2015 20:39
@jsternberg
Copy link
Contributor Author

I have now confirmed that all unit tests run for cmd/influx/cli now run with this PR.

@jsternberg jsternberg force-pushed the js-fix-use-test-panic branch 2 times, most recently from 46254db to 1b64b07 Compare December 29, 2015 18:43
@@ -66,9 +67,11 @@ func New(version string) *CommandLine {
}

// Run executes the CLI
func (c *CommandLine) Run() {
func (c *CommandLine) Run() int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I'd rather see Run() return an error and the caller can write it out to os.Stderr. That would make it easier to evaluate which errors are returned from the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

One of the first unit tests in the cli tests called the Run method.
Since the Run method called os.Exit, it reported the unit tests as
succeeded. When parallel is set to 1, this skips _all_ unit tests after
the first one. When parallel is set to a higher value, unit tests run by
other processes still get run.

This changes the Run method to return an error (if one occurred). This
error can then be printed out and a bad exit status can be used to exit
the program from the main program instead.  That causes the unit tests
to run correctly regardless of how many parallel processes are running.

Also added an additional option to the CLI called `IgnoreSignals`. If
this is set to true, then signals are not registered with the process.
Setting signals doesn't really work in unit tests so it's good to ensure
they don't get set in the first place.

In addition to fixing the influx cli tests, this adds a mock client to
the cli test for Use. PR #5183 added a validation for `use` to only be
able to select public databases so `_internal` couldn't be chosen. To
implement this, the `SHOW DATABASES` command was used by the internal
client.

Some of the unit tests in `cli_test.go` don't set the client to
anything. `TestParseCommand_Use` previously didn't, but now it needs to
have a client in the unit test with an empty test server.
@jsternberg jsternberg force-pushed the js-fix-use-test-panic branch from 1b64b07 to 6b546cb Compare December 29, 2015 20:00
@benbjohnson
Copy link
Contributor

👍

jsternberg added a commit that referenced this pull request Jan 4, 2016
Add a mock client to the cli test for Use
@jsternberg jsternberg merged commit c825ff7 into master Jan 4, 2016
@jsternberg jsternberg deleted the js-fix-use-test-panic branch January 4, 2016 18:54
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.

3 participants