From fcd2b963b013f7eade35e5d09fdf9fd732ff87e5 Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Mon, 11 Oct 2021 22:26:24 +0530 Subject: [PATCH] Get DB config from env. --- .github/workflows/on-pr.yaml | 2 +- pkg/eth/api_test.go | 12 +++++++----- pkg/graphql/graphql_test.go | 13 ++++++++----- scripts/run_unit_test.sh | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/on-pr.yaml b/.github/workflows/on-pr.yaml index fd1d8001..d33adc7a 100644 --- a/.github/workflows/on-pr.yaml +++ b/.github/workflows/on-pr.yaml @@ -32,7 +32,7 @@ jobs: - name: Test run: | sleep 10 - PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 make test + PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test integrationtest: name: Run integration tests diff --git a/pkg/eth/api_test.go b/pkg/eth/api_test.go index fa5025c2..13a6336b 100644 --- a/pkg/eth/api_test.go +++ b/pkg/eth/api_test.go @@ -19,6 +19,7 @@ package eth_test import ( "context" "math/big" + "os" "strconv" "github.com/ethereum/go-ethereum/common" @@ -184,12 +185,13 @@ var ( // SetupDB is use to setup a db for watcher tests func SetupDB() (*postgres.DB, error) { + port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) uri := postgres.DbConnectionString(postgres.ConnectionParams{ - User: "vdbm", - Password: "password", - Hostname: "localhost", - Name: "vulcanize_testing", - Port: 8077, + User: os.Getenv("DATABASE_USER"), + Password: os.Getenv("DATABASE_PASSWORD"), + Hostname: os.Getenv("DATABASE_HOSTNAME"), + Name: os.Getenv("DATABASE_NAME"), + Port: port, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) } diff --git a/pkg/graphql/graphql_test.go b/pkg/graphql/graphql_test.go index 68e394db..ceb87c9d 100644 --- a/pkg/graphql/graphql_test.go +++ b/pkg/graphql/graphql_test.go @@ -20,6 +20,8 @@ import ( "context" "fmt" "math/big" + "os" + "strconv" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -45,12 +47,13 @@ import ( // SetupDB is use to setup a db for watcher tests func SetupDB() (*postgres.DB, error) { + port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT")) uri := postgres.DbConnectionString(postgres.ConnectionParams{ - User: "vdbm", - Password: "password", - Hostname: "localhost", - Name: "vulcanize_testing", - Port: 8077, + User: os.Getenv("DATABASE_USER"), + Password: os.Getenv("DATABASE_PASSWORD"), + Hostname: os.Getenv("DATABASE_HOSTNAME"), + Name: os.Getenv("DATABASE_NAME"), + Port: port, }) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) } diff --git a/scripts/run_unit_test.sh b/scripts/run_unit_test.sh index 703fcef8..bcbeced7 100755 --- a/scripts/run_unit_test.sh +++ b/scripts/run_unit_test.sh @@ -2,4 +2,4 @@ docker-compose down --remove-orphans --volumes docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db -PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 make test \ No newline at end of file +PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test \ No newline at end of file