-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Introduce environment variables to customize running tests #1429
Conversation
db_test.go
Outdated
User: "postgres", | ||
Database: "postgres", | ||
User: pg.GetPGUser(), | ||
Database: pg.GetPGDatabase(), |
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 think you can leave these empty so they are auto-populated later in options.go
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.
Thanks, done.
} | ||
return pgDatabase | ||
} | ||
|
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.
Can you please unexport all these functions? I don't think they should be part of the public API.
I think we don't need these functions at all - just inline the code in options init, e.g.
if opt.Database == "" {
opt.Database = env("PGDATABASE", "postgres")
}
func env(key, defValue string) string {
}
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.
Thanks, done.
options_test.go
Outdated
@@ -132,7 +132,7 @@ func TestParseURL(t *testing.T) { | |||
}, | |||
{ | |||
"postgres://vasya:[email protected]/postgres", | |||
"somewhere.at.amazonaws.com:5432", | |||
"somewhere.at.amazonaws.com:" + GetPGPort(), |
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.
Given that these are not actually used for connections, and are purely for testing the parsing capability, i would not change any of these.
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.
Thanks. I think I went overboard with the changes, reverted.
This commit adds the support of some environment variables (namely, PGHOST, PGPORT, PGUSER, PGDATABASE, and PGSSLMODE) that override certain options when running tests. The inspiration is taken from lib/pq tests (https://www.postgresql.org/docs/9.3/libpq-envars.html). For every option, the corresponding environment variable is first checked. If it is present, then the value is used; if it is not present or empty, then we fall back to using the default values.
aec3039
to
f0bf4ea
Compare
Thank you! |
In go-pg#1429, environment variable were added to read in postgres connection details for customizing tests. This change does the same but with a password variable.
In go-pg#1429, environment variable were added to read in postgres connection details for customizing tests. This change does the same but with a password variable.
In go-pg#1429, environment variable were added to read in postgres connection details for customizing tests. This change does the same but with a password variable.
In go-pg#1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable.
In go-pg#1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable. It also removes the hardcoded user and password values from pgOptions, as Options init() will set the default if one is not specified.
In go-pg#1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable. It also removes the explicit user and password values from pgOptions, as Options init() will set it as postgres anyway if not specified, and enabling env variables to be used instead.
In go-pg#1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable. It also removes the explicit user and password values from pgOptions, as Options init() will set it as postgres anyway if not specified. This also enables env variables to be used instead for those values.
In #1429, environment variables were added to read in postgres connection details for customizing tests. This change does the same but with a password variable. It also removes the explicit user and password values from pgOptions, as Options init() will set it as postgres anyway if not specified. This also enables env variables to be used instead for those values.
This commit adds the support of some environment variables (namely,
PGHOST, PGPORT, PGUSER, PGDATABASE, and PGSSLMODE) that override
certain options when running tests. The inspiration is taken from
lib/pq tests (https://www.postgresql.org/docs/9.3/libpq-envars.html).
For every option, the corresponding environment variable is first
checked. If it is present, then the value is used; if it is not present
or empty, then we fall back to using the default values.