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

Introduce environment variables to customize running tests #1429

Merged
merged 1 commit into from
Oct 27, 2019

Conversation

yuzefovich
Copy link
Contributor

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.

db_test.go Outdated
User: "postgres",
Database: "postgres",
User: pg.GetPGUser(),
Database: pg.GetPGDatabase(),
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, done.

}
return pgDatabase
}

Copy link
Member

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 {
}

Copy link
Contributor Author

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:pupkin@somewhere.at.amazonaws.com/postgres",
"somewhere.at.amazonaws.com:5432",
"somewhere.at.amazonaws.com:" + GetPGPort(),
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
@vmihailenco
Copy link
Member

Thank you!

@vmihailenco vmihailenco merged commit f757238 into go-pg:master Oct 27, 2019
@yuzefovich yuzefovich deleted the add-test-env-vars branch October 28, 2019 03:15
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
DarrylWong added a commit to DarrylWong/pg that referenced this pull request Jan 23, 2024
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.
elliotcourant pushed a commit that referenced this pull request Jan 23, 2024
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.
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