Skip to content

Commit 1eccdba

Browse files
authored
Merge pull request #19 from usernameisnull/remove-pg-env
remove pg_ and PG env
2 parents 6546ce0 + 64b89e2 commit 1eccdba

File tree

13 files changed

+121
-120
lines changed

13 files changed

+121
-120
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ jobs:
6767
- name: Run tests
6868
env:
6969
IS_OPENGAUSS: true
70-
PGDATABASE: pgx_test
71-
PGPORT: 5432
72-
PGUSER: gaussdb
73-
PGHOST: localhost
74-
POSTGRESQL_DATA_DIR: /var/lib/opengauss/data
75-
GAUSSDB_TEST_CRATEDB_CONN_STRING: "host=localhost port=${{ env.PORT }} user=gaussdb dbname=pgx_test password=${{ env.OPENGAUSS_PASSWORD }}"
76-
GAUSSDB_TEST_DATABASE: "host=localhost database=pgx_test user=pgx_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
77-
GAUSSDB_TEST_MD5_PASSWORD_CONN_STRING: "host=localhost database=pgx_test user=pgx_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
78-
GAUSSDB_TEST_PLAIN_PASSWORD_CONN_STRING: "host=localhost user=pgx_pw password=${{ env.OPENGAUSS_PASSWORD }}"
79-
GAUSSDB_TEST_SCRAM_PASSWORD_CONN_STRING: "host=localhost user=pgx_scram database=pgx_test password=${{ env.OPENGAUSS_PASSWORD }}"
80-
GAUSSDB_TEST_TCP_CONN_STRING: "host=localhost database=pgx_test user=pgx_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
70+
GAUSSDB_DATABASE: gaussdbgo_test
71+
GAUSSDB_PORT: 5432
72+
GAUSSDB_USER: gaussdb
73+
GAUSSDB_HOST: localhost
74+
GAUSSDB_DATA_DIR: /var/lib/opengauss/data
75+
GAUSSDB_TEST_CRATEDB_CONN_STRING: "host=localhost port=${{ env.PORT }} user=gaussdb dbname=gaussdbgo_test password=${{ env.OPENGAUSS_PASSWORD }}"
76+
GAUSSDB_TEST_DATABASE: "host=localhost database=gaussdbgo_test user=gaussdbgo_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
77+
GAUSSDB_TEST_MD5_PASSWORD_CONN_STRING: "host=localhost database=gaussdbgo_test user=gaussdbgo_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
78+
GAUSSDB_TEST_PLAIN_PASSWORD_CONN_STRING: "host=localhost user=gaussdbgo_pw password=${{ env.OPENGAUSS_PASSWORD }}"
79+
GAUSSDB_TEST_SCRAM_PASSWORD_CONN_STRING: "host=localhost user=gaussdbgo_scram database=gaussdbgo_test password=${{ env.OPENGAUSS_PASSWORD }}"
80+
GAUSSDB_TEST_TCP_CONN_STRING: "host=localhost database=gaussdbgo_test user=gaussdbgo_md5 password=${{ env.OPENGAUSS_PASSWORD }}"
8181
# parallel testing is disabled because somehow parallel testing causes Github Actions to kill the runner.
8282
run: go test -parallel=1 -race ./...
8383

CONTRIBUTING.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ that adds a dependency is no.
1414

1515
gaussdb-go tests naturally require a GaussDB database. It will connect to the database specified in the `GAUSSDB_TEST_DATABASE`
1616
environment variable. The `GAUSSDB_TEST_DATABASE` environment variable can either be a URL or key-value pairs. In addition,
17-
the standard `PG*` environment variables will be respected. Consider using [direnv](https://github.com/direnv/direnv) to
18-
simplify environment variable handling.
17+
the standard `GAUSSDB_*` environment variables will be respected.
1918

2019
### Using an Existing GaussDB Cluster
2120

@@ -26,14 +25,14 @@ authentication methods).
2625
Create and setup a test database:
2726

2827
```
29-
gsql -c 'create database pgx_test DBCOMPATIBILITY 'PG'; create extension hstore;'
28+
gsql -c 'create database gaussdbgo_test DBCOMPATIBILITY 'PG'; create extension hstore;'
3029
```
3130

