2017-05-28 04:13:55 +08:00
# Unit Testing DNS Data
2017-09-30 03:44:13 +08:00
## Built-in Tests
2017-05-28 04:13:55 +08:00
DNSControl performs a number of tests during the validation stage.
You can find them in `pkg/normalize/validate.go` .
## External tests
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:
2023-01-20 20:56:20 +08:00
```shell
dnscontrol print-ir --out foo.json --pretty
```
2017-12-11 22:57:46 +08:00
2023-01-20 20:56:20 +08:00
{% hint style="info" %}
**NOTE**: The `--pretty` flag is optional.
{% endhint %}
2017-05-28 04:13:55 +08:00
Here is a sample test written in `bash` using the [jq ](https://stedolan.github.io/jq/ ) command. This fails if the number of MX records in the `stackex.com` domain is not exactly 5:
COUNTMX=$(jq --raw-output < foo.json ' . domains [ ] | select ( . name = = " stackex . com " ) | . records [ ] | select ( . type = = " MX " ) | . target ' | wc -l )
echo COUNT=:"$COUNTMX":
if [[ "$COUNTMX" -eq "5" ]]; then
echo GOOD
else
echo BAD
fi
## Future directions
2019-05-12 09:32:52 +08:00
Manipulating JSON data is difficult. If you implement ways to make it easier, we'd
2017-05-28 04:13:55 +08:00
gladly accept contributions.