summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_mysql_query.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t/check_mysql_query.t')
-rw-r--r--plugins/t/check_mysql_query.t66
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/t/check_mysql_query.t b/plugins/t/check_mysql_query.t
new file mode 100644
index 0000000..f4743b7
--- /dev/null
+++ b/plugins/t/check_mysql_query.t
@@ -0,0 +1,66 @@
1#! /usr/bin/perl -w -I ..
2#
3# MySQL Database Server Tests via check_mysql
4#
5# $Id$
6#
7#
8# These are the database permissions required for this test:
9# GRANT SELECT ON $db.* TO $user@$host INDENTIFIED BY '$password';
10# Check with:
11# mysql -u$user -p$password -h$host $db
12
13use strict;
14use Test::More;
15use NPTest;
16
17use vars qw($tests);
18
19plan skip_all => "check_mysql_query not compiled" unless (-x "check_mysql_query");
20
21my $mysqlserver = getTestParameter(
22 "NP_MYSQL_SERVER",
23 "A MySQL Server with no slaves setup"
24 );
25my $mysql_login_details = getTestParameter(
26 "MYSQL_LOGIN_DETAILS",
27 "Command line parameters to specify login access",
28 "-u user -ppw -d db",
29 );
30my $result;
31
32if (! $mysqlserver) {
33 plan skip_all => "No mysql server defined";
34} else {
35 plan tests => 13;
36}
37
38$result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver $mysql_login_details");
39cmp_ok( $result->return_code, '==', 0, "Can run query");
40
41$result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details");
42cmp_ok( $result->return_code, '==', 3, "Missing query parmeter");
43like( $result->output, "/Must specify a SQL query to run/", "Missing query error message");
44
45$result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy");
46cmp_ok( $result->return_code, '==', 2, "Login failure");
47like( $result->output, "/Access denied for user /", "Expected login failure message");
48
49$result = NPTest->testCmd("./check_mysql_query -q 'SELECT PI()' -w 3 -c 4 -H $mysqlserver $mysql_login_details");
50cmp_ok( $result->return_code, '==', 1, "Got warning");
51
52$result = NPTest->testCmd("./check_mysql_query -q 'SELECT PI()*2' -w 3 -c 4 -H $mysqlserver $mysql_login_details");
53cmp_ok( $result->return_code, '==', 2, "Got critical");
54
55$result = NPTest->testCmd("./check_mysql_query -q 'SELECT * FROM adsf' -H $mysqlserver $mysql_login_details");
56cmp_ok( $result->return_code, '==', 2, "Bad query");
57like( $result->output, "/Error with query/", "Bad query error message");
58
59$result = NPTest->testCmd("./check_mysql_query -q 'SHOW VARIABLES LIKE \"bob\"' -H $mysqlserver $mysql_login_details");
60cmp_ok( $result->return_code, '==', 1, "No rows");
61like( $result->output, "/No rows returned/", "No rows error message");
62
63$result = NPTest->testCmd("./check_mysql_query -q 'SHOW VARIABLES' -H $mysqlserver $mysql_login_details");
64cmp_ok( $result->return_code, '==', 2, "Data not numeric");
65like( $result->output, "/Is not a numeric/", "Data not numeric error message");
66