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
This commit is contained in:
TwinProduction 2020-12-29 17:31:43 -05:00
parent a83f6c7619
commit 3eb8299316

View File

@ -2,6 +2,8 @@ package core
import ( import (
"testing" "testing"
"github.com/TwinProduction/gatus/pattern"
) )
func TestIntegrationQuery(t *testing.T) { func TestIntegrationQuery(t *testing.T) {
@ -61,7 +63,7 @@ func TestIntegrationQuery(t *testing.T) {
}, },
inputURL: "8.8.8.8", inputURL: "8.8.8.8",
expectedDNSCode: "NOERROR", expectedDNSCode: "NOERROR",
expectedBody: "b.iana-servers.net.", expectedBody: "*.iana-servers.net.",
}, },
{ {
name: "test DNS with fake type and retrieve error", 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) t.Errorf("DNSRCodePlaceholder '%s' should have been %s", result.DNSRCode, test.expectedDNSCode)
} }
if string(result.Body) != test.expectedBody { if test.inputDNS.QueryType == "NS" {
t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody) // 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)
}
} }
}) })
} }