github.com/teknogeek/dnscontrol@v0.2.8/docs/unittests.md (about)

     1  ---
     2  layout: default
     3  title: Unit Testing DNS Data
     4  ---
     5  
     6  # Unit Testing DNS Data
     7  
     8  ## Built-in Tests
     9  
    10  DNSControl performs a number of tests during the validation stage.
    11  You can find them in `pkg/normalize/validate.go`.
    12  
    13  
    14  ## External tests
    15  
    16  Tests specific to your environment may be added as external tests.
    17  Output the intermediate representation as a JSON file and perform
    18  tests on this data.
    19  
    20  Output the intermediate representation:
    21  
    22      dnscontrol print-ir --out foo.json --pretty
    23  
    24  NOTE: The `--pretty` flag is optional.
    25  
    26  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:
    27  
    28      COUNTMX=$(jq --raw-output <foo.json '.domains[] | select(.name == "stackex.com") | .records[] | select(.type == "MX") | .target' | wc -l)
    29      echo COUNT=:"$COUNTMX":
    30      if [[ "$COUNTMX" -eq "5" ]]; then
    31        echo GOOD
    32      else
    33        echo BAD
    34      fi
    35  
    36  
    37  ## Future directions
    38  
    39  Manipulting JSON data is difficult. If you implement ways to make it easier, we'd
    40  gladly accept contributions.