3231
```
3332
Ensure your `GAUSSDB_TEST_DATABASE` environment variable points to the database you just created and run the tests.
3433
3534
```
36-
export GAUSSDB_TEST_DATABASE="host='your gaussdb host' database=pgx_test"
35+
export GAUSSDB_TEST_DATABASE="host='your gaussdb host' database=gaussdbgo_test"
3736
go test ./...
3837
```
3938
@@ -45,20 +44,20 @@ The following environment variables need to be set both for initial setup and wh
4544
highly recommended). Depending on your platform, you may need to change the host for `GAUSSDB_TEST_UNIX_SOCKET_CONN_STRING`.
4645
4746
```
48-
export PGPORT=5015
49-
export PGUSER=root
50-
export PGDATABASE=pgx_test
51-
export POSTGRESQL_DATA_DIR=GaussDB
52-
53-
export GAUSSDB_TEST_DATABASE="host=127.0.0.1 database=pgx_test user=pgx_md5 password=secret"
54-
export GAUSSDB_TEST_UNIX_SOCKET_CONN_STRING="host=/private/tmp database=pgx_test"
55-
export GAUSSDB_TEST_TCP_CONN_STRING="host=127.0.0.1 database=pgx_test user=pgx_md5 password=secret"
56-
export GAUSSDB_TEST_SCRAM_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_scram password=secret database=pgx_test"
57-
export GAUSSDB_TEST_MD5_PASSWORD_CONN_STRING="host=127.0.0.1 database=pgx_test user=pgx_md5 password=secret"
58-
export GAUSSDB_TEST_PLAIN_PASSWORD_CONN_STRING="host=127.0.0.1 user=pgx_pw password=secret"
59-
export GAUSSDB_TEST_TLS_CONN_STRING="host=localhost user=pgx_ssl password=secret sslmode=verify-full sslrootcert=`pwd`/.testdb/ca.pem"
47+
export GAUSSDB_PORT=5015
48+
export GAUSSDB_USER=root
49+
export GAUSSDB_DATABASE=gaussdbgo_test
50+
export GAUSSDB_DATA_DIR=/var/lib/opengauss/data
51+
52+
export GAUSSDB_TEST_DATABASE="host=127.0.0.1 database=gaussdbgo_test user=gaussdbgo_md5 password=secret"
53+
export GAUSSDB_TEST_UNIX_SOCKET_CONN_STRING="host=/private/tmp database=gaussdbgo_test"
54+
export GAUSSDB_TEST_TCP_CONN_STRING="host=127.0.0.1 database=gaussdbgo_test user=gaussdbgo_md5 password=secret"
55+
export GAUSSDB_TEST_SCRAM_PASSWORD_CONN_STRING="host=127.0.0.1 user=gaussdbgo_scram password=secret database=gaussdbgo_test"
56+
export GAUSSDB_TEST_MD5_PASSWORD_CONN_STRING="host=127.0.0.1 database=gaussdbgo_test user=gaussdbgo_md5 password=secret"
57+
export GAUSSDB_TEST_PLAIN_PASSWORD_CONN_STRING="host=127.0.0.1 user=gaussdbgo_pw password=secret"
58+
export GAUSSDB_TEST_TLS_CONN_STRING="host=localhost user=gaussdbgo_ssl password=secret sslmode=verify-full sslrootcert=`pwd`/.testdb/ca.pem"
6059
export GAUSSDB_SSL_PASSWORD=certpw
61-
export GAUSSDB_TEST_TLS_CLIENT_CONN_STRING="host=localhost user=pgx_sslcert sslmode=verify-full sslrootcert=`pwd`/.testdb/ca.pem database=pgx_test sslcert=`pwd`/.testdb/pgx_sslcert.crt sslkey=`pwd`/.testdb/pgx_sslcert.key"
60+
export GAUSSDB_TEST_TLS_CLIENT_CONN_STRING="host=localhost user=gaussdbgo_sslcert sslmode=verify-full sslrootcert=`pwd`/.testdb/ca.pem database=gaussdbgo_test sslcert=`pwd`/.testdb/gaussdbgo_sslcert.crt sslkey=`pwd`/.testdb/gaussdbgo_sslcert.key"
6261
```
6362
6463
Create a new database cluster.
@@ -67,7 +66,7 @@ Create a new database cluster.
6766
initdb --locale=en_US -E UTF-8 --username=postgres .testdb/$POSTGRESQL_DATA_DIR
6867

6968
echo "listen_addresses = '127.0.0.1'" >> .testdb/$POSTGRESQL_DATA_DIR/GaussDB.conf
70-
echo "port = $PGPORT" >> .testdb/$POSTGRESQL_DATA_DIR/GaussDB.conf
69+
echo "port = $GAUSSDB_PORT" >> .testdb/$POSTGRESQL_DATA_DIR/GaussDB.conf
7170
cat testsetup/postgresql_ssl.conf >> .testdb/$POSTGRESQL_DATA_DIR/GaussDB.conf
7271
cp testsetup/pg_hba.conf .testdb/$POSTGRESQL_DATA_DIR/pg_hba.conf
7372

@@ -101,7 +100,7 @@ psql --no-psqlrc -f testsetup/postgresql_setup.sql
101100
102101
### Optional Tests
103102
104-
gaussdb-go supports multiple connection types and means of authentication. These tests are optional. They will only run if the
105-
appropriate environment variables are set. In addition, there may be tests specific to particular GaussDB versions,
103+
gaussdb-go supports multiple connection types and means of authentication. These tests are optional. They will only run
104+
if theappropriate environment variables are set. In addition, there may be tests specific to particular GaussDB versions,
106105
non-GaussDB servers (e.g. CockroachDB), or connection poolers (e.g. PgBouncer). `go test ./... -v | grep SKIP` to see
107106
if any tests are being skipped.

ci/initialize_database.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
# verify_sql_user_connection: verify that the username and password created using the SQL file can connect to the database.
2121
function verify_sql_created_user_connection() {
22-
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U pgx_md5 -p ${port} -W${password} -d pgx_test -c \"select version(); show server_version;\"'"
22+
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U gaussdbgo_md5 -p ${port} -W${password} -d gaussdbgo_test -c \"select version(); show server_version;\"'"
2323
}
2424

2525
sleep ${interval_check_time}
@@ -42,7 +42,7 @@ while [ $retry_count -lt $max_retries ]; do
4242
if [ $status -eq 0 ]; then
4343
# replace password
4444
sudo sed -i "s/'{{OPENGAUSS_PASSWORD}}'/'${password}'/" "${mounted_dir}/${sql_file}"
45-
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U omm -c \"CREATE DATABASE pgx_test DBCOMPATIBILITY 'pg';\" -f ${mounted_dir}/${sql_file}'"
45+
docker exec -i ${TTY_FLAG} "${container_name}" bash -c "su - omm -c 'gsql -U omm -c \"CREATE DATABASE gaussdbgo_test DBCOMPATIBILITY 'pg';\" -f ${mounted_dir}/${sql_file}'"
4646
echo "Database initialization completed."
4747
verify_sql_created_user_connection
4848
exit 0

conn_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,15 +1010,15 @@ func TestLoadTypeSameNameInDifferentSchemas(t *testing.T) {
10101010
require.NoError(t, err)
10111011
defer tx.Rollback(ctx)
10121012

1013-
_, err = tx.Exec(ctx, `create schema pgx_a;
1014-
create type pgx_a.point as (a text, b text);
1015-
create schema pgx_b;
1016-
create type pgx_b.point as (c text);
1013+
_, err = tx.Exec(ctx, `create schema gaussdbgo_a;
1014+
create type gaussdbgo_a.point as (a text, b text);
1015+
create schema gaussdbgo_b;
1016+
create type gaussdbgo_b.point as (c text);
10171017
`)
10181018
require.NoError(t, err)
10191019

