Refactored tests

This commit is contained in:
Joona Hoikkala
2016-11-27 19:41:54 +02:00
parent b4cc6b8e81
commit 5072b231af
7 changed files with 88 additions and 147 deletions

View File

@ -1,29 +1,10 @@
package main
import (
"flag"
"testing"
)
var (
postgres = flag.Bool("postgres", false, "run integration tests against PostgreSQL")
)
func TestRegister(t *testing.T) {
flag.Parse()
if *postgres {
DNSConf.Database.Engine = "postgres"
err := DB.Init("postgres", "postgres://acmedns:acmedns@localhost/acmedns")
if err != nil {
t.Errorf("PostgreSQL integration tests expect database \"acmedns\" running in localhost, with username and password set to \"acmedns\"")
return
}
} else {
DNSConf.Database.Engine = "sqlite3"
_ = DB.Init("sqlite3", ":memory:")
}
defer DB.DB.Close()
// Register tests
_, err := DB.Register()
if err != nil {
@ -32,20 +13,6 @@ func TestRegister(t *testing.T) {
}
func TestGetByUsername(t *testing.T) {
flag.Parse()
if *postgres {
DNSConf.Database.Engine = "postgres"
err := DB.Init("postgres", "postgres://acmedns:acmedns@localhost/acmedns")
if err != nil {
t.Errorf("PostgreSQL integration tests expect database \"acmedns\" running in localhost, with username and password set to \"acmedns\"")
return
}
} else {
DNSConf.Database.Engine = "sqlite3"
_ = DB.Init("sqlite3", ":memory:")
}
defer DB.DB.Close()
// Create reg to refer to
reg, err := DB.Register()
if err != nil {
@ -72,20 +39,6 @@ func TestGetByUsername(t *testing.T) {
}
func TestGetByDomain(t *testing.T) {
flag.Parse()
if *postgres {
DNSConf.Database.Engine = "postgres"
err := DB.Init("postgres", "postgres://acmedns:acmedns@localhost/acmedns")
if err != nil {
t.Errorf("PostgreSQL integration tests expect database \"acmedns\" running in localhost, with username and password set to \"acmedns\"")
return
}
} else {
DNSConf.Database.Engine = "sqlite3"
_ = DB.Init("sqlite3", ":memory:")
}
defer DB.DB.Close()
var regDomain = ACMETxt{}
// Create reg to refer to
@ -125,20 +78,6 @@ func TestGetByDomain(t *testing.T) {
}
func TestUpdate(t *testing.T) {
flag.Parse()
if *postgres {
DNSConf.Database.Engine = "postgres"
err := DB.Init("postgres", "postgres://acmedns:acmedns@localhost/acmedns")
if err != nil {
t.Errorf("PostgreSQL integration tests expect database \"acmedns\" running in localhost, with username and password set to \"acmedns\"")
return
}
} else {
DNSConf.Database.Engine = "sqlite3"
_ = DB.Init("sqlite3", ":memory:")
}
defer DB.DB.Close()
// Create reg to refer to
reg, err := DB.Register()
if err != nil {