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

@ -11,21 +11,29 @@ TESTS = \
tests/alarm-warning-snets \
tests/shnet-alarm \
tests/big-small \
tests/binding-states \
tests/bootp \
tests/cidr-v4 \
tests/cidr-v6 \
tests/complete \
tests/complete-perfdata \
tests/empty \
tests/errors \
tests/full-json \
tests/full-xml \
tests/formats \
tests/leading0 \
tests/one-ip \
tests/one-line \
tests/parser \
tests/range4 \
tests/range6 \
tests/same-twice \
tests/shufled \
tests/simple \
tests/skip \
tests/sorts \
tests/statuses \
tests/v6 \
tests/v6-perfdata

14
tests/binding-states Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
#
# Minimal regression test suite.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=never \
-l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
exit $?

1
tests/cidr-v4 Symbolic link
View file

@ -0,0 +1 @@
test.sh

1
tests/cidr-v6 Symbolic link
View file

@ -0,0 +1 @@
test.sh

1
tests/confs/binding-states Symbolic link
View file

@ -0,0 +1 @@
complete

31
tests/confs/cidr-v4 Normal file
View file

@ -0,0 +1,31 @@
shared-network example1 {
subnet 10.0.0.0 netmask 255.255.255.0 {
pool {
range 10.0.0.1/27;
}
}
subnet 10.1.0.0 netmask 255.255.255.0 {
pool {
range 10.1.0.1/27;
}
}
}
shared-network example2 {
subnet 10.2.0.0 netmask 255.255.255.0 {
pool {
range 10.2.0.1/27;
}
}
subnet 10.3.0.0 netmask 255.255.255.0 {
pool {
range 10.3.0.1/27;
}
}
}
subnet 10.4.0.0 netmask 255.255.255.0 {
pool {
range 10.4.0.1/28;
}
}

10
tests/confs/cidr-v6 Normal file
View file

@ -0,0 +1,10 @@
subnet6 dead:abba:1000::/56 {
range6 dead:abba:1000::2/120;
prefix6 dead:abba:1000:0100:: dead:abba:1000:ff00::/56;
}
subnet6 dead:abba:40ff::/56 {
range6 dead:abba:4000::2/120;
prefix6 dead:abba:4000:0100:: dead:abba:4000:ff00::/56;
}

1
tests/confs/formats Symbolic link
View file

@ -0,0 +1 @@
complete

View file

@ -1,31 +0,0 @@
shared-network example1 {
subnet 10.0.0.0 netmask 255.255.255.0 {
pool {
range 10.0.0.1 10.0.0.20;
}
}
subnet 10.1.0.0 netmask 255.255.255.0 {
pool {
range 10.1.0.1 10.1.0.20;
}
}
}
shared-network example2 {
subnet 10.2.0.0 netmask 255.255.255.0 {
pool {
range 10.2.0.1 10.2.0.20;
}
}
subnet 10.3.0.0 netmask 255.255.255.0 {
pool {
range 10.3.0.1 10.3.0.20;
}
}
}
subnet 10.4.0.0 netmask 255.255.255.0 {
pool {
range 10.4.0.1 10.4.0.20;
}
}

1
tests/confs/shnet-alarm Symbolic link
View file

@ -0,0 +1 @@
complete

1
tests/confs/shufled Symbolic link
View file

@ -0,0 +1 @@
complete

1
tests/confs/statuses Symbolic link
View file

@ -0,0 +1 @@
complete

48
tests/errors Executable file
View file

@ -0,0 +1,48 @@
#!/bin/sh
#
# Test error inputs.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
echo '=== output mask' >| tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
-L 88 >> tests/outputs/$IAM 2>&1
echo '=== unknown specifier' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
--skip=okish >> tests/outputs/$IAM 2>&1
echo '=== color mode' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
--color=sometimes >> tests/outputs/$IAM 2>&1
echo '=== IPv5' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
--ip-version=5 >> tests/outputs/$IAM 2>&1
echo '=== missing conf' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete_NXFILE -l $top_srcdir/tests/leases/complete 2>&1 | \
sed 's/: ..\/..\/tests/: .\/tests/'>> tests/outputs/$IAM
echo '=== missing leases' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete_NXFILE 2>&1 | \
sed 's/: ..\/..\/tests/: .\/tests/' >> tests/outputs/$IAM
echo '=== html table' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
--format=html >> tests/outputs/$IAM 2>&1
echo '=== none existing format' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
-fz >> tests/outputs/$IAM 2>&1
echo '=== broken percent input' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/complete -l $top_srcdir/tests/leases/complete \
--warning=eighty >> tests/outputs/$IAM 2>&1
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
exit $?

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 }
]
}

