acme-dns/main_test.go

76 lines
1.5 KiB
Go
Raw Normal View History

2016-11-26 21:23:22 +07:00
package main
import (
"flag"
2016-11-28 00:41:54 +07:00
"fmt"
2016-11-26 21:23:22 +07:00
"os"
"testing"
)
2016-11-28 00:41:54 +07:00
var (
postgres = flag.Bool("postgres", false, "run integration tests against PostgreSQL")
)
var records = []string{
"auth.example.org. A 192.168.1.100",
"ns1.auth.example.org. A 192.168.1.101",
"!''b', unparseable ",
"ns2.auth.example.org. A 192.168.1.102",
}
2016-11-26 21:23:22 +07:00
func TestMain(m *testing.M) {
2016-11-28 00:41:54 +07:00
setupConfig()
RR.Parse(DNSConf.General)
2016-11-26 21:23:22 +07:00
flag.Parse()
2016-11-28 00:41:54 +07:00
2016-11-28 04:21:46 +07:00
newDb := new(acmedb)
2016-11-28 00:41:54 +07:00
if *postgres {
DNSConf.Database.Engine = "postgres"
2016-11-28 04:21:46 +07:00
err := newDb.Init("postgres", "postgres://acmedns:acmedns@localhost/acmedns")
2016-11-28 00:41:54 +07:00
if err != nil {
fmt.Println("PostgreSQL integration tests expect database \"acmedns\" running in localhost, with username and password set to \"acmedns\"")
os.Exit(1)
}
} else {
DNSConf.Database.Engine = "sqlite3"
2016-11-28 04:21:46 +07:00
_ = newDb.Init("sqlite3", ":memory:")
2016-11-28 00:41:54 +07:00
}
2016-11-28 04:21:46 +07:00
DB = newDb
2016-11-28 00:41:54 +07:00
2016-11-28 02:21:38 +07:00
server := startDNS("0.0.0.0:15353")
2016-11-26 21:23:22 +07:00
exitval := m.Run()
server.Shutdown()
2016-11-28 04:21:46 +07:00
DB.Close()
2016-11-26 21:23:22 +07:00
os.Exit(exitval)
}
2016-11-28 00:41:54 +07:00
func setupConfig() {
var dbcfg = dbsettings{
Engine: "sqlite3",
Connection: ":memory:",
}
var generalcfg = general{
Domain: "auth.example.org",
Nsname: "ns1.auth.example.org",
Nsadmin: "admin.example.org",
StaticRecords: records,
Debug: false,
2016-11-28 00:41:54 +07:00
}
var httpapicfg = httpapi{
Domain: "",
Port: "8080",
TLS: "none",
CorsOrigins: []string{"*"},
}
var dnscfg = DNSConfig{
Database: dbcfg,
General: generalcfg,
API: httpapicfg,
}
DNSConf = dnscfg
}