aboutsummaryrefslogtreecommitdiff
path: root/environment_test.go
diff options
context:
space:
mode:
authorShulhan <m.shulhan@gmail.com>2020-05-18 23:57:56 +0700
committerShulhan <m.shulhan@gmail.com>2020-07-26 03:48:51 +0700
commit03ab6a462ddbd7589ac385a219f035ca7975f856 (patch)
treeac26781fb0246021ce5ba4bbf69aaf1055e5c6bb /environment_test.go
parent7574bb6ebff609b9a2889fc573ce3edce256e030 (diff)
downloadrescached-03ab6a462ddbd7589ac385a219f035ca7975f856.tar.xz
all: rename Options to environment
While at it, unexport it.
Diffstat (limited to 'environment_test.go')
-rw-r--r--environment_test.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/environment_test.go b/environment_test.go
new file mode 100644
index 0000000..19fd80c
--- /dev/null
+++ b/environment_test.go
@@ -0,0 +1,57 @@
+// Copyright 2019, Shulhan <m.shulhan@gmail.com>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package rescached
+
+import (
+ "testing"
+
+ "github.com/shuLhan/share/lib/dns"
+ "github.com/shuLhan/share/lib/ini"
+ "github.com/shuLhan/share/lib/test"
+)
+
+func TestEnvironment(t *testing.T) {
+ cases := []struct {
+ desc string
+ content string
+ exp *environment
+ expError string
+ }{{
+ desc: "With empty content",
+ exp: &environment{},
+ }, {
+ desc: "With multiple parents",
+ content: `[dns "server"]
+listen = 127.0.0.1:53
+parent = udp://35.240.172.103
+parent = https://kilabit.info/dns-query
+`,
+ exp: &environment{
+ ServerOptions: dns.ServerOptions{
+ ListenAddress: "127.0.0.1:53",
+ NameServers: []string{
+ "udp://35.240.172.103",
+ "https://kilabit.info/dns-query",
+ },
+ },
+ },
+ }}
+
+ for _, c := range cases {
+ t.Log(c.desc)
+
+ got := &environment{
+ ServerOptions: dns.ServerOptions{},
+ }
+
+ err := ini.Unmarshal([]byte(c.content), got)
+ if err != nil {
+ test.Assert(t, "error", c.expError, err.Error(), true)
+ continue
+ }
+
+ test.Assert(t, "environment", c.exp, got, true)
+ }
+}