10201020
// Register types
1021-
for _, typename := range []string{"pgx_a.point", "pgx_b.point"} {
1021+
for _, typename := range []string{"gaussdbgo_a.point", "gaussdbgo_b.point"} {
10221022
// Obviously using conn while a tx is in use and registering a type after the connection has been established are
10231023
// really bad practices, but for the sake of convenience we do it in the test here.
10241024
dt, err := conn.LoadType(ctx, typename)
@@ -1037,7 +1037,7 @@ create type pgx_b.point as (c text);
10371037

10381038
var a aPoint
10391039
var b bPoint
1040-
err = tx.QueryRow(ctx, `select '(foo,bar)'::pgx_a.point, '(baz)'::pgx_b.point`).Scan(&a, &b)
1040+
err = tx.QueryRow(ctx, `select '(foo,bar)'::gaussdbgo_a.point, '(baz)'::gaussdbgo_b.point`).Scan(&a, &b)
10411041
require.NoError(t, err)
10421042
require.Equal(t, aPoint{"foo", "bar"}, a)
10431043
require.Equal(t, bPoint{"baz"}, b)

examples/chat/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ between them.
88

99
## Connection configuration
1010

11-
The database connection is configured via DATABASE_URL and standard GaussDB environment variables (PGHOST, PGUSER, etc.)
11+
The database connection is configured via DATABASE_URL and standard GaussDB environment variables (GAUSSDB_HOST, GAUSSDB_USER, etc.)
1212

1313
You can either export them then run chat:
1414

15-
export PGHOST=/private/tmp
15+
export GAUSSDB_HOST=/private/tmp
1616
./chat
1717

1818
Or you can prefix the chat execution with the environment variables:
1919

20-
PGHOST=/private/tmp ./chat
20+
GAUSSDB_HOST=/private/tmp ./chat

examples/todo/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ Build todo:
1919

2020
## Connection configuration
2121

22-
The database connection is configured via DATABASE_URL and standard GaussDB environment variables (PGHOST, PGUSER, etc.)
22+
The database connection is configured via DATABASE_URL and standard GaussDB environment variables (GAUSSDB_HOST, GAUSSDB_USER, etc.)
2323

2424
You can either export them then run todo:
2525

26-
export PGDATABASE=todo
26+
export GAUSSDB_DATABASE=todo
2727
./todo list
2828

2929
Or you can prefix the todo execution with the environment variables:
3030

31-
PGDATABASE=todo ./todo list
31+
GAUSSDB_DATABASE=todo ./todo list
3232

3333
## Add a todo item
3434

@@ -55,7 +55,7 @@ Or you can prefix the todo execution with the environment variables:
5555
CREATE TABLE
5656
Time: 6.363 ms
5757
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ go build
58-
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ export PGDATABASE=todo
58+
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ export GAUSSDB_DATABASE=todo
5959
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ ./todo list
6060
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ ./todo add 'Learn Go'
6161
jack@hk-47~/dev/go/src/github.com/HuaweiCloudDeveloper/gaussdb-go/examples/todo$ ./todo list

gaussdbconn/config.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func isAbsolutePath(path string) bool {
152152
func NetworkAddress(host string, port uint16) (network, address string) {
153153
if isAbsolutePath(host) {
154154
network = "unix"
155+
// opengauss still use this name, don't change it.
155156
address = filepath.Join(host, ".s.PGSQL.") + strconv.FormatInt(int64(port), 10)
156157
} else {
157158
network = "tcp"
@@ -161,7 +162,7 @@ func NetworkAddress(host string, port uint16) (network, address string) {
161162
}
162163

163164
// ParseConfig builds a *Config from connString with similar behavior to the GaussDB standard C library libpq. It
164-
// uses the same defaults as libpq (e.g. port=5432) and understands most PG* environment variables. ParseConfig closely
165+
// uses the same defaults as libpq (e.g. port=5432) and understands most GAUSSDB_* environment variables. ParseConfig closely
165166
// matches the parsing behavior of libpq. connString may either be in URL format or keyword = value format.
166167
//
167168
// # Example Keyword/Value
@@ -184,22 +185,22 @@ func NetworkAddress(host string, port uint16) (network, address string) {
184185
// ParseConfig currently recognizes the following environment variable and their parameter key word equivalents passed
185186
// via database URL or keyword/value:
186187
//
187-
// PGHOST
188-
// PGPORT
189-
// PGDATABASE
190-
// PGUSER
191-
// PGPASSWORD
192-
// PGPASSFILE
193-
// PGSERVICE
194-
// PGSERVICEFILE
195-
// PGSSLMODE
196-
// PGSSLCERT
197-
// PGSSLKEY
198-
// PGSSLROOTCERT
199-
// PGSSLPASSWORD
200-
// PGAPPNAME
201-
// PGCONNECT_TIMEOUT
202-
// PGTARGETSESSIONATTRS
188+
// GAUSSDB_HOST
189+
// GAUSSDB_PORT
190+
// GAUSSDB_DATABASE
191+
// GAUSSDB_USER
192+
// GAUSSDB_PASSWORD
193+
// GAUSSDB_PASSFILE
194+
// GAUSSDB_SERVICE
195+
// GAUSSDB_SERVICEFILE
196+
// GAUSSDB_SSLMODE
197+
// GAUSSDB_SSLCERT
198+
// GAUSSDB_SSLKEY
199+
// GAUSSDB_SSLROOTCERT
200+
// GAUSSDB_SSLPASSWORD
201+
// GAUSSDB_APPNAME
202+
// GAUSSDB_CONNECT_TIMEOUT
203+
// GAUSSDB_TARGETSESSIONATTRS
203204
//
204205
// The sslmode "prefer" (the default), sslmode "allow", and multiple hosts are implemented via the Fallbacks field of
205206
// the Config struct. If TLSConfig is manually changed it will not affect the fallbacks. For example, in the case of
@@ -211,7 +212,7 @@ func NetworkAddress(host string, port uint16) (network, address string) {
211212
// In addition, ParseConfig accepts the following options:
212213
//
213214
// - servicefile.
214-
// libpq only reads servicefile from the PGSERVICEFILE environment variable. ParseConfig accepts servicefile as a
215+
// libpq only reads servicefile from the GAUSSDB_SERVICEFILE environment variable. ParseConfig accepts servicefile as a
215216
// part of the connection string.
216217
func ParseConfig(connString string) (*Config, error) {
217218
var parseConfigOptions ParseConfigOptions
@@ -420,23 +421,23 @@ func parseEnvSettings() map[string]string {
420421
settings := make(map[string]string)
421422

422423
nameMap := map[string]string{
423-
"PGHOST": "host",
424-
"PGPORT": "port",
425-
"PGDATABASE": "database",
426-
"PGUSER": "user",
427-
"PGPASSWORD": "password",
428-
"PGPASSFILE": "passfile",
429-
"PGAPPNAME": "application_name",
430-
"PGCONNECT_TIMEOUT": "connect_timeout",
431-
"PGSSLMODE": "sslmode",
432-
"PGSSLKEY": "sslkey",
433-
"PGSSLCERT": "sslcert",
434-
"PGSSLSNI": "sslsni",
435-
"PGSSLROOTCERT": "sslrootcert",
436-
"PGSSLPASSWORD": "sslpassword",
437-
"PGTARGETSESSIONATTRS": "target_session_attrs",
438-
"PGSERVICE": "service",
439-
"PGSERVICEFILE": "servicefile",
424+
"GAUSSDB_HOST": "host",
425+
"GAUSSDB_PORT": "port",
426+
"GAUSSDB_DATABASE": "database",
427+
"GAUSSDB_USER": "user",
428+
"GAUSSDB_PASSWORD": "password",
429+
"GAUSSDB_PASSFILE": "passfile",
430+
"GAUSSDB_APPNAME": "application_name",
431+
"GAUSSDB_CONNECT_TIMEOUT": "connect_timeout",
432+
"GAUSSDB_SSLMODE": "sslmode",
433+
"GAUSSDB_SSLKEY": "sslkey",
434+
"GAUSSDB_SSLCERT": "sslcert",
435+
"GAUSSDB_SSLSNI": "sslsni",
436+
"GAUSSDB_SSLROOTCERT": "sslrootcert",
437+
"GAUSSDB_SSLPASSWORD": "sslpassword",
438+
"GAUSSDB_TARGETSESSIONATTRS": "target_session_attrs",
439+
"GAUSSDB_SERVICE": "service",
440+
"GAUSSDB_SERVICEFILE": "servicefile",
440441
}
441442

442443
for envname, realname := range nameMap {

0 commit comments

Comments
 (0)