Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Kämmerling <[email protected]>
  • Loading branch information
LKaemmerling committed Mar 26, 2022
1 parent a8ff56a commit ca71dfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 4 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions pkg/datastore/sqlstore/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit ca71dfc

Please sign in to comment.