From 507652efff5d76f82e08eb09d445d486d10a4415 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 2 Mar 2019 07:23:20 +0700 Subject: go.mod: update dependency github.com/shuLhan/share to v0.4.0 The dns package provide more human readable when printing Question. Instead of printing query type in number, for example A record with "1", the Question stringer now print "A" instead. --- cacheworker_test.go | 34 +++++++++++++++++----------------- go.mod | 2 +- go.sum | 8 +++++--- listrequest_test.go | 6 +++--- listresponse_test.go | 6 +++--- rescached_test.go | 9 +++++++-- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/cacheworker_test.go b/cacheworker_test.go index bc1d322..bafbd89 100644 --- a/cacheworker_test.go +++ b/cacheworker_test.go @@ -75,7 +75,7 @@ func TestCacheWorkerUpsert(t *testing.T) { }, isLocal: true, expReturn: true, - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\]\]$`, + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\]\]$`, expCachesList: `^cachesList\[\]$`, }, { desc: "With new message, test1 - A", @@ -91,8 +91,8 @@ func TestCacheWorkerUpsert(t *testing.T) { }, }, expReturn: true, - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:1 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:1 Class:1}}\]$`, + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:A}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:A}}\]$`, }, { desc: "With new message, different type, test1 - NS", msg: &dns.Message{ @@ -107,8 +107,8 @@ func TestCacheWorkerUpsert(t *testing.T) { }, }, expReturn: true, - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:1 Class:1}} {\d+ \d+ &{Name:test1 Type:2 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:1 Class:1}} &{\d+ \d+ &{Name:test1 Type:2 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:A}} {\d+ \d+ &{Name:test1 Type:NS}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:A}} &{\d+ \d+ &{Name:test1 Type:NS}}\]$`, // nolint: lll }, { desc: "With updated message, test1 - A", msg: &dns.Message{ @@ -123,8 +123,8 @@ func TestCacheWorkerUpsert(t *testing.T) { }, }, expReturn: true, - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:1 Class:1}} {\d+ \d+ &{Name:test1 Type:2 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:2 Class:1}} &{\d+ \d+ &{Name:test1 Type:1 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:A}} {\d+ \d+ &{Name:test1 Type:NS}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:NS}} &{\d+ \d+ &{Name:test1 Type:A}}\]$`, // nolint: lll }, { desc: "With new message, test2 - A", msg: &dns.Message{ @@ -139,8 +139,8 @@ func TestCacheWorkerUpsert(t *testing.T) { }, }, expReturn: true, - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:1 Class:1}} {\d+ \d+ &{Name:test1 Type:2 Class:1}}\] test2:\[{\d+ \d+ &{Name:test2 Type:1 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:2 Class:1}} &{\d+ \d+ &{Name:test1 Type:1 Class:1}} &{\d+ \d+ &{Name:test2 Type:1 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:A}} {\d+ \d+ &{Name:test1 Type:NS}}\] test2:\[{\d+ \d+ &{Name:test2 Type:A}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:NS}} &{\d+ \d+ &{Name:test1 Type:A}} &{\d+ \d+ &{Name:test2 Type:A}}\]$`, // nolint: lll }} for _, c := range cases { @@ -174,13 +174,13 @@ func TestCacheWorkerRemove(t *testing.T) { expCachesList string }{{ desc: "With nil response", - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:1 Class:1}} {\d+ \d+ &{Name:test1 Type:2 Class:1}}\] test2:\[{\d+ \d+ &{Name:test2 Type:1 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test1 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test2 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test1 Type:2 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:A}} {\d+ \d+ &{Name:test1 Type:NS}}\] test2:\[{\d+ \d+ &{Name:test2 Type:A}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test1 Type:A}} &{\d{10} \d{10} &{Name:test2 Type:A}} &{\d{10} \d{10} &{Name:test1 Type:NS}}\]$`, // nolint: lll }, { desc: "Removing one element", el: testCacheWorker.cachesList.v.Front(), - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:2 Class:1}}\] test2:\[{\d+ \d+ &{Name:test2 Type:1 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test2 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test1 Type:2 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:NS}}\] test2:\[{\d+ \d+ &{Name:test2 Type:A}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test2 Type:A}} &{\d{10} \d{10} &{Name:test1 Type:NS}}\]$`, // nolint: lll }} for _, c := range cases { @@ -209,13 +209,13 @@ func TestCacheWorkerPrune(t *testing.T) { expCachesList string }{{ desc: "With no items pruned", - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:2 Class:1}}\] test2:\[{\d+ \d+ &{Name:test2 Type:1 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test2 Type:1 Class:1}} &{\d{10} \d{10} &{Name:test1 Type:2 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:NS}}\] test2:\[{\d+ \d+ &{Name:test2 Type:A}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d{10} \d{10} &{Name:test2 Type:A}} &{\d{10} \d{10} &{Name:test1 Type:NS}}\]$`, // nolint: lll }, { desc: "Pruning one element", res: testCacheWorker.cachesList.v.Front().Value.(*response), - expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:1 Class:1}}\] test1:\[{\d+ \d+ &{Name:test1 Type:2 Class:1}}\]\]$`, // nolint: lll - expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:2 Class:1}}\]$`, // nolint: lll + expCaches: `^caches\[local:\[{\d+ \d+ &{Name:local Type:A}}\] test1:\[{\d+ \d+ &{Name:test1 Type:NS}}\]\]$`, // nolint: lll + expCachesList: `^cachesList\[&{\d+ \d+ &{Name:test1 Type:NS}}\]$`, // nolint: lll }} for _, c := range cases { diff --git a/go.mod b/go.mod index 7a77bdd..64a248e 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/shuLhan/rescached-go -require github.com/shuLhan/share v0.3.0 +require github.com/shuLhan/share v0.4.0 diff --git a/go.sum b/go.sum index 7254796..421927e 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ -github.com/shuLhan/share v0.3.0 h1:TmH6XtYQRVxBlq1X1woFzyIYCNcBORo45WBUtRu9cxk= -github.com/shuLhan/share v0.3.0/go.mod h1:SjjW0kmafz7R07V8GP8D9YvTj0jQ4A5LoLVYjC+920U= -golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +github.com/shuLhan/share v0.4.0 h1:bp5SlzcF7u1feOc4BvWHHVtUXecaq26Lyn8rROMbQ1k= +github.com/shuLhan/share v0.4.0/go.mod h1:n3BWSX6aGXiCmpc89DsfnhNnax89yhKLHFu6WC9ODes= +golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/listrequest_test.go b/listrequest_test.go index 39b8e2d..6d139a5 100644 --- a/listrequest_test.go +++ b/listrequest_test.go @@ -45,17 +45,17 @@ func TestListRequestPush(t *testing.T) { }{{ desc: "With empty request", expLen: 1, - exp: `[&{Kind:0 Message.Question:&{Name: Type:1 Class: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:1 Class:1}} &{Kind:0 Message.Question:&{Name: Type:2 Class:1}}]`, // nolint: lll + 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:1 Class:1}} &{Kind:0 Message.Question:&{Name: Type:2 Class:1}} &{Kind:0 Message.Question:&{Name: Type:3 Class:1}}]`, // nolint: lll + 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 { diff --git a/listresponse_test.go b/listresponse_test.go index 33c022c..b276cf6 100644 --- a/listresponse_test.go +++ b/listresponse_test.go @@ -23,17 +23,17 @@ func TestListResponseAdd(t *testing.T) { desc: "New", msg: _testResponses[0].message, expLen: 1, - exp: `[{0 0 &{Name:1 Type:1 Class:1}}]`, + exp: `[{0 0 &{Name:1 Type:A}}]`, }, { desc: "New", msg: _testResponses[1].message, expLen: 2, - exp: `[{0 0 &{Name:1 Type:1 Class:1}} {0 0 &{Name:2 Type:2 Class:1}}]`, + exp: `[{0 0 &{Name:1 Type:A}} {0 0 &{Name:2 Type:NS}}]`, }, { desc: "Replace", msg: _testResponses[2].message, expLen: 3, - exp: `[{0 0 &{Name:1 Type:1 Class:1}} {0 0 &{Name:2 Type:2 Class:1}} {0 0 &{Name:1 Type:1 Class:1}}]`, + exp: `[{0 0 &{Name:1 Type:A}} {0 0 &{Name:2 Type:NS}} {0 0 &{Name:1 Type:A}}]`, }} for _, c := range cases { diff --git a/rescached_test.go b/rescached_test.go index 0254384..22ab579 100644 --- a/rescached_test.go +++ b/rescached_test.go @@ -194,7 +194,7 @@ func TestLoadHostsDir(t *testing.T) { }, { desc: "With non empty directory", dir: "testdata/hosts.d", - expCaches: `caches\[1.test:\[{0 \d+ &{Name:1.test Type:1 Class:1}}\] 2.test:\[{0 \d+ &{Name:2.test Type:1 Class:1}}\]\]`, // nolint: lll + expCaches: `caches\[1.test:\[{0 \d+ &{Name:1.test Type:A}}\] 2.test:\[{0 \d+ &{Name:2.test Type:A}}\]\]`, // nolint: lll }} srv := New(nil) @@ -231,7 +231,7 @@ func TestLoadMasterDir(t *testing.T) { }, { desc: "With non empty directory", dir: "testdata/master.d", - expCaches: `caches\[test.x:\[{0 \d+ &{Name:test.x Type:1 Class:1}}\]\]`, // nolint: lll + expCaches: `caches\[test.x:\[{0 \d+ &{Name:test.x Type:A}}\]\]`, // nolint: lll }} srv := New(nil) @@ -300,6 +300,7 @@ func TestProcessRequest(t *testing.T) { req: &dns.Request{ Kind: dns.ConnTypeUDP, Message: &dns.Message{ + Header: &dns.SectionHeader{}, Question: &dns.SectionQuestion{ Name: []byte("notexist"), Type: dns.QueryTypeA, @@ -310,6 +311,7 @@ func TestProcessRequest(t *testing.T) { expFw: &dns.Request{ Kind: dns.ConnTypeUDP, Message: &dns.Message{ + Header: &dns.SectionHeader{}, Question: &dns.SectionQuestion{ Name: []byte("notexist"), Type: dns.QueryTypeA, @@ -322,6 +324,7 @@ func TestProcessRequest(t *testing.T) { req: &dns.Request{ Kind: dns.ConnTypeUDP, Message: &dns.Message{ + Header: &dns.SectionHeader{}, Question: &dns.SectionQuestion{ Name: []byte("notexist"), Type: dns.QueryTypeA, @@ -334,6 +337,7 @@ func TestProcessRequest(t *testing.T) { req: &dns.Request{ Kind: dns.ConnTypeDoH, Message: &dns.Message{ + Header: &dns.SectionHeader{}, Question: &dns.SectionQuestion{ Name: []byte("doh"), Type: dns.QueryTypeA, @@ -344,6 +348,7 @@ func TestProcessRequest(t *testing.T) { expFwDoH: &dns.Request{ Kind: dns.ConnTypeDoH, Message: &dns.Message{ + Header: &dns.SectionHeader{}, Question: &dns.SectionQuestion{ Name: []byte("doh"), Type: dns.QueryTypeA, -- cgit v1.3