-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
USE databasename will work only for existing databases. #5183
Conversation
Also, I'd like to know why |
@pires |
@beckettsean indeed, thank you. Does this LGTY? |
@pires again I can't qualify Go code, but it looks like the right approach. It might be a little weird to get error messages for a
|
fmt.Printf("Using database %s\n", d) | ||
|
||
// validate if specified database exists | ||
query := "SHOW DATABASES" |
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.
Very minor, but just shove SHOW DATABASES
inside the call to Query
. A new variable isn't really needed, don't you agree?
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.
Agreed.
Works for me, some minor improvements suggested. +1 |
+1. |
@beckettsean you may find issues with the database that are not related to the database not existing. Said verifications follow the same pattern as other queries. |
@corylanou @otoolep comments addressed. Thank you! |
USE databasename will work only for existing databases.
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.
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.
Fixes #5174
Unfortunately, I don't see a way of testing this without implementing some database behavior on
cli_test.go
, namely to return one existing database.