Fix ent-based postgres storage tests

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
m.nabokikh 2021-05-15 08:32:43 +04:00
parent 19884d92ac
commit 49adc4e5bb
3 changed files with 30 additions and 10 deletions

View file

@ -20,6 +20,12 @@ jobs:
- 5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
postgres-ent:
image: postgres:10.8
ports:
- 5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mysql:
image: mysql:5.7
env:
@ -70,6 +76,11 @@ jobs:
DEX_POSTGRES_PASSWORD: postgres
DEX_POSTGRES_HOST: localhost
DEX_POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
DEX_POSTGRES_ENT_DATABASE: postgres
DEX_POSTGRES_ENT_USER: postgres
DEX_POSTGRES_ENT_PASSWORD: postgres
DEX_POSTGRES_ENT_HOST: localhost
DEX_POSTGRES_ENT_PORT: ${{ job.services.postgres-ent.ports[5432] }}
DEX_ETCD_ENDPOINTS: http://localhost:${{ job.services.etcd.ports[2379] }}
DEX_LDAP_HOST: localhost
DEX_LDAP_PORT: 389

View file

@ -11,10 +11,11 @@ import (
"strings"
"time"
entSQL "entgo.io/ent/dialect/sql"
// Register postgres driver.
_ "github.com/lib/pq"
entSQL "entgo.io/ent/dialect/sql"
"github.com/dexidp/dex/pkg/log"
"github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/ent/client"

View file

@ -12,6 +12,14 @@ import (
"github.com/dexidp/dex/storage/conformance"
)
const (
PostgresEntHostEnv = "DEX_POSTGRES_ENT_HOST"
PostgresEntPortEnv = "DEX_POSTGRES_ENT_PORT"
PostgresEntDatabaseEnv = "DEX_POSTGRES_ENT_DATABASE"
PostgresEntUserEnv = "DEX_POSTGRES_ENT_USER"
PostgresEntPasswordEnv = "DEX_POSTGRES_ENT_PASSWORD"
)
func getenv(key, defaultVal string) string {
if val := os.Getenv(key); val != "" {
return val
@ -22,9 +30,9 @@ func getenv(key, defaultVal string) string {
func postgresTestConfig(host string, port uint64) *Postgres {
return &Postgres{
NetworkDB: NetworkDB{
Database: getenv("DEX_POSTGRES_DATABASE", "postgres"),
User: getenv("DEX_POSTGRES_USER", "postgres"),
Password: getenv("DEX_POSTGRES_PASSWORD", "postgres"),
Database: getenv(PostgresEntDatabaseEnv, "postgres"),
User: getenv(PostgresEntUserEnv, "postgres"),
Password: getenv(PostgresEntPasswordEnv, "postgres"),
Host: host,
Port: uint16(port),
},
@ -50,13 +58,13 @@ func newPostgresStorage(host string, port uint64) storage.Storage {
}
func TestPostgres(t *testing.T) {
host := os.Getenv("DEX_POSTGRES_HOST")
host := os.Getenv(PostgresEntHostEnv)
if host == "" {
t.Skipf("test environment variable DEX_POSTGRES_HOST not set, skipping")
t.Skipf("test environment variable %s not set, skipping", PostgresEntHostEnv)
}
port := uint64(5432)
if rawPort := os.Getenv("DEX_POSTGRES_PORT"); rawPort != "" {
if rawPort := os.Getenv(PostgresEntPortEnv); rawPort != "" {
var err error
port, err = strconv.ParseUint(rawPort, 10, 32)
@ -138,13 +146,13 @@ func TestPostgresDSN(t *testing.T) {
}
func TestPostgresDriver(t *testing.T) {
host := os.Getenv("DEX_POSTGRES_HOST")
host := os.Getenv(PostgresEntHostEnv)
if host == "" {
t.Skipf("test environment variable DEX_POSTGRES_HOST not set, skipping")
t.Skipf("test environment variable %s not set, skipping", PostgresEntHostEnv)
}
port := uint64(5432)
if rawPort := os.Getenv("DEX_POSTGRES_PORT"); rawPort != "" {
if rawPort := os.Getenv(PostgresEntPortEnv); rawPort != "" {
var err error
port, err = strconv.ParseUint(rawPort, 10, 32)