summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_mysql.t
blob: 764db72c1ddda7dbaf414cd29b3944faa336e1f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#! /usr/bin/perl -w -I ..
#
# MySQL Database Server Tests via check_mysql
#
# $Id$
#

use strict;
use Test::More;
use NPTest;

use vars qw($tests);

plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");

plan tests => 7;

my $bad_login_output = '/Access denied for user /';
my $mysqlserver = getTestParameter( 
		"NP_MYSQL_SERVER", 
		"A MySQL Server with no slaves setup"
		);
my $mysql_login_details = getTestParameter( 
		"MYSQL_LOGIN_DETAILS", 
		"Command line parameters to specify login access",
		"-u user -ppw",
		);
my $with_slave = getTestParameter( 
		"NP_MYSQL_WITH_SLAVE", 
		"MySQL server with slaves setup"
		);
my $with_slave_login = getTestParameter( 
		"NP_MYSQL_WITH_SLAVE_LOGIN", 
		"Login details for server with slave", 
		"-uroot -ppw"
		);

my $result;

SKIP: {
	skip "No mysql server defined", 5 unless $mysqlserver;
	$result = NPTest->testCmd("./check_mysql -H $mysqlserver $mysql_login_details");
	cmp_ok( $result->return_code, '==', 0, "Login okay");

	$result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy");
	cmp_ok( $result->return_code, '==', 2, "Login failure");
	like( $result->output, $bad_login_output, "Expected login failure message");

	$result = NPTest->testCmd("./check_mysql -S -H $mysqlserver $mysql_login_details");
	cmp_ok( $result->return_code, "==", 1, "No slaves defined" );
	like( $result->output, "/No slaves defined/", "Correct error message");
}

SKIP: {
	skip "No mysql server with slaves defined", 2 unless $with_slave;
	$result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login");
	cmp_ok( $result->return_code, '==', 0, "Login okay");

	$result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login");
	cmp_ok( $result->return_code, "==", 0, "Slaves okay" );
}