From d8aae53968a0a2be66d8ae49db923e4d3f29287e Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Fri, 7 Dec 2012 20:25:21 +0000 Subject: [PATCH] tests: add json tests, and make fail output loud Gilles reported the full-json is currently broken, which the new check demonstrates. Luckily the issue occurs only when active leases details are being queried, leaving the count to be correct. That said bug is a bug, and that should be corrected. Reported-by: Gilles Bouthenot Signed-off-by: Sami Kerola --- tests/Makefile.am | 14 ++++++++++---- tests/confs/same-twice | 1 + tests/expected/same-twice | 10 ++++++++++ tests/expected/same-twice-json | 16 ++++++++++++++++ tests/full-json | 14 ++++++++++++++ tests/leases/same-twice | 10 ++++++++++ tests/same-twice | 1 + tests/test.sh | 2 +- 8 files changed, 63 insertions(+), 5 deletions(-) create mode 120000 tests/confs/same-twice create mode 100644 tests/expected/same-twice create mode 100644 tests/expected/same-twice-json create mode 100755 tests/full-json create mode 100644 tests/leases/same-twice create mode 120000 tests/same-twice diff --git a/tests/Makefile.am b/tests/Makefile.am index 0a062c1..6aa921e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,14 +1,20 @@ EXTRA_DIST = \ bootp \ + full-json \ confs \ expected \ leading0 \ leases \ - simple \ - test.sh + same-twice \ + simple -TESTS = simple bootp leading0 v6 -check_SCRIPTS = test.sh +TESTS = \ + bootp \ + full-json \ + leading0 \ + same-twice \ + simple \ + v6 check-local: $(SHELL) $(top_srcdir)/tests/test.sh diff --git a/tests/confs/same-twice b/tests/confs/same-twice new file mode 120000 index 0000000..8fd3246 --- /dev/null +++ b/tests/confs/same-twice @@ -0,0 +1 @@ +simple \ No newline at end of file diff --git a/tests/expected/same-twice b/tests/expected/same-twice new file mode 100644 index 0000000..477fc7e --- /dev/null +++ b/tests/expected/same-twice @@ -0,0 +1,10 @@ +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 1 10.000 0 1 10.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 1 10.000 0 1 10.000 diff --git a/tests/expected/same-twice-json b/tests/expected/same-twice-json new file mode 100644 index 0000000..aa0c419 --- /dev/null +++ b/tests/expected/same-twice-json @@ -0,0 +1,16 @@ +{ + "active_leases": [ + { "ip":"10.0.0.5", "macaddress":"00:00:00:00:00:00" } + ], + "subnets": [ + { "location":"All networks", "range":"10.0.0.1 - 10.0.0.10", "defined":10, "used":1, "free":9 } + ], + "shared-networks": [ + ], + "summary": { + "location":"All networks", + "defined":10, + "used":1, + "free":9 + } +} diff --git a/tests/full-json b/tests/full-json new file mode 100755 index 0000000..93c4ffd --- /dev/null +++ b/tests/full-json @@ -0,0 +1,14 @@ +#!/bin/sh +# +# Minimal regression test suite. + +TEST_TOPDIR=$(cd $(dirname $0) && pwd) +DHCPD_POOLS=$(readlink -f $TEST_TOPDIR/../src/dhcpd-pools) + +if [ ! -d outputs ]; then + mkdir outputs +fi + +$DHCPD_POOLS -f J -c confs/same-twice -l leases/same-twice -o outputs/same-twice-json +diff -u expected/same-twice-json outputs/same-twice-json +exit $? diff --git a/tests/leases/same-twice b/tests/leases/same-twice new file mode 100644 index 0000000..1a5179a --- /dev/null +++ b/tests/leases/same-twice @@ -0,0 +1,10 @@ +lease 10.0.0.5 { + binding state active; + next binding state free; + hardware ethernet be:ef:00:00:co:de; +} +lease 10.0.0.5 { + binding state active; + next binding state free; + hardware ethernet 00:00:00:00:00:00; +} diff --git a/tests/same-twice b/tests/same-twice new file mode 120000 index 0000000..61a58b0 --- /dev/null +++ b/tests/same-twice @@ -0,0 +1 @@ +test.sh \ No newline at end of file diff --git a/tests/test.sh b/tests/test.sh index f1f1587..3b06828 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -11,5 +11,5 @@ if [ ! -d outputs ]; then fi $DHCPD_POOLS -c confs/$IAM -l leases/$IAM -o outputs/$IAM -diff -q expected/$IAM outputs/$IAM >/dev/null +diff -u expected/$IAM outputs/$IAM exit $?