37
tests/formats Executable file
View file

@ -0,0 +1,37 @@
#!/bin/sh
#
# Minimal regression test suite.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
echo '=== color text' > tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=always \
-l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM
echo '=== html' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=always --format=H \
-l $top_srcdir/tests/leases/$IAM |
sed '/was last modified at/d; /Generated using/d' >> tests/outputs/$IAM
echo '=== xml' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fx \
-l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM
echo '=== csv' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fc \
-l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM
echo '=== json' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM -fj --limit=33 \
-l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM
echo '=== perfdata' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --perfdata --warning=20 --critical=40 \
-l $top_srcdir/tests/leases/$IAM >> tests/outputs/$IAM
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
exit $?

241
tests/leases/binding-states Normal file
View file

@ -0,0 +1,241 @@
lease 10.0.0.0 {
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
lease 10.0.0.1 {
binding state free;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.1 {
binding state active;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.1 {
binding state abandoned;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.1 {
binding state expired;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.1 {
binding state released;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.1 {
binding state backup;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.0.0.2 {
binding state free;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.2 {
binding state abandoned;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.2 {
binding state expired;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.2 {
binding state released;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.2 {
binding state backup;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.0.0.3 {
binding state free;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.0.0.4 {
binding state active;
hardware ethernet 00:00:00:00:00:04;
}
lease 10.0.0.5 {
binding state expired;
hardware ethernet 00:00:00:00:00:05;
}
lease 10.0.0.6 {
binding state released;
hardware ethernet 00:00:00:00:00:06;
}
lease 10.0.0.7 {
binding state backup;
hardware ethernet 00:00:00:00:00:07;
}
lease 10.0.0.8 {
binding state none-existing-state;
hardware ethernet 00:00:00:00:00:08;
}
lease 10.0.0.9 {
binding state active;
hardware ethernet 00:00:00:00:00:09;
}
lease 10.0.0.20 {
binding state active;
hardware ethernet 00:00:00:00:00:10;
}
lease 10.0.0.21 {
binding state active;
hardware ethernet 00:00:00:00:00:11;
}
lease 10.1.0.0 {
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
lease 10.1.0.1 {
binding state active;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.1.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.1.0.3 {
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.1.0.4 {
binding state active;
hardware ethernet 00:00:00:00:00:04;
}
lease 10.1.0.5 {
binding state active;
hardware ethernet 00:00:00:00:00:05;
}
lease 10.1.0.6 {
binding state active;
hardware ethernet 00:00:00:00:00:06;
}
lease 10.1.0.7 {
binding state active;
hardware ethernet 00:00:00:00:00:07;
}
lease 10.1.0.8 {
binding state active;
hardware ethernet 00:00:00:00:00:08;
}
lease 10.1.0.9 {
binding state active;
hardware ethernet 00:00:00:00:00:09;
}
lease 10.1.0.10 {
binding state active;
hardware ethernet 00:00:00:00:00:10;
}
lease 10.2.0.0 {
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
lease 10.2.0.1 {
binding state active;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.2.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.2.0.3 {
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.2.0.4 {
binding state active;
hardware ethernet 00:00:00:00:00:04;
}
lease 10.2.0.5 {
binding state active;
hardware ethernet 00:00:00:00:00:05;
}
lease 10.2.0.6 {
binding state active;
hardware ethernet 00:00:00:00:00:06;
}
lease 10.2.0.7 {
binding state active;
hardware ethernet 00:00:00:00:00:07;
}
lease 10.2.0.8 {
binding state active;
hardware ethernet 00:00:00:00:00:08;
}
lease 10.3.0.0 {
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
lease 10.3.0.1 {
binding state active;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.3.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.3.0.3 {
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.3.0.4 {
binding state active;
hardware ethernet 00:00:00:00:00:04;
}
lease 10.3.0.5 {
binding state active;
hardware ethernet 00:00:00:00:00:05;
}
lease 10.3.0.6 {
binding state active;
hardware ethernet 00:00:00:00:00:06;
}
lease 10.3.0.7 {
binding state active;
hardware ethernet 00:00:00:00:00:07;
}
lease 10.3.0.8 {
binding state active;
hardware ethernet 00:00:00:00:00:08;
}
lease 10.3.0.9 {
binding state active;
hardware ethernet 00:00:00:00:00:09;
}
lease 10.4.0.0 {
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
lease 10.4.0.1 {
binding state active;
hardware ethernet 00:00:00:00:00:01;
}
lease 10.4.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:02;
}
lease 10.4.0.3 {
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.4.0.4 {
binding state active;
hardware ethernet 00:00:00:00:00:04;
}
lease 10.4.0.5 {
binding state active;
hardware ethernet 00:00:00:00:00:05;
}

1
tests/leases/cidr-v4 Symbolic link
View file

@ -0,0 +1 @@
complete

1
tests/leases/cidr-v6 Symbolic link
View file

@ -0,0 +1 @@
v6

1
tests/leases/formats Symbolic link
View file

@ -0,0 +1 @@
complete

1
tests/leases/parser Symbolic link
View file

@ -0,0 +1 @@
complete

198
tests/leases/shufled Normal file
View file

@ -0,0 +1,198 @@
lease 10.0.0.7 {
}
binding state active;
hardware ethernet 00:00:00:00:00:07;
hardware ethernet 00:00:00:00:00:10;
lease 10.2.0.4 {
lease 10.2.0.6 {
lease 10.0.0.11 {
binding state active;
}
hardware ethernet 00:00:00:00:00:03;
lease 10.3.0.9 {
}
hardware ethernet 00:00:00:00:00:04;
}
binding state active;
lease 10.1.0.7 {
}
}
lease 10.1.0.9 {
hardware ethernet 00:00:00:00:00:07;
hardware ethernet 00:00:00:00:00:01;
binding state active;
binding state active;
}
}
}
binding state active;
lease 10.4.0.1 {
}
lease 10.0.0.0 {
}
hardware ethernet 00:00:00:00:00:10;
}
}
binding state active;
hardware ethernet 00:00:00:00:00:00;
}
}
binding state active;
}
lease 10.3.0.2 {
hardware ethernet 00:00:00:00:00:01;
binding state active;
hardware ethernet 00:00:00:00:00:02;
binding state active;
lease 10.1.0.3 {
binding state active;
}
binding state active;
}
lease 10.1.0.1 {
lease 10.3.0.8 {
lease 10.2.0.1 {
hardware ethernet 00:00:00:00:00:07;
}
}
lease 10.4.0.0 {
hardware ethernet 00:00:00:00:00:01;
}
binding state active;
hardware ethernet 00:00:00:00:00:02;
lease 10.0.0.10 {
binding state active;
}
hardware ethernet 00:00:00:00:00:04;
hardware ethernet 00:00:00:00:00:11;
hardware ethernet 00:00:00:00:00:08;
binding state active;
hardware ethernet 00:00:00:00:00:08;
binding state active;
lease 10.2.0.5 {
hardware ethernet 00:00:00:00:00:01;
lease 10.1.0.8 {
lease 10.0.0.3 {
binding state active;
binding state active;
lease 10.0.0.1 {
lease 10.4.0.5 {
hardware ethernet 00:00:00:00:00:06;
hardware ethernet 00:00:00:00:00:06;
hardware ethernet 00:00:00:00:00:02;
lease 10.2.0.3 {
binding state active;
lease 10.1.0.10 {
binding state active;
}
}
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
}
hardware ethernet 00:00:00:00:00:05;
lease 10.0.0.2 {
}
binding state active;
}
hardware ethernet 00:00:00:00:00:06;
lease 10.3.0.6 {
lease 10.0.0.8 {
hardware ethernet 00:00:00:00:00:01;
lease 10.4.0.3 {
}
}
}
binding state active;
binding state active;
lease 10.1.0.6 {
lease 10.1.0.2 {
hardware ethernet 00:00:00:00:00:05;
binding state active;
}
}
lease 10.2.0.7 {
}
}
hardware ethernet 00:00:00:00:00:03;
binding state active;
}
binding state active;
hardware ethernet 00:00:00:00:00:03;
}
lease 10.1.0.0 {
hardware ethernet 00:00:00:00:00:04;
binding state active;
}
lease 10.3.0.1 {
lease 10.2.0.2 {
binding state active;
hardware ethernet 00:00:00:00:00:09;
}
binding state active;
hardware ethernet 00:00:00:00:00:00;
binding state active;
lease 10.0.0.6 {
hardware ethernet 00:00:00:00:00:02;
binding state active;
}
binding state active;
}
lease 10.3.0.0 {
lease 10.0.0.9 {
binding state active;
lease 10.0.0.4 {
hardware ethernet 00:00:00:00:00:08;
binding state active;
hardware ethernet 00:00:00:00:00:07;
hardware ethernet 00:00:00:00:00:00;
binding state active;
lease 10.1.0.4 {
lease 10.4.0.2 {
binding state active;
}
}
lease 10.3.0.4 {
hardware ethernet 00:00:00:00:00:05;
hardware ethernet 00:00:00:00:00:05;
binding state active;
binding state active;
lease 10.0.0.5 {
hardware ethernet 00:00:00:00:00:04;
binding state active;
hardware ethernet 00:00:00:00:00:02;
binding state active;
hardware ethernet 00:00:00:00:00:09;
hardware ethernet 00:00:00:00:00:08;
lease 10.2.0.8 {
}
binding state active;
binding state active;
hardware ethernet 00:00:00:00:00:06;
hardware ethernet 00:00:00:00:00:00;
lease 10.3.0.7 {
lease 10.4.0.4 {
}
hardware ethernet 00:00:00:00:00:04;
}
binding state active;
lease 10.3.0.3 {
hardware ethernet 00:00:00:00:00:03;
lease 10.2.0.0 {
binding state active;
binding state active;
hardware ethernet 00:00:00:00:00:05;
binding state active;
}
hardware ethernet 00:00:00:00:00:00;
binding state active;
lease 10.1.0.5 {
hardware ethernet 00:00:00:00:00:09;
lease 10.3.0.5 {
}

1
tests/leases/statuses Symbolic link
View file

@ -0,0 +1 @@
complete

30
tests/parser Executable file
View file

@ -0,0 +1,30 @@
#!/bin/sh
#
# Minimal regression test suite.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
cat <<EOF >"./${IAM}-conf"
#shared-network "example3 " {
# subnet 10.0.6.0 netmask 255.255.255.0 {
# pool {
# range 10.0.6.1 10.0.6.20;
# }
# }
# subnet 10.1.7.0 netmask 255.255.255.0 {
# pool {
# range 10.1.7.1 10.1.7.20;
# }
# }
#}
include "tests/confs/complete";
EOF
dhcpd-pools -c "./${IAM}-conf" --color=never \
-l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
rm -f "./${IAM}-conf"
exit $?

15
tests/shufled Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
#
# Minimal regression test suite.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --color=never \
--sort nimcptTenimcptTe --sort nimcptTe \
-l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
exit $?

22
tests/statuses Executable file
View file

@ -0,0 +1,22 @@
#!/bin/sh
#
# Test json status field values.
IAM=$(basename $0)
if [ ! -d tests/outputs ]; then
mkdir tests/outputs
fi
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --format=json -L33 \
-l $top_srcdir/tests/leases/$IAM -o tests/outputs/$IAM \
--warning=20 --critical=41 --all-as-shared --snet-alarms --all-as-shared
echo '== minsize' >> tests/outputs/$IAM
dhcpd-pools -c $top_srcdir/tests/confs/$IAM --format=json --limit 33 \
-l $top_srcdir/tests/leases/$IAM --minsize=20 \
--warning=20 --critical=41 --all-as-shared --snet-alarms --all-as-shared \
>> tests/outputs/$IAM
diff -u $top_srcdir/tests/expected/$IAM tests/outputs/$IAM
exit $?