aboutsummaryrefslogtreecommitdiff
path: root/middleware/kubernetes/parse_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-08-10 01:08:58 -0700
committerGravatar GitHub <noreply@github.com> 2017-08-10 01:08:58 -0700
commit7e56cc74e5420bfc1670ddf858420909fdaf3fee (patch)
treeb8d2992c476a57c11082239c9501761f19f52ef8 /middleware/kubernetes/parse_test.go
parentfefc4374d72086d6325019471677a6ae73622a63 (diff)
downloadcoredns-7e56cc74e5420bfc1670ddf858420909fdaf3fee.tar.gz
coredns-7e56cc74e5420bfc1670ddf858420909fdaf3fee.tar.zst
coredns-7e56cc74e5420bfc1670ddf858420909fdaf3fee.zip
WIP: Parserequest2 cutback (#868)
* middleware/kubernetes: pull TXT out of parseRequest Put the TXT handling one layer higher and remove it from parseRequest. Also rename the podsvc field in there to podOrSvc. Now that it isn't used anymore for TXT record (dns-version) that was put in there. We can make this a boolean (in a future PR). Make parseRequest get an optional Zone that is from state.Zone and use that instead of its own code. Removed some tests and other smaller cleanups. Fixes #836 * add this reverse * another check * readd * Rename to kPod and kService for some clarity
Diffstat (limited to 'middleware/kubernetes/parse_test.go')
-rw-r--r--middleware/kubernetes/parse_test.go131
1 files changed, 131 insertions, 0 deletions
diff --git a/middleware/kubernetes/parse_test.go b/middleware/kubernetes/parse_test.go
new file mode 100644
index 000000000..06c3711cd
--- /dev/null
+++ b/middleware/kubernetes/parse_test.go
@@ -0,0 +1,131 @@
+package kubernetes
+
+import (
+ "reflect"
+ "testing"
+
+ "github.com/miekg/dns"
+)
+
+func expectString(t *testing.T, function, qtype, query string, r *recordRequest, field, expected string) {
+ ref := reflect.ValueOf(r)
+ refField := reflect.Indirect(ref).FieldByName(field)
+ got := refField.String()
+ if got != expected {
+ t.Errorf("Expected %v(%v, \"%v\") to get %v == \"%v\". Instead got \"%v\".", function, query, qtype, field, expected, got)
+ }
+}
+
+func TestParseRequest(t *testing.T) {
+
+ var tcs map[string]string
+
+ zone := "intern.webs.tests."
+ k := Kubernetes{Zones: []string{zone}}
+ f := "parseRequest"
+
+ // Test a valid SRV request
+ //
+ query := "_http._tcp.webs.mynamespace.svc.inter.webs.test."
+ r, e := k.parseRequest(query, dns.TypeSRV, zone)
+ if e != nil {
+ t.Errorf("Expected no error from parseRequest(%v, \"SRV\"). Instead got '%v'.", query, e)
+ }
+
+ tcs = map[string]string{
+ "port": "http",
+ "protocol": "tcp",
+ "endpoint": "",
+ "service": "webs",
+ "namespace": "mynamespace",
+ "podOrSvc": Svc,
+ "zone": zone,
+ }
+ for field, expected := range tcs {
+ expectString(t, f, "SRV", query, &r, field, expected)
+ }
+
+ // Test wildcard acceptance
+ //
+ query = "*.any.*.any.svc.inter.webs.test."
+ r, e = k.parseRequest(query, dns.TypeSRV, zone)
+ if e != nil {
+ t.Errorf("Expected no error from parseRequest(\"%v\", \"SRV\"). Instead got '%v'.", query, e)
+ }
+
+ tcs = map[string]string{
+ "port": "*",
+ "protocol": "any",
+ "endpoint": "",
+ "service": "*",
+ "namespace": "any",
+ "podOrSvc": Svc,
+ "zone": zone,
+ }
+ for field, expected := range tcs {
+ expectString(t, f, "SRV", query, &r, field, expected)
+ }
+
+ // Test A request of endpoint
+ query = "1-2-3-4.webs.mynamespace.svc.inter.webs.test."
+ r, e = k.parseRequest(query, dns.TypeA, zone)
+ if e != nil {
+ t.Errorf("Expected no error from parseRequest(\"%v\", \"A\"). Instead got '%v'.", query, e)
+ }
+ tcs = map[string]string{
+ "port": "",
+ "protocol": "",
+ "endpoint": "1-2-3-4",
+ "service": "webs",
+ "namespace": "mynamespace",
+ "podOrSvc": Svc,
+ "zone": zone,
+ }
+ for field, expected := range tcs {
+ expectString(t, f, "A", query, &r, field, expected)
+ }
+
+ // Test NS request
+ query = "inter.webs.test."
+ r, e = k.parseRequest(query, dns.TypeNS, zone)
+ if e != nil {
+ t.Errorf("Expected no error from parseRequest(\"%v\", \"NS\"). Instead got '%v'.", query, e)
+ }
+ tcs = map[string]string{
+ "port": "",
+ "protocol": "",
+ "endpoint": "",
+ "service": "",
+ "namespace": "",
+ "podOrSvc": "",
+ "zone": zone,
+ }
+ for field, expected := range tcs {
+ expectString(t, f, "NS", query, &r, field, expected)
+ }
+
+ // Invalid query tests
+ invalidAQueries := []string{
+ "_http._tcp.webs.mynamespace.svc.inter.webs.test.", // A requests cannot have port or protocol TODO(miek): this must return NODATA
+
+ }
+ for _, q := range invalidAQueries {
+ _, e = k.parseRequest(q, dns.TypeA, zone)
+ if e == nil {
+ t.Errorf("Expected error from %v(\"%v\", \"A\").", f, q)
+ }
+ }
+
+ invalidSRVQueries := []string{
+ "_http._pcp.webs.mynamespace.svc.inter.webs.test.", // SRV protocol must be tcp or udp
+ "_http._tcp.ep.webs.ns.svc.inter.webs.test.", // SRV requests cannot have an endpoint
+ "_*._*.webs.mynamespace.svc.inter.webs.test.", // SRV request with invalid wildcards
+ }
+
+ for _, q := range invalidSRVQueries {
+ _, e = k.parseRequest(q, dns.TypeSRV, zone)
+ if e == nil {
+ t.Errorf("Expected error from %v(\"%v\", \"SRV\").", f, q)
+ }
+ }
+}
ers'>re-export-drivers Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/examples/portfolio/astro.config.mjs (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-02-07Delete robots.txt (#2540)Gravatar Marcus Otterström 2-3/+0
2022-02-07[ci] yarn formatGravatar matthewp 1-1/+1
2022-02-07[ci] update lockfile (#2543)Gravatar Fred K. Schott 1-171/+178
2022-02-07improve debug logs (#2537)Gravatar Fred K. Schott 3-4/+19
2022-02-07[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-06[ci] update lockfile (#2527)Gravatar Fred K. Schott 1-208/+238
2022-02-06[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-05[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-04[ci] yarn formatGravatar natemoo-re 1-2/+3
2022-02-04fix: HTML/SVG boolean attributes (#2538)Gravatar Nate Moore 2-3/+21
2022-02-04[ci] yarn formatGravatar matthewp 1-4/+2
2022-02-04fix: import local plugins into markdown (#2534)Gravatar Juan Martín Seery 9-22/+41
2022-02-04[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03Append to list of HMR modules, don't override (#2532)Gravatar Matthew Phillips 2-1/+6
2022-02-03add back dev server host support (#2531)Gravatar Fred K. Schott 2-1/+14
2022-02-03simplify status code regexGravatar Fred K. Schott 2-87/+4
2022-02-03Adding StackUp Digital to the list of sponsors (#2521)Gravatar Astroalex 3-0/+10
2022-02-03[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-03[ci] yarn formatGravatar FredKSchott 2-3/+85
2022-02-02Handles all http error code file names the same as 404 files. (#2525)Gravatar Zade Viggers 2-4/+7
2022-02-02fix(sitemap): remove debug if sitemap disabled (#2514)Gravatar Mark Pinero 1-2/+2
2022-02-02[ci] update lockfile (#2515)Gravatar Fred K. Schott 1-276/+279
2022-02-02[ci] yarn formatGravatar matthewp 1-8/+8
2022-02-02[ci] release (next) (#2523)astro@0.23.0-next.1Gravatar github-actions[bot] 28-34/+41
2022-02-02[ci] yarn formatGravatar matthewp 2-17/+29
2022-02-02Fix support for scss in static build (#2522)Gravatar Matthew Phillips 6-20/+114
2022-02-02[ci] collect statsGravatar FredKSchott 1-0/+1
2022-02-01[ci] yarn formatGravatar matthewp 2-12/+12
2022-02-01[ci] release (next) (#2492)astro@0.23.0-next.0@astrojs/test-static-build-pkg@0.0.2@astrojs/markdown-remark@0.6.1-next.0Gravatar github-actions[bot] 31-43/+93
2022-02-01[ci] collect statsGravatar FredKSchott 1-0/+1
2022-01-31update congratsbot format againGravatar Fred K. Schott 1-1/+1
2022-01-31update congratsbot againGravatar Fred K. Schott 1-1/+1
2022-01-31Remove SVG animation on GitHub/NPM (#2512)Gravatar Nate Moore 1-21/+0
2022-01-31[ci] yarn formatGravatar natemoo-re 2-4/+6
2022-01-31Add Shiki as an alternative to Prism (#2497)Gravatar Juan Martín Seery 26-9/+356
2022-01-31Deprecate unescaped HTML inside of expressions (#2489)Gravatar Nate Moore 9-31/+74