tests: improve coverage

Add error condition checks.  Add lease file binding states.  Check all
output formats.  Check leases file that is in mad order, cse all sorting
methods when checking this.  Use json output to check status classfications.
Add cidr range checks.  Add conf include and comment parsing input checks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2017-11-26 15:14:49 +00:00
parent 2849dde21b
commit 447241e6c3
No known key found for this signature in database
GPG key ID: A9553245FDE9B739
33 changed files with 1059 additions and 51 deletions

View file

@ -1,10 +0,0 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
All networks 10.0.0.1 - 10.0.0.10 10 10 100.000 0 10 100.000
Shared networks:
name max cur percent touch t+c t+c perc
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 10 10 100.000 0 10 100.000

1
tests/expected/big-small Symbolic link
View file

@ -0,0 +1 @@
simple

View file

@ -0,0 +1,16 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc bu bu perc
example1 10.0.0.1 - 10.0.0.20 20 4 20.000 3 7 35.000 2 10.000
example1 10.1.0.1 - 10.1.0.20 20 10 50.000 0 10 50.000 0 0.000
example2 10.2.0.1 - 10.2.0.20 20 8 40.000 0 8 40.000 0 0.000
example2 10.3.0.1 - 10.3.0.20 20 9 45.000 0 9 45.000 0 0.000
All networks 10.4.0.1 - 10.4.0.20 20 5 25.000 0 5 25.000 0 0.000
Shared networks:
name max cur percent touch t+c t+c perc bu bu perc
example1 40 14 35.000 3 17 42.500 2 5.000
example2 40 17 42.500 0 17 42.500 0 0.000
Sum of all ranges:
name max cur percent touch t+c t+c perc bu bu perc
All networks 100 36 36.000 3 39 39.000 2 2.000

View file

@ -1,10 +0,0 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
All networks 10.0.0.1 - 10.0.0.10 10 10 100.000 0 10 100.000
Shared networks:
name max cur percent touch t+c t+c perc
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 10 10 100.000 0 10 100.000

1
tests/expected/bootp Symbolic link
View file

@ -0,0 +1 @@
simple

16
tests/expected/cidr-v4 Normal file
View file

@ -0,0 +1,16 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
example1 10.0.0.1 - 10.0.0.31 31 11 35.484 0 11 35.484
example1 10.1.0.1 - 10.1.0.31 31 10 32.258 0 10 32.258
example2 10.2.0.1 - 10.2.0.31 31 8 25.806 0 8 25.806
example2 10.3.0.1 - 10.3.0.31 31 9 29.032 0 9 29.032
All networks 10.4.0.1 - 10.4.0.15 15 5 33.333 0 5 33.333
Shared networks:
name max cur percent touch t+c t+c perc
example1 62 21 33.871 0 21 33.871
example2 62 17 27.419 0 17 27.419
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 139 43 30.935 0 43 30.935

11
tests/expected/cidr-v6 Normal file
View file

@ -0,0 +1,11 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
All networks dead:abba:1000::2 - dead:abba:1000::ff 254 0 0.000 0 0 0.000
All networks dead:abba:4000::2 - dead:abba:4000::ff 254 1 0.394 0 1 0.394
Shared networks:
name max cur percent touch t+c t+c perc
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 508 1 0.197 0 1 0.197

18
tests/expected/errors Normal file
View file

@ -0,0 +1,18 @@
=== output mask
dhcpd-pools: return_limit: output mask '88' is illegal
=== unknown specifier
dhcpd-pools: unknown --skip specifier: okish
=== color mode
dhcpd-pools: unknown color mode: 'sometimes'
=== IPv5
dhcpd-pools: unknown --ip-version argument: 5
=== missing conf
dhcpd-pools: parse_config: ./tests/confs/complete_NXFILE: No such file or directory
=== missing leases
dhcpd-pools: parse_leases: ./tests/leases/complete_NXFILE: No such file or directory
=== html table
dhcpd-pools: html table only output format is deprecated
=== none existing format
dhcpd-pools: unknown output format: 'z'
=== broken percent input
dhcpd-pools: illegal argument: 'eighty'

