aboutsummaryrefslogtreecommitdiff
path: root/lib/dns
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-03-22 20:31:47 +0700
committerShulhan <ms@kilabit.info>2024-03-22 20:31:47 +0700
commitfde000db7006ce8545e5556072dfe4faed24bdd9 (patch)
treee6410a2bd74a64bd28baeb639e9df57e9f463538 /lib/dns
parentcee16b8ead859b1ac372d6153d03a058d4e7ae82 (diff)
downloadpakakeh.go-fde000db7006ce8545e5556072dfe4faed24bdd9.tar.xz
lib/dns: add test flag to skip running DNS server
When we want to test a function or methods that does not interact with DNS server, there is no need to run dummy DNS server.
Diffstat (limited to 'lib/dns')
-rw-r--r--lib/dns/dns_test.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/dns/dns_test.go b/lib/dns/dns_test.go
index 207b5a3c..ce94c9f8 100644
--- a/lib/dns/dns_test.go
+++ b/lib/dns/dns_test.go
@@ -5,6 +5,7 @@
package dns
import (
+ "flag"
"log"
"os"
"testing"
@@ -27,10 +28,23 @@ var (
func TestMain(m *testing.M) {
log.SetFlags(0)
+ var flagNoServer bool
+
+ flag.BoolVar(&flagNoServer, `no-server`, false, `Skip running servers`)
+ flag.Parse()
+
timeNow = func() time.Time {
return time.Unix(testNowEpoch, 0)
}
+ if !flagNoServer {
+ runServer()
+ }
+
+ os.Exit(m.Run())
+}
+
+func runServer() {
var (
serverOptions = &ServerOptions{
ListenAddress: "127.0.0.1:5300",
@@ -41,8 +55,7 @@ func TestMain(m *testing.M) {
TLSAllowInsecure: true,
}
- zoneFile *Zone
- err error
+ err error
)
_testServer, err = NewServer(serverOptions)
@@ -50,6 +63,8 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
+ var zoneFile *Zone
+
zoneFile, err = ParseZoneFile("testdata/kilabit.info", "", 0)
if err != nil {
log.Fatal(err)
@@ -66,6 +81,4 @@ func TestMain(m *testing.M) {
// Wait for all listeners running.
time.Sleep(500 * time.Millisecond)
-
- os.Exit(m.Run())
}