From 3eb8299316d4f507aa9c77c89a076599f1a8a9d8 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Tue, 29 Dec 2020 17:31:43 -0500 Subject: [PATCH] Fix potential issue with integration DNS and NS fallbacks Because there are often multiple nameservers backing a single domain, we need to ensure that the test passes even if the nameserver returned isn't the primary name server --- core/dns_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/dns_test.go b/core/dns_test.go index a3172d23..d5073463 100644 --- a/core/dns_test.go +++ b/core/dns_test.go @@ -2,6 +2,8 @@ package core import ( "testing" + + "github.com/TwinProduction/gatus/pattern" ) func TestIntegrationQuery(t *testing.T) { @@ -61,7 +63,7 @@ func TestIntegrationQuery(t *testing.T) { }, inputURL: "8.8.8.8", expectedDNSCode: "NOERROR", - expectedBody: "b.iana-servers.net.", + expectedBody: "*.iana-servers.net.", }, { name: "test DNS with fake type and retrieve error", @@ -87,8 +89,15 @@ func TestIntegrationQuery(t *testing.T) { t.Errorf("DNSRCodePlaceholder '%s' should have been %s", result.DNSRCode, test.expectedDNSCode) } - if string(result.Body) != test.expectedBody { - t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody) + if test.inputDNS.QueryType == "NS" { + // Because there are often multiple nameservers backing a single domain, we'll only look at the suffix + if !pattern.Match(test.expectedBody, string(result.Body)) { + t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody) + } + } else { + if string(result.Body) != test.expectedBody { + t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody) + } } }) }