mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-07 00:39:05 +07:00
Refactored tests
This commit is contained in:
61
db_test.go
61
db_test.go
@ -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 {
|
||||
|
Reference in New Issue
Block a user