diff options
| author | Shulhan <ms@kilabit.info> | 2019-04-12 23:07:58 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-07-05 00:37:21 +0700 |
| commit | b412fb5853219fee7c0fcad7bab8a72d846d7bc5 (patch) | |
| tree | 59ec94fe15ad69a92920c4378a6ecc5c6109ef48 /listrequest_test.go | |
| parent | 3bb229101b114153606f7ecec8911c811188bc30 (diff) | |
| download | rescached-b412fb5853219fee7c0fcad7bab8a72d846d7bc5.tar.xz | |
all: refactoring with latest update on dns package
All the server core functionalities (caches and forwarding) now
implemented inside "dns.Server". The main function of this package are
for reading options from configuration file (or from command line options)
and watching changes from system resolv.conf.
There are also some major changes on configuration file.
* "server.parent" option now use URI format instead of IP:PORT.
This will allow parent name servers to be UDP, TCP, and/or DoH
simultaneusly.
* "server.doh.parent" and "server.parent.connection" are removed,
redundant with new "server.parent" format.
* "cache.threshold" is renamed to "cache.prune_threshold".
Diffstat (limited to 'listrequest_test.go')
| -rw-r--r-- | listrequest_test.go | 156 |
1 files changed, 0 insertions, 156 deletions
diff --git a/listrequest_test.go b/listrequest_test.go deleted file mode 100644 index 6d139a5..0000000 --- a/listrequest_test.go +++ /dev/null @@ -1,156 +0,0 @@ -// Copyright 2019, Shulhan <ms@kilabit.info>. 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/test" -) - -var testRequests = []*dns.Request{{ // nolint: gochecknoglobals - Message: &dns.Message{ - Question: &dns.SectionQuestion{ - Type: 1, - Class: 1, - }, - }, -}, { - Message: &dns.Message{ - Question: &dns.SectionQuestion{ - Type: 2, - Class: 1, - }, - }, -}, { - Message: &dns.Message{ - Question: &dns.SectionQuestion{ - Type: 3, - Class: 1, - }, - }, -}} - -var testListRequest = newListRequest(testRequests[0]) // nolint: gochecknoglobals - -func TestListRequestPush(t *testing.T) { - cases := []struct { - desc string - req *dns.Request - expLen int - exp string - }{{ - desc: "With empty request", - expLen: 1, - exp: `[&{Kind:0 Message.Question:&{Name: Type:A}}]`, - }, { - desc: "With non empty request (1)", - req: testRequests[1], - expLen: 2, - exp: `[&{Kind:0 Message.Question:&{Name: Type:A}} &{Kind:0 Message.Question:&{Name: Type:NS}}]`, // nolint: lll - }, { - desc: "With non empty request (2)", - req: testRequests[2], - expLen: 3, - exp: `[&{Kind:0 Message.Question:&{Name: Type:A}} &{Kind:0 Message.Question:&{Name: Type:NS}} &{Kind:0 Message.Question:&{Name: Type:}}]`, // nolint: lll - }} - - for _, c := range cases { - t.Log(c.desc) - - testListRequest.push(c.req) - - test.Assert(t, "length", c.expLen, testListRequest.v.Len(), true) - test.Assert(t, "String", c.exp, testListRequest.String(), true) - } -} - -func TestListRequestIsExist(t *testing.T) { - cases := []struct { - desc string - qtype uint16 - qclass uint16 - exp bool - }{{ - desc: "With qtype not found", - qtype: 0, - qclass: 1, - }, { - desc: "With qclass not found", - qtype: 1, - qclass: 0, - }, { - desc: "With qtype and qclass found", - qtype: 1, - qclass: 1, - exp: true, - }} - - for _, c := range cases { - t.Log(c.desc) - - got := testListRequest.isExist(c.qtype, c.qclass) - test.Assert(t, "IsExist", c.exp, got, true) - } -} - -func TestListRequestPops(t *testing.T) { - cases := []struct { - desc string - qtype uint16 - qclass uint16 - expIsEmpty bool - expLen int - exp []*dns.Request - }{{ - desc: "With qtype not found", - qtype: 0, - qclass: 1, - }, { - desc: "With qclass not found", - qtype: 1, - qclass: 0, - }, { - desc: "With qtype and qclass found (1)", - qtype: 1, - qclass: 1, - expLen: 1, - exp: []*dns.Request{ - testRequests[0], - }, - }, { - desc: "With qtype and qclass found (2)", - qtype: 2, - qclass: 1, - expLen: 1, - exp: []*dns.Request{ - testRequests[1], - }, - }, { - desc: "With qtype and qclass found (3)", - qtype: 3, - qclass: 1, - expLen: 1, - expIsEmpty: true, - exp: []*dns.Request{ - testRequests[2], - }, - }} - - for _, c := range cases { - t.Log(c.desc) - - gots, gotIsEmpty := testListRequest.pops(c.qtype, c.qclass) - - test.Assert(t, "IsEmpty", c.expIsEmpty, gotIsEmpty, true) - test.Assert(t, "len", c.expLen, len(gots), true) - - for x, got := range gots { - test.Assert(t, "request", c.exp[x], got, true) - } - } - -} |
