Unit Testing DNS Data
DNSControl performs a number of tests during the validation stage. You can find them in
Tests specific to your environment may be added as external tests. Output the intermediate representation as a JSON file and perform tests on this data.
Output the intermediate representation:
dnscontrol print-ir --out foo.json --pretty
--prettyflag is optional.
Here is a sample test written in
bashusing the jq command. This fails if the number of MX records in the
stackex.comdomain is not exactly 5:
COUNTMX=$(jq --raw-output <foo.json '.domains | select(.name == "stackex.com") | .records | select(.type == "MX") | .target' | wc -l)
if [[ "$COUNTMX" -eq "5" ]]; then
Manipulating JSON data is difficult. If you implement ways to make it easier, we'd gladly accept contributions.
Last modified 4mo ago