diff options
author | 2017-08-22 20:44:42 +0100 | |
---|---|---|
committer | 2017-08-22 12:44:42 -0700 | |
commit | 6a4e69eb9fd0aa02c47d74d743ae4fce292dcbb7 (patch) | |
tree | e07ebb0b33dd61c190af6b98a079cf45b91ac279 /middleware/kubernetes/parse_test.go | |
parent | 60d5e71a1aa3e7ff75e385600a214063a7b17d01 (diff) | |
download | coredns-6a4e69eb9fd0aa02c47d74d743ae4fce292dcbb7.tar.gz coredns-6a4e69eb9fd0aa02c47d74d743ae4fce292dcbb7.tar.zst coredns-6a4e69eb9fd0aa02c47d74d743ae4fce292dcbb7.zip |
mw/kubernetes: Rewrite parseRequest and Readability improvements (#939)
* mw/kubernetes: rewrite parseRequest
Stop looking at the qtype in parseRequest and make k.Namespace a map.
Fallout from this is that pkg/strings as it is not used anymore. Also
add a few helper functions to make unexposed namespaces easier to see in
the code.
Add wildcard tests to the middleware tests.
* Fix tests
Add a whole bunch of comments to document what we are trying to do.
* This is now answered
* up coverage
* duh
* Update testcase
* Make it nodata
Diffstat (limited to 'middleware/kubernetes/parse_test.go')
-rw-r--r-- | middleware/kubernetes/parse_test.go | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/middleware/kubernetes/parse_test.go b/middleware/kubernetes/parse_test.go index daf884b30..e44fb09f4 100644 --- a/middleware/kubernetes/parse_test.go +++ b/middleware/kubernetes/parse_test.go @@ -13,34 +13,18 @@ func TestParseRequest(t *testing.T) { tests := []struct { query string - qtype uint16 expected string // output from r.String() }{ - { - // valid SRV request - "_http._tcp.webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV, - "http.tcp..webs.mynamespace.svc", - }, - { - // wildcard acceptance - "*.any.*.any.svc.inter.webs.test.", dns.TypeSRV, - "*.any..*.any.svc", - }, - { - // A request of endpoint - "1-2-3-4.webs.mynamespace.svc.inter.webs.test.", dns.TypeA, - "..1-2-3-4.webs.mynamespace.svc", - }, - { - - // 3 segments - "webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV, - "*...webs.mynamespace.svc", - }, + // valid SRV request + {"_http._tcp.webs.mynamespace.svc.inter.webs.test.", "http.tcp..webs.mynamespace.svc"}, + // wildcard acceptance + {"*.any.*.any.svc.inter.webs.test.", "*.any..*.any.svc"}, + // A request of endpoint + {"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", "*.*.1-2-3-4.webs.mynamespace.svc"}, } for i, tc := range tests { m := new(dns.Msg) - m.SetQuestion(tc.query, tc.qtype) + m.SetQuestion(tc.query, dns.TypeA) state := request.Request{Zone: zone, Req: m} r, e := k.parseRequest(state) @@ -57,21 +41,18 @@ func TestParseRequest(t *testing.T) { func TestParseInvalidRequest(t *testing.T) { k := New([]string{zone}) - invalid := map[string]uint16{ - "_http._tcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeA, // A requests cannot have port or protocol - "_http._pcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeSRV, // SRV protocol must be tcp or udp - "_http._tcp.ep.webs.ns.svc.inter.webs.test.": dns.TypeSRV, // SRV requests cannot have an endpoint - "_*._*.webs.mynamespace.svc.inter.webs.test.": dns.TypeSRV, // SRV request with invalid wildcards - + invalid := []string{ + "webs.mynamespace.pood.inter.webs.test.", // Request must be for pod or svc subdomain. + "too.long.for.what.I.am.trying.to.pod.inter.webs.tests.", // Too long. } - for query, qtype := range invalid { + for i, query := range invalid { m := new(dns.Msg) - m.SetQuestion(query, qtype) + m.SetQuestion(query, dns.TypeA) state := request.Request{Zone: zone, Req: m} if _, e := k.parseRequest(state); e == nil { - t.Errorf("Expected error from %s:%d, got none", query, qtype) + t.Errorf("Test %d: expected error from %s, got none", i, query) } } } |