From eaf9908edd7bce25412dcdf4d96b23f3a3cafd57 Mon Sep 17 00:00:00 2001 From: Ton Voon Date: Thu, 24 May 2007 08:35:53 +0000 Subject: Tests for check_dummy git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1716 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/plugins/check_dummy.c b/plugins/check_dummy.c index dfd6c9c..876ebb1 100644 --- a/plugins/check_dummy.c +++ b/plugins/check_dummy.c @@ -84,8 +84,10 @@ main (int argc, char **argv) printf (_("UNKNOWN")); break; default: + printf (_("UNKNOWN")); + printf (": "); printf (_("Status %d is not a supported error state\n"), result); - break; + return STATE_UNKNOWN; } if (argc >= 3) diff --git a/plugins/t/check_dummy.t b/plugins/t/check_dummy.t new file mode 100644 index 0000000..aaa7a41 --- /dev/null +++ b/plugins/t/check_dummy.t @@ -0,0 +1,55 @@ +#! /usr/bin/perl -w -I .. +# +# check_dummy tests +# +# $Id$ +# + +use strict; +use Test::More; +use NPTest; + +plan tests => 20; + +my $res; + +$res = NPTest->testCmd("./check_dummy"); +is( $res->return_code, 3, "No args" ); +like( $res->output, "/Could not parse arguments/", "Correct usage message"); + +$res = NPTest->testCmd("./check_dummy 0"); +is( $res->return_code, 0, "OK state returned"); +is( $res->output, "OK", "Says 'OK'"); + +$res = NPTest->testCmd("./check_dummy 0 'some random data'"); +is( $res->return_code, 0, "Still OK"); +is( $res->output, "OK: some random data", "Sample text okay"); + +$res = NPTest->testCmd("./check_dummy 1"); +is( $res->return_code, 1, "Warning okay"); +is( $res->output, "WARNING", "Says 'WARNING'"); + +$res = NPTest->testCmd("./check_dummy 1 'more stuff'"); +is( $res->return_code, 1, "Still warning"); +is( $res->output, "WARNING: more stuff", "optional text okay" ); + +$res = NPTest->testCmd("./check_dummy 2"); +is( $res->return_code, 2, "Critical ok" ); +is( $res->output, "CRITICAL", "Says 'CRITICAL'"); + +$res = NPTest->testCmd("./check_dummy 2 'roughly drafted'"); +is( $res->return_code, 2, "Still critical"); +is( $res->output, "CRITICAL: roughly drafted", "optional text okay" ); + +$res = NPTest->testCmd("./check_dummy 3"); +is( $res->return_code, 3, "Unknown ok" ); +is( $res->output, "UNKNOWN", "Says 'UNKNOWN'"); + +$res = NPTest->testCmd("./check_dummy 3 'daringfireball'"); +is( $res->return_code, 3, "Still unknown"); +is( $res->output, "UNKNOWN: daringfireball", "optional text okay" ); + +$res = NPTest->testCmd("./check_dummy 4"); +is( $res->return_code, 3, "Invalid error code" ); +is( $res->output, "UNKNOWN: Status 4 is not a supported error state", "With appropriate error message"); + -- cgit v0.10-9-g596f