From ca71dfcf66a9a26656b4c32ff49b999278299f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Sat, 26 Mar 2022 17:40:41 +0100 Subject: [PATCH] Fix unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Kämmerling --- pkg/config/config.go | 5 ++++- pkg/datastore/sqlstore/config_test.go | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 27de0f27..139d1dc2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -54,10 +54,13 @@ func Parse() *Config { } if cfg.Database.URL != "" { - _, err := url.Parse(cfg.Database.URL) + u, err := url.Parse(cfg.Database.URL) if err != nil { log.Fatalf("Error parsing DATABASE_URL from environment: %s", err) } + if u.Scheme == "postgres" { + cfg.Database.Driver = "postgres" + } } // alias sqlite to sqlite3 diff --git a/pkg/datastore/sqlstore/config_test.go b/pkg/datastore/sqlstore/config_test.go index 8e6f2c9d..21234165 100644 --- a/pkg/datastore/sqlstore/config_test.go +++ b/pkg/datastore/sqlstore/config_test.go @@ -8,21 +8,21 @@ import ( func TestConfigDSN(t *testing.T) { c := Config{ Driver: "postgres", - user: "john", - password: "foo", + User: "john", + Password: "foo", } - e := fmt.Sprintf("user=%s password=%s", c.user, c.password) + e := fmt.Sprintf("user=%s password=%s", c.User, c.Password) if v := c.DSN(); v != e { t.Errorf("Invalid DSN. Expected %s, got %s", e, v) } c = Config{ Driver: "postgres", - user: "john", - password: "foo", - sslmode: "disable", + User: "john", + Password: "foo", + SSLMode: "disable", } - e = fmt.Sprintf("user=%s password=%s sslmode=%s", c.user, c.password, c.sslmode) + e = fmt.Sprintf("user=%s password=%s sslmode=%s", c.User, c.Password, c.SSLMode) if v := c.DSN(); v != e { t.Errorf("Invalid DSN. Expected %s, got %s", e, v) } @@ -32,21 +32,21 @@ func TestConfigDbname(t *testing.T) { var c Config c = Config{ - url: "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full", + URL: "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full", } if e, v := "pqgotest", c.Dbname(); v != e { t.Errorf("Expected %q, got %q", e, v) } c = Config{ - url: "root@tcp(host.myhost)/mysqltest?loc=Local", + URL: "root@tcp(host.myhost)/mysqltest?loc=Local", } if e, v := "mysqltest", c.Dbname(); v != e { t.Errorf("Expected %q, got %q", e, v) } c = Config{ - url: "/mysqltest?loc=Local&parseTime=true", + URL: "/mysqltest?loc=Local&parseTime=true", } if e, v := "mysqltest", c.Dbname(); v != e { t.Errorf("Expected %q, got %q", e, v)