Get DB config from env.

This commit is contained in:
Arijit Das 2021-10-11 22:26:24 +05:30
parent 20c04a98bc
commit fcd2b963b0
4 changed files with 17 additions and 12 deletions

View File

@ -32,7 +32,7 @@ jobs:
- name: Test - name: Test
run: | run: |
sleep 10 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: integrationtest:
name: Run integration tests name: Run integration tests

View File

@ -19,6 +19,7 @@ package eth_test
import ( import (
"context" "context"
"math/big" "math/big"
"os"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -184,12 +185,13 @@ var (
// SetupDB is use to setup a db for watcher tests // SetupDB is use to setup a db for watcher tests
func SetupDB() (*postgres.DB, error) { func SetupDB() (*postgres.DB, error) {
port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT"))
uri := postgres.DbConnectionString(postgres.ConnectionParams{ uri := postgres.DbConnectionString(postgres.ConnectionParams{
User: "vdbm", User: os.Getenv("DATABASE_USER"),
Password: "password", Password: os.Getenv("DATABASE_PASSWORD"),
Hostname: "localhost", Hostname: os.Getenv("DATABASE_HOSTNAME"),
Name: "vulcanize_testing", Name: os.Getenv("DATABASE_NAME"),
Port: 8077, Port: port,
}) })
return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{})
} }

View File

@ -20,6 +20,8 @@ import (
"context" "context"
"fmt" "fmt"
"math/big" "math/big"
"os"
"strconv"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
@ -45,12 +47,13 @@ import (
// SetupDB is use to setup a db for watcher tests // SetupDB is use to setup a db for watcher tests
func SetupDB() (*postgres.DB, error) { func SetupDB() (*postgres.DB, error) {
port, _ := strconv.Atoi(os.Getenv("DATABASE_PORT"))
uri := postgres.DbConnectionString(postgres.ConnectionParams{ uri := postgres.DbConnectionString(postgres.ConnectionParams{
User: "vdbm", User: os.Getenv("DATABASE_USER"),
Password: "password", Password: os.Getenv("DATABASE_PASSWORD"),
Hostname: "localhost", Hostname: os.Getenv("DATABASE_HOSTNAME"),
Name: "vulcanize_testing", Name: os.Getenv("DATABASE_NAME"),
Port: 8077, Port: port,
}) })
return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{}) return postgres.NewDB(uri, postgres.ConnectionConfig{}, node.Info{})
} }

View File

@ -2,4 +2,4 @@
docker-compose down --remove-orphans --volumes docker-compose down --remove-orphans --volumes
docker-compose -f docker-compose.test.yml -f docker-compose.yml up -d ipld-eth-db 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 PGPASSWORD=password DATABASE_USER=vdbm DATABASE_PORT=8077 DATABASE_PASSWORD=password DATABASE_HOSTNAME=127.0.0.1 DATABASE_NAME=vulcanize_testing make test