284
tests/expected/formats Normal file
View file

@ -0,0 +1,284 @@
=== color text
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
example1 10.0.0.1 - 10.0.0.20 20 11 55.000 0 11 55.000
example1 10.1.0.1 - 10.1.0.20 20 10 50.000 0 10 50.000
example2 10.2.0.1 - 10.2.0.20 20 8 40.000 0 8 40.000
example2 10.3.0.1 - 10.3.0.20 20 9 45.000 0 9 45.000
All networks 10.4.0.1 - 10.4.0.20 20 5 25.000 0 5 25.000
Shared networks:
name max cur percent touch t+c t+c perc
example1 40 21 52.500 0 21 52.500
example2 40 17 42.500 0 17 42.500
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 100 43 43.000 0 43 43.000
=== html
<!DOCTYPE html>
<html>
<head>
<title>ISC dhcpd dhcpd-pools output</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs/jq-3.2.1/dt-1.10.16/datatables.min.css">
<style type="text/css">
table.dhcpd-pools th { text-transform: capitalize }
</style>
</head>
<body>
<div class="container">
<h2>ISC DHCPD status</h2>
<h3>Sum of all</h3>
<table id="a" class="dhcpd-pools order-column table table-hover" summary="all">
<thead>
<tr>
<th>name</th>
<th>max</th>
<th>cur</th>
<th>free</th>
<th>percent</th>
<th>touch</th>
<th>t+c</th>
<th>t+c perc</th>
</tr>
</thead>
<tbody>
<tr>
<td>All networks</td>
<td>100</td>
<td>43</td>
<td>57</td>
<td>43.000</td>
<td>0</td>
<td>43</td>
<td>43.000</td>
</tr>
</tbody>
</table>
<h3>Shared networks</h3>
<table id="s" class="dhcpd-pools order-column table table-hover" summary="snet">
<thead>
<tr>
<th>name</th>
<th>max</th>
<th>cur</th>
<th>free</th>
<th>percent</th>
<th>touch</th>
<th>t+c</th>
<th>t+c perc</th>
</tr>
</thead>
<tbody>
<tr>
<td>example1</td>
<td>40</td>
<td>21</td>
<td>19</td>
<td>52.5</td>
<td>0</td>
<td>21</td>
<td>52.500</td>
</tr>
<tr>
<td>example2</td>
<td>40</td>
<td>17</td>
<td>23</td>
<td>42.5</td>
<td>0</td>
<td>17</td>
<td>42.500</td>
</tr>
</tbody>
</table>
<h3>Ranges</h3>
<table id="r" class="dhcpd-pools order-column table table-hover" summary="ranges">
<thead>
<tr>
<th>shared net name</th>
<th>first ip</th>
<th>last ip</th>
<th>max</th>
<th>cur</th>
<th>free</th>
<th>percent</th>
<th>touch</th>
<th>t+c</th>
<th>t+c perc</th>
</tr>
</thead>
<tbody>
<tr>
<td>example1</td>
<td>10.0.0.1</td>
<td>10.0.0.20</td>
<td>20</td>
<td>11</td>
<td>9</td>
<td>55</td>
<td>0</td>
<td>11</td>
<td>55.000</td>
</tr>
<tr>
<td>example1</td>
<td>10.1.0.1</td>
<td>10.1.0.20</td>
<td>20</td>
<td>10</td>
<td>10</td>
<td>50</td>
<td>0</td>
<td>10</td>
<td>50.000</td>
</tr>
<tr>
<td>example2</td>
<td>10.2.0.1</td>
<td>10.2.0.20</td>
<td>20</td>
<td>8</td>
<td>12</td>
<td>40</td>
<td>0</td>
<td>8</td>
<td>40.000</td>
</tr>
<tr>
<td>example2</td>
<td>10.3.0.1</td>
<td>10.3.0.20</td>
<td>20</td>
<td>9</td>
<td>11</td>
<td>45</td>
<td>0</td>
<td>9</td>
<td>45.000</td>
</tr>
<tr>
<td>All networks</td>
<td>10.4.0.1</td>
<td>10.4.0.20</td>
<td>20</td>
<td>5</td>
<td>15</td>
<td>25</td>
<td>0</td>
<td>5</td>
<td>25.000</td>
</tr>
</tbody>
</table>
<br /><div class="well well-lg">
More info at <a href="http://dhcpd-pools.sourceforge.net/">http://dhcpd-pools.sourceforge.net/</a>
</small></div></div>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/jq-3.2.1/dt-1.10.16/datatables.min.js"></script>
<script type="text/javascript" class="init">$(document).ready(function() { $('#s').DataTable({ "iDisplayLength": 50, "lengthMenu": [ [25, 50, 100, -1], [25, 50, 100, "All"] ], "order": [[ 4, "desc" ]] } ); } );</script>
<script type="text/javascript" class="init">$(document).ready(function() { $('#r').DataTable({ "iDisplayLength": 100, "lengthMenu": [ [25, 50, 100, -1], [25, 50, 100, "All"] ], "order": [[ 6, "desc" ]] } ); } );</script>
</body></html>
=== xml
<dhcpstatus>
<subnet>
<location>example1</location>
<range>10.0.0.1 - 10.0.0.20</range>
<defined>20</defined>
<used>11</used>
<touched>0</touched>
<free>9</free>
</subnet>
<subnet>
<location>example1</location>
<range>10.1.0.1 - 10.1.0.20</range>
<defined>20</defined>
<used>10</used>
<touched>0</touched>
<free>10</free>
</subnet>
<subnet>
<location>example2</location>
<range>10.2.0.1 - 10.2.0.20</range>
<defined>20</defined>
<used>8</used>
<touched>0</touched>
<free>12</free>
</subnet>
<subnet>
<location>example2</location>
<range>10.3.0.1 - 10.3.0.20</range>
<defined>20</defined>
<used>9</used>
<touched>0</touched>
<free>11</free>
</subnet>
<subnet>
<location>All networks</location>
<range>10.4.0.1 - 10.4.0.20</range>
<defined>20</defined>
<used>5</used>
<touched>0</touched>
<free>15</free>
</subnet>
<shared-network>
<location>example1</location>
<defined>40</defined>
<used>21</used>
<touched>0</touched>
<free>19</free>
</shared-network>
<shared-network>
<location>example2</location>
<defined>40</defined>
<used>17</used>
<touched>0</touched>
<free>23</free>
</shared-network>
<summary>
<location>All networks</location>
<defined>100</defined>
<used>43</used>
<touched>0</touched>
<free>57</free>
</summary>
</dhcpstatus>
=== csv
"Ranges:"
"shared net name","first ip","last ip","max","cur","percent","touch","t+c","t+c perc"
"example1","10.0.0.1","10.0.0.20","20","11","55.000","0","11","55.000"
"example1","10.1.0.1","10.1.0.20","20","10","50.000","0","10","50.000"
"example2","10.2.0.1","10.2.0.20","20","8","40.000","0","8","40.000"
"example2","10.3.0.1","10.3.0.20","20","9","45.000","0","9","45.000"
"All networks","10.4.0.1","10.4.0.20","20","5","25.000","0","5","25.000"
"Shared networks:"
"name","max","cur","percent","touch","t+c","t+c perc"
"example1","40","21","52.500","0","21","52.500"
"example2","40","17","42.500","0","17","42.500"
"Sum of all ranges:"
"name","max","cur","percent","touch","t+c","t+c perc"
"All networks","100","43","43.000","0","43","43.000"
=== json
{
"subnets": [
{ "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":0 },
{ "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":0 },
{ "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":0 },
{ "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":0 },
{ "location":"All networks", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":0 }
],
"shared-networks": [
{ "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":0 },
{ "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":0 }
]
}
=== perfdata
CRITICAL: dhcpd-pools: Ranges - crit: 3 warn: 2 ok: 0; | range_crit=3 range_warn=2 range_ok=0 10.4.0.1_r=5;4;8;0;20 10.4.0.1_rt=0 10.3.0.1_r=9;4;8;0;20 10.3.0.1_rt=0 10.2.0.1_r=8;4;8;0;20 10.2.0.1_rt=0 10.1.0.1_r=10;4;8;0;20 10.1.0.1_rt=0 10.0.0.1_r=11;4;8;0;20 10.0.0.1_rt=0
Shared nets - crit: 2 warn: 0 ok: 0; | snet_crit=2 snet_warn=0 snet_ok=0 'example1_s'=21;8;16;0;40 'example1_st'=0 'example2_s'=17;8;16;0;40 'example2_st'=0

1
tests/expected/parser Symbolic link
View file

@ -0,0 +1 @@
complete

16
tests/expected/shufled Normal file
View file

@ -0,0 +1,16 @@
Ranges:
shared net name first ip last ip max cur percent touch t+c t+c perc
All networks 10.4.0.1 - 10.4.0.20 20 3 15.000 0 3 15.000
example1 10.0.0.1 - 10.0.0.20 20 9 45.000 0 9 45.000
example1 10.1.0.1 - 10.1.0.20 20 4 20.000 0 4 20.000
example2 10.2.0.1 - 10.2.0.20 20 4 20.000 0 4 20.000
example2 10.3.0.1 - 10.3.0.20 20 3 15.000 0 3 15.000
Shared networks:
name max cur percent touch t+c t+c perc
example1 40 13 32.500 0 13 32.500
example2 40 7 17.500 0 7 17.500
Sum of all ranges:
name max cur percent touch t+c t+c perc
All networks 100 23 23.000 0 23 23.000

29
tests/expected/statuses Normal file
View file

@ -0,0 +1,29 @@
{
"subnets": [
{ "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":4 },
{ "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":4 },
{ "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":4 },
{ "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":4 },
{ "location":"10.4.0.0/24", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":4 }
],
"shared-networks": [
{ "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":2 },
{ "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":2 },
{ "location":"10.4.0.0/24", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":1 }
]
}
== minsize
{
"subnets": [
{ "location":"example1", "range":"10.0.0.1 - 10.0.0.20", "first_ip":"10.0.0.1", "last_ip":"10.0.0.20", "defined":20, "used":11, "touched":0, "free":9, "percent":55, "touch_count":11, "touch_percent":55, "status":3 },
{ "location":"example1", "range":"10.1.0.1 - 10.1.0.20", "first_ip":"10.1.0.1", "last_ip":"10.1.0.20", "defined":20, "used":10, "touched":0, "free":10, "percent":50, "touch_count":10, "touch_percent":50, "status":3 },
{ "location":"example2", "range":"10.2.0.1 - 10.2.0.20", "first_ip":"10.2.0.1", "last_ip":"10.2.0.20", "defined":20, "used":8, "touched":0, "free":12, "percent":40, "touch_count":8, "touch_percent":40, "status":3 },
{ "location":"example2", "range":"10.3.0.1 - 10.3.0.20", "first_ip":"10.3.0.1", "last_ip":"10.3.0.20", "defined":20, "used":9, "touched":0, "free":11, "percent":45, "touch_count":9, "touch_percent":45, "status":3 },
{ "location":"10.4.0.0/24", "range":"10.4.0.1 - 10.4.0.20", "first_ip":"10.4.0.1", "last_ip":"10.4.0.20", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":3 }
],
"shared-networks": [
{ "location":"example1", "defined":40, "used":21, "touched":0, "free":19, "percent":52.5, "touch_count":21, "touch_percent":52.5, "status":2 },
{ "location":"example2", "defined":40, "used":17, "touched":0, "free":23, "percent":42.5, "touch_count":17, "touch_percent":42.5, "status":2 },
{ "location":"10.4.0.0/24", "defined":20, "used":5, "touched":0, "free":15, "percent":25, "touch_count":5, "touch_percent":25, "status":3 }
]
}