mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Add unittest docs
This commit is contained in:
@@ -11,10 +11,12 @@ Dnscontrol is a platform for seamlessly managing your dns configuration across a
|
|||||||
|
|
||||||
## [Language Reference]({{site.github.url}}/js): Description of the DNSControl language (DSL).
|
## [Language Reference]({{site.github.url}}/js): Description of the DNSControl language (DSL).
|
||||||
|
|
||||||
## [Examples]({{site.github.url}}/examples): DSL examples.
|
## [Examples]({{site.github.url}}/examples): The DNSControl language by example.
|
||||||
|
|
||||||
## [Migrating]({{site.github.url}}/migrating): Migrating zones to DNSControl.
|
## [Migrating]({{site.github.url}}/migrating): Migrating zones to DNSControl.
|
||||||
|
|
||||||
|
## [Testing]({{site.github.url}}/unittests): Unit Testing DNS Data.
|
||||||
|
|
||||||
## [github](https://github.com/StackExchange/dnscontrol): Get the source!
|
## [github](https://github.com/StackExchange/dnscontrol): Get the source!
|
||||||
|
|
||||||
|
|
||||||
|
33
docs/unittests.md
Normal file
33
docs/unittests.md
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Unit Testing DNS Data
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
dnscontrol -debugjson foo.json print
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Manipulting JSON data is difficult. If you implement ways to make it easier, we'd
|
||||||
|
gladly accept contributions.
|
Reference in New Issue
Block a user