App-GitHooks-Plugin-PgBouncerAuthSyntax

 view release on metacpan or  search on metacpan

lib/App/GitHooks/Plugin/PgBouncerAuthSyntax.pm  view on Meta::CPAN

			push(
				@issues,
				{
					line_number => $i,
					line        => $line,
				}
			);
			next;
		}

		# Skip lines with the correct username/password specification.
		next
			if $line =~ /
					^
					"[^"]*"   # Username.
					\         # Space.
					"[^"]*"   # Password.
					(?:\ .*)? # Remainder of the line, no specific format required except
					          # for a space if anything follows.
					$
				/x;

t/10-run.t  view on Meta::CPAN

test_requires_git( '1.7.4.1' );

# List of tests to perform.
my $tests =
[
	{
		comments_setting => 'allow_anywhere',
		name             => 'Pass syntax check (two fields).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|,
		},
		expected         => qr/o The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'allow_anywhere',
		name     => 'Pass syntax check (extra information).',
		files    =>
		{
			'userlist.txt' => qq|"user" "password" "something else"\n|,
		},
		expected => qr/o The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'allow_anywhere',
		name             => 'Fail syntax check (extra double quote).',
		files            =>
		{
			'userlist.txt' => qq|"us"er" "password"\n|,
		},
		expected         => qr/\Qx The PgBouncer syntax is correct\E.*\QLine 0: "us"er" "password"\E/s,
	},
	{
		comments_setting => 'allow_anywhere',
		name             => 'Fail syntax check (extra double quote in later line).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|"us"er" "password"\n|,
		},
		expected         => qr/\Qx The PgBouncer syntax is correct\E.*\QLine 1: "us"er" "password"\E/s,
	},
	{
		comments_setting => 'allow_anywhere',
		name             => 'Fail syntax check (only one field provided).',
		files            =>
		{
			'userlist.txt' => qq|"user"\n|,
		},
		expected => qr/\Qx The PgBouncer syntax is correct\E.*\QLine 0: "user"\E/s,
	},

t/10-run.t  view on Meta::CPAN

		{
			'test.txt'     => qq|"user"\n|,
		},
		expected         => qr/(?!\QThe PgBouncer syntax is correct\E)/,
	},
	{
		comments_setting => 'allow_anywhere',
		name             => 'Ignore comment lines (comments_setting=allow_anywhere).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|; A commment\n|
				. qq|"user" "password"\n|,
		},
		expected         => qr/o The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'allow_end_only',
		name             => 'Ignore comment lines at the end of the file (comments_setting=allow_end_only).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|"user" "password"\n|
				. qq|; A commment\n|,
		},
		expected         => qr/o The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'allow_end_only',
		name             => 'Prevent comment lines not at the end of the file (comments_setting=allow_end_only).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|; A commment\n|
				. qq|"user" "password"\n|,
		},
		expected         => qr/x The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'disallow',
		name             => 'Prevent comment lines at the end of the file (comments_setting=disallow).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|"user" "password"\n|
				. qq|; A commment\n|,
		},
		expected         => qr/x The PgBouncer syntax is correct/,
	},
	{
		comments_setting => 'disallow',
		name             => 'Prevent comment lines not at the end of the file (comments_setting=disallow).',
		files            =>
		{
			'userlist.txt' => qq|"user" "password"\n|
				. qq|; A commment\n|
				. qq|"user" "password"\n|,
		},
		expected         => qr/x The PgBouncer syntax is correct/,
	},
];

# Bail out if Git isn't available.
test_requires_git();
plan( tests => scalar( @$tests ) );

foreach my $test ( @$tests )



( run in 1.056 second using v1.01-cache-2.11-cpan-49f99fa48dc )