summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-08-10 21:41:53 +0200
committerdklawren <dklawren@users.noreply.github.com>2018-08-10 21:41:53 +0200
commitea5beeacb185309572836cc60989f95ea4705f9d (patch)
tree1f8f44b5d1dba73fb05214ba1e539c0918d42bb9
parent53e1adcc77b3e68c1d8659d418aa5639d9917e42 (diff)
downloadbugzilla-ea5beeacb185309572836cc60989f95ea4705f9d.tar.gz
bugzilla-ea5beeacb185309572836cc60989f95ea4705f9d.tar.xz
Bug 1482475 - Add extensive testing framework
-rw-r--r--.circleci/config.yml2
-rw-r--r--Bugzilla.pm3
-rw-r--r--Bugzilla/Config.pm37
-rw-r--r--Bugzilla/DB/Sqlite.pm2
-rw-r--r--Bugzilla/Test/MockDB.pm49
-rw-r--r--Bugzilla/Test/MockLocalconfig.pm18
-rw-r--r--Bugzilla/Test/MockParams.pm71
-rw-r--r--Bugzilla/Test/Util.pm2
-rwxr-xr-xMakefile.PL1
-rw-r--r--conf/log4perl-t.conf4
-rw-r--r--extensions/BMO/t/bounty_attachment.t8
-rw-r--r--extensions/BMO/t/bug_format_comment.t90
-rw-r--r--extensions/PhabBugz/lib/Feed.pm4
-rw-r--r--extensions/PhabBugz/t/basic.t (renamed from t/phabbugz.t)0
-rw-r--r--extensions/PhabBugz/t/feed-daemon-guts.t160
-rw-r--r--extensions/Push/t/ReviewBoard.t3
-rw-r--r--extensions/RequestNagger/Extension.pm2
-rw-r--r--t/mock-db.t35
-rw-r--r--t/mock-params.t25
-rw-r--r--t/sqlite-memory.t89
20 files changed, 484 insertions, 121 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml
index a9a087609..d8c30f717 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -190,7 +190,7 @@ jobs:
name: run sanity tests
command: |
[[ -f build_info/only_version_changed.txt ]] && exit 0
- /app/scripts/entrypoint.pl prove -qf $(circleci tests glob 't/*.t' | circleci tests split) | tee artifacts/$CIRCLE_JOB.txt
+ /app/scripts/entrypoint.pl prove -qf $(circleci tests glob 't/*.t' 'extensions/*/t/*.t' | circleci tests split) | tee artifacts/$CIRCLE_JOB.txt
- store_artifacts:
path: /app/artifacts
- *store_log
diff --git a/Bugzilla.pm b/Bugzilla.pm
index b0387d179..5e48d21f4 100644
--- a/Bugzilla.pm
+++ b/Bugzilla.pm
@@ -85,6 +85,9 @@ sub init_page {
# request cache are very annoying (see bug 1347335)
# and this is not an expensive operation.
clear_request_cache();
+ if ($0 =~ /\.t/) {
+ return;
+ }
if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
init_console();
}
diff --git a/Bugzilla/Config.pm b/Bugzilla/Config.pm
index d050ff9e0..85779fa6b 100644
--- a/Bugzilla/Config.pm
+++ b/Bugzilla/Config.pm
@@ -251,28 +251,11 @@ sub write_params {
my ($param_data) = @_;
$param_data ||= Bugzilla->params;
- my $datadir = bz_locations()->{'datadir'};
- my $param_file = "$datadir/params";
-
local $Data::Dumper::Sortkeys = 1;
- my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
- DIR => $datadir );
-
my %params = %$param_data;
$params{urlbase} = Bugzilla->localconfig->{urlbase};
- print $fh (Data::Dumper->Dump([\%params], ['*param']))
- || die "Can't write param file: $!";
-
- close $fh;
-
- rename $tmpname, $param_file
- or die "Can't rename $tmpname to $param_file: $!";
-
- # It's not common to edit parameters and loading
- # Bugzilla::Install::Filesystem is slow.
- require Bugzilla::Install::Filesystem;
- Bugzilla::Install::Filesystem::fix_file_permissions($param_file);
+ __PACKAGE__->_write_file( Data::Dumper->Dump([\%params], ['*param']) );
# And now we have to reset the params cache so that Bugzilla will re-read
# them.
@@ -311,6 +294,24 @@ sub read_param_file {
return \%params;
}
+sub _write_file {
+ my ($class, $str) = @_;
+ my $datadir = bz_locations()->{'datadir'};
+ my $param_file = "$datadir/params";
+ my ($fh, $tmpname) = File::Temp::tempfile('params.XXXXX',
+ DIR => $datadir );
+ print $fh $str || die "Can't write param file: $!";
+ close $fh || die "Can't close param file: $!";
+
+ rename $tmpname, $param_file
+ or die "Can't rename $tmpname to $param_file: $!";
+
+ # It's not common to edit parameters and loading
+ # Bugzilla::Install::Filesystem is slow.
+ require Bugzilla::Install::Filesystem;
+ Bugzilla::Install::Filesystem::fix_file_permissions($param_file);
+}
+
1;
__END__
diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm
index 3890d0795..81ee7d888 100644
--- a/Bugzilla/DB/Sqlite.pm
+++ b/Bugzilla/DB/Sqlite.pm
@@ -73,7 +73,7 @@ sub BUILDARGS {
my $db_name = $params->{db_name};
# Let people specify paths intead of data/ for the DB.
- if ($db_name and $db_name !~ m{[\\/]}) {
+ if ($db_name && $db_name ne ':memory:' && $db_name !~ m{[\\/]}) {
# When the DB is first created, there's a chance that the
# data directory doesn't exist at all, because the Install::Filesystem
# code happens after DB creation. So we create the directory ourselves
diff --git a/Bugzilla/Test/MockDB.pm b/Bugzilla/Test/MockDB.pm
new file mode 100644
index 000000000..d158a73de
--- /dev/null
+++ b/Bugzilla/Test/MockDB.pm
@@ -0,0 +1,49 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockDB;
+use 5.10.1;
+use strict;
+use warnings;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+
+use Bugzilla::Test::MockLocalconfig (
+ db_driver => 'sqlite',
+ db_name => ':memory:',
+);
+use Bugzilla;
+BEGIN { Bugzilla->extensions };
+use Bugzilla::Test::MockParams;
+
+sub import {
+ require Bugzilla::Install;
+ require Bugzilla::Install::DB;
+ require Bugzilla::Field;;
+
+ state $first_time = 0;
+
+ return undef if $first_time++;
+
+ return capture_merged {
+ Bugzilla->dbh->bz_setup_database();
+
+ # Populate the tables that hold the values for the <select> fields.
+ Bugzilla->dbh->bz_populate_enum_tables();
+
+ Bugzilla::Install::DB::update_fielddefs_definition();
+ Bugzilla::Field::populate_field_definitions();
+ Bugzilla::Install::init_workflow();
+ Bugzilla::Install::DB->update_table_definitions({});
+ Bugzilla::Install::update_system_groups();
+
+ Bugzilla->set_user(Bugzilla::User->super_user);
+
+ Bugzilla::Install::update_settings();
+ };
+}
+
+1;
diff --git a/Bugzilla/Test/MockLocalconfig.pm b/Bugzilla/Test/MockLocalconfig.pm
new file mode 100644
index 000000000..a32aea0d4
--- /dev/null
+++ b/Bugzilla/Test/MockLocalconfig.pm
@@ -0,0 +1,18 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockLocalconfig;
+use 5.10.1;
+use strict;
+use warnings;
+
+sub import {
+ my ($class, %lc) = @_;
+ $ENV{LOCALCONFIG_ENV} = 'BMO';
+ $ENV{"BMO_$_"} = $lc{$_} for keys %lc;
+}
+
+1;
diff --git a/Bugzilla/Test/MockParams.pm b/Bugzilla/Test/MockParams.pm
new file mode 100644
index 000000000..2d064c616
--- /dev/null
+++ b/Bugzilla/Test/MockParams.pm
@@ -0,0 +1,71 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+package Bugzilla::Test::MockParams;
+use 5.10.1;
+use strict;
+use warnings;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+use Test2::Tools::Mock qw(mock);
+
+use Bugzilla::Config;
+use Safe;
+
+our $Params;
+BEGIN {
+ our $Mock = mock 'Bugzilla::Config' => (
+ override => [
+ 'read_param_file' => sub {
+ my ($class) = @_;
+ return {} unless $Params;
+ my $s = Safe->new;
+ $s->reval($Params);
+ die "Error evaluating params: $@" if $@;
+ return { %{ $s->varglob('param') } };
+ },
+ '_write_file' => sub {
+ my ($class, $str) = @_;
+ $Params = $str;
+ },
+ ],
+ );
+}
+
+sub import {
+ my ($self, %answers) = @_;
+ state $first_time = 0;
+
+ require Bugzilla::Field;
+ require Bugzilla::Status;
+ require Bugzilla;
+ my $Bugzilla = mock 'Bugzilla' => (
+ override => [
+ installation_answers => sub { \%answers },
+ ],
+ );
+ my $BugzillaField = mock 'Bugzilla::Field' => (
+ override => [
+ get_legal_field_values => sub { [] },
+ ],
+ );
+ my $BugzillaStatus = mock 'Bugzilla::Status' => (
+ override => [
+ closed_bug_statuses => sub { die "no database" },
+ ],
+ );
+
+ if ($first_time++) {
+ capture_merged {
+ Bugzilla::Config::update_params();
+ };
+ }
+ else {
+ Bugzilla::Config::SetParam($_, $answers{$_}) for keys %answers;
+ }
+}
+
+1; \ No newline at end of file
diff --git a/Bugzilla/Test/Util.pm b/Bugzilla/Test/Util.pm
index 4c9981e52..02c842658 100644
--- a/Bugzilla/Test/Util.pm
+++ b/Bugzilla/Test/Util.pm
@@ -24,7 +24,7 @@ sub create_user {
cryptpassword => $password,
disabledtext => "",
disable_mail => 0,
- extern_id => 0,
+ extern_id => undef,
%extra,
});
}
diff --git a/Makefile.PL b/Makefile.PL
index d9245c36f..4cf8755c6 100755
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -93,6 +93,7 @@ my %test_requires = (
'Test::Selenium::Firefox' => 0,
'Test::Perl::Critic::Progressive' => 0,
'Perl::Critic::Freenode' => 0,
+ 'Capture::Tiny' => 0,
);
my %recommends = ( Safe => '2.30' );
diff --git a/conf/log4perl-t.conf b/conf/log4perl-t.conf
new file mode 100644
index 000000000..33100d76c
--- /dev/null
+++ b/conf/log4perl-t.conf
@@ -0,0 +1,4 @@
+log4perl.rootLogger = DEBUG, Screen
+log4perl.appender.Screen = Log::Log4perl::Appender::Screen
+log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
+log4perl.appender.Screen.layout.ConversionPattern = # [%6p] {%c} %m{chomp}%n
diff --git a/extensions/BMO/t/bounty_attachment.t b/extensions/BMO/t/bounty_attachment.t
index bd79b0dfe..6e596eeba 100644
--- a/extensions/BMO/t/bounty_attachment.t
+++ b/extensions/BMO/t/bounty_attachment.t
@@ -7,15 +7,13 @@
# defined by the Mozilla Public License, v. 2.0.
use strict;
use warnings;
-use lib qw( . lib );
+use lib qw( . lib local/lib/perl5 );
use Test::More;
use Bugzilla;
-use Bugzilla::Extension;
-
-my $class = Bugzilla::Extension->load('extensions/BMO/Extension.pm',
- 'extensions/BMO/Config.pm');
+BEGIN { Bugzilla->extensions }
+my $class = 'Bugzilla::Extension::BMO';
my $parse = $class->can('parse_bounty_attachment_description');
my $format = $class->can('format_bounty_attachment_description');
diff --git a/extensions/BMO/t/bug_format_comment.t b/extensions/BMO/t/bug_format_comment.t
deleted file mode 100644
index 532b8fb8d..000000000
--- a/extensions/BMO/t/bug_format_comment.t
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/perl -T
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-#
-# This Source Code Form is "Incompatible With Secondary Licenses", as
-# defined by the Mozilla Public License, v. 2.0.
-use strict;
-use warnings;
-use lib qw( . lib );
-
-use Test::More;
-use Bugzilla;
-use Bugzilla::Extension;
-
-my $class = Bugzilla::Extension->load('extensions/BMO/Extension.pm',
- 'extensions/BMO/Config.pm');
-ok( $class->can('bug_format_comment'), 'the function exists');
-
-my $bmo = $class->new;
-ok($bmo, "got a new bmo extension");
-
-my $text = <<'END_OF_LINKS';
-# crash stats, a fake one
-bp-deadbeef-deaf-beef-beed-cafefeed1337
-
-# CVE/CAN security things
-CVE-2014-0160
-CVE-2014-0001
-CVE-2014-13579
-CVE-2014-999999999
-
-# svn
-r2424
-
-# bzr commit
-Committing to: bzr+ssh://dlawrence%40mozilla.com@bzr.mozilla.org/bmo/4.2
-modified extensions/Review/Extension.pm
-Committed revision 9257.
-
-# git with scp-style address
-To gitolite3@git.mozilla.org:bugzilla/bugzilla.git
- 36f56bd..eab44b1 nouri -> nouri
-
-# git with uri (with login)
-To ssh://gitolite3@git.mozilla.org/bugzilla/bugzilla.git
- 36f56bd..eab44b1 withuri -> withuri
-
-# git with uri (without login)
-To ssh://git.mozilla.org/bugzilla/bugzilla.git
- 36f56bd..eab44b1 nologin -> nologin
-END_OF_LINKS
-
-my @regexes;
-
-$bmo->bug_format_comment({ regexes => \@regexes });
-
-ok(@regexes > 0, "got some regexes to play with");
-
-foreach my $re (@regexes) {
- my ($match, $replace) = @$re{qw(match replace)};
- if (ref($replace) eq 'CODE') {
- $text =~ s/$match/$replace->({matches => [ $1, $2, $3, $4,
- $5, $6, $7, $8,
- $9, $10]})/egx;
- }
- else {
- $text =~ s/$match/$replace/egx;
- }
-}
-
-my @links = (
- '<a href="https://crash-stats.mozilla.com/report/index/deadbeef-deaf-beef-beed-cafefeed1337">bp-deadbeef-deaf-beef-beed-cafefeed1337</a>',
- '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0160">CVE-2014-0160</a>',
- '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-0001">CVE-2014-0001</a>',
- '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-13579">CVE-2014-13579</a>',
- '<a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-999999999">CVE-2014-999999999</a>',
- '<a href="https://viewvc.svn.mozilla.org/vc?view=rev&amp;revision=2424">r2424</a>',
- '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1 withuri -> withuri</a>',
- '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1 nouri -> nouri</a>',
- '<a href="https://git.mozilla.org/?p=bugzilla/bugzilla.git;a=commitdiff;h=eab44b1">36f56bd..eab44b1 nologin -> nologin</a>',
- 'https://bzr.mozilla.org/bmo/4.2/revision/9257',
-);
-
-foreach my $link (@links) {
- ok(index($text, $link) > -1, "check for $link");
-}
-
-
-done_testing;
diff --git a/extensions/PhabBugz/lib/Feed.pm b/extensions/PhabBugz/lib/Feed.pm
index 8e7290988..1cc73d134 100644
--- a/extensions/PhabBugz/lib/Feed.pm
+++ b/extensions/PhabBugz/lib/Feed.pm
@@ -380,7 +380,7 @@ sub process_revision_change {
# Pre setup before making changes
my $old_user = set_phab_user();
- my $bug = Bugzilla::Bug->new({ id => $revision->bug_id, cache => 1 });
+ my $bug = $revision->bug;
# Check to make sure bug id is valid and author can see it
if ($bug->{error}
@@ -714,7 +714,7 @@ sub process_new_user {
# that are connected to revisions
f11 => 'attachments.filename',
o11 => 'regexp',
- v11 => '^phabricator-D[[:digit:]]+-url[[.period.]]txt$',
+ v11 => '^phabricator-D[[:digit:]]+-url.txt$',
};
my $search = Bugzilla::Search->new( fields => [ 'bug_id' ],
diff --git a/t/phabbugz.t b/extensions/PhabBugz/t/basic.t
index ba2f35e1d..ba2f35e1d 100644
--- a/t/phabbugz.t
+++ b/extensions/PhabBugz/t/basic.t
diff --git a/extensions/PhabBugz/t/feed-daemon-guts.t b/extensions/PhabBugz/t/feed-daemon-guts.t
new file mode 100644
index 000000000..376af18e4
--- /dev/null
+++ b/extensions/PhabBugz/t/feed-daemon-guts.t
@@ -0,0 +1,160 @@
+#!/usr/bin/perl
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+use strict;
+use warnings;
+use 5.10.1;
+use lib qw( . lib local/lib/perl5 );
+BEGIN { $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf' }
+use Bugzilla::Test::MockDB;
+use Bugzilla::Test::MockParams;
+use Bugzilla::Test::Util qw(create_user);
+use Test::More;
+use Test2::Tools::Mock;
+use Try::Tiny;
+use JSON::MaybeXS;
+use Bugzilla::Constants;
+use URI;
+use File::Basename;
+use Digest::SHA qw(sha1_hex);
+
+use ok 'Bugzilla::Extension::PhabBugz::Feed';
+use ok 'Bugzilla::Extension::PhabBugz::Constants', 'PHAB_AUTOMATION_USER';
+use ok 'Bugzilla::Config', 'SetParam';
+can_ok('Bugzilla::Extension::PhabBugz::Feed', qw( group_query feed_query user_query ));
+
+Bugzilla->error_mode(ERROR_MODE_TEST);
+
+my $phab_bot = create_user(PHAB_AUTOMATION_USER, '*');
+
+my $UserAgent = mock 'LWP::UserAgent' => ();
+
+{
+ SetParam('phabricator_enabled', 0);
+ my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+ my $Feed = mock 'Bugzilla::Extension::PhabBugz::Feed' => (
+ override => [
+ get_last_id => sub { die "get_last_id" },
+ ],
+ );
+
+ foreach my $method (qw( feed_query user_query group_query )) {
+ try {
+ $feed->$method;
+ pass "disabling the phabricator sync: $method";
+ }
+ catch {
+ fail "disabling the phabricator sync: $method";
+ }
+ }
+}
+
+my @bad_response = (
+ ['http error', mock({ is_error => 1, message => 'some http error' }) ],
+ ['invalid json', mock({ is_error => 0, content => '<xml>foo</xml>' })],
+ ['json containing error code', mock({ is_error => 0, content => encode_json({error_code => 1234 }) })],
+);
+
+SetParam(phabricator_enabled => 1);
+SetParam(phabricator_api_key => 'FAKE-API-KEY');
+SetParam(phabricator_base_uri => 'http://fake.fabricator.tld/');
+
+foreach my $bad_response (@bad_response) {
+ my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+ $UserAgent->override(
+ post => sub {
+ my ( $self, $url, $params ) = @_;
+ return $bad_response->[1];
+ }
+ );
+
+ foreach my $method (qw( feed_query user_query group_query )) {
+ try {
+ # This is a hack to get reasonable exception objects.
+ local $Bugzilla::Template::is_processing = 1;
+ $feed->$method;
+ fail "$method - $bad_response->[0]";
+ }
+ catch {
+ is( $_->type, 'bugzilla.code.phabricator_api_error', "$method - $bad_response->[0]" );
+ };
+ }
+ $UserAgent->reset('post');
+}
+
+my $feed = Bugzilla::Extension::PhabBugz::Feed->new;
+my $json = JSON::MaybeXS->new( canonical => 1, pretty => 1 );
+my $dylan = create_user( 'dylan@mozilla.com', '*', realname => 'Dylan Hardison :dylan' );
+my $evildylan = create_user( 'dylan@gmail.com', '*', realname => 'Evil Dylan :dylan' );
+my $myk = create_user( 'myk@mozilla.com', '*', realname => 'Myk Melez :myk' );
+
+my $phab_bot_phid = next_phid('PHID-USER');
+
+done_testing;
+
+sub user_search {
+ my (%conf) = @_;
+
+ return {
+ error_info => undef,
+ error_code => undef,
+ result => {
+ cursor => {
+ after => $conf{after},
+ order => undef,
+ limit => 100,
+ before => undef
+ },
+ query => {
+ queryKey => undef
+ },
+ maps => {},
+ data => [
+ map {
+ +{
+ attachments => {
+ $_->{bmo_id}
+ ? ( "external-accounts" => {
+ "external-accounts" => [
+ {
+ type => 'bmo',
+ id => $_->{bmo_id},
+ }
+ ]
+ }
+ )
+ : (),
+ },
+ fields => {
+ roles => [ "verified", "approved", "activated" ],
+ realName => $_->{realname},
+ dateModified => time,
+ policy => {
+ view => "public",
+ edit => "no-one"
+ },
+ dateCreated => time,
+ username => $_->{username},
+ },
+ phid => next_phid("PHID-USER"),
+ type => "USER",
+ id => $_->{phab_id},
+ },
+ } @{ $conf{users} },
+ ]
+ }
+ };
+
+}
+
+sub next_phid {
+ my ($prefix) = @_;
+ state $number = 'a' x 20;
+ return $prefix . '-' . ($number++);
+}
+
+
diff --git a/extensions/Push/t/ReviewBoard.t b/extensions/Push/t/ReviewBoard.t
index 3eb54760c..c752e34ef 100644
--- a/extensions/Push/t/ReviewBoard.t
+++ b/extensions/Push/t/ReviewBoard.t
@@ -7,14 +7,13 @@
# defined by the Mozilla Public License, v. 2.0.
use strict;
use warnings;
-use lib qw( . lib );
+use lib qw( . lib local/lib/perl5 );
use Test::More;
use Bugzilla;
use Bugzilla::Extension;
use Bugzilla::Attachment;
use Scalar::Util 'blessed';
-use YAML;
BEGIN {
eval {
diff --git a/extensions/RequestNagger/Extension.pm b/extensions/RequestNagger/Extension.pm
index 65f5e6b84..e0f97c9f7 100644
--- a/extensions/RequestNagger/Extension.pm
+++ b/extensions/RequestNagger/Extension.pm
@@ -355,7 +355,7 @@ sub db_schema_abstract_schema {
},
],
INDEXES => [
- nag_watch_idx => {
+ nag_setting_idx => {
FIELDS => [ 'user_id', 'setting_name' ],
TYPE => 'UNIQUE',
},
diff --git a/t/mock-db.t b/t/mock-db.t
new file mode 100644
index 000000000..6cf84f316
--- /dev/null
+++ b/t/mock-db.t
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Try::Tiny;
+
+use ok 'Bugzilla::Test::MockDB';
+use ok 'Bugzilla::Test::Util', qw(create_user);
+
+try {
+ Bugzilla::Test::MockDB->import();
+ pass('made fake in-memory db');
+}
+catch {
+ diag $_;
+ fail('made fake in-memory db');
+};
+
+try {
+ create_user('bob@pants.gov', '*');
+ ok( Bugzilla::User->new({name => 'bob@pants.gov'})->id, 'create a user' );
+}
+catch {
+ fail('create a user');
+};
+
+done_testing;
diff --git a/t/mock-params.t b/t/mock-params.t
new file mode 100644
index 000000000..7c2318130
--- /dev/null
+++ b/t/mock-params.t
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Test2::Tools::Mock qw(mock);
+use Bugzilla::Test::MockParams (
+ phabricator_auth_callback_url => 'http://pants.gov/',
+);
+
+is(Bugzilla->params->{phabricator_auth_callback_url}, 'http://pants.gov/', 'import default params');
+
+Bugzilla::Test::MockParams->import(phabricator_api_key => 'FAKE-KEY');
+
+is(Bugzilla->params->{phabricator_api_key}, 'FAKE-KEY', 'set key');
+
+
+done_testing;
diff --git a/t/sqlite-memory.t b/t/sqlite-memory.t
new file mode 100644
index 000000000..66f8e5d29
--- /dev/null
+++ b/t/sqlite-memory.t
@@ -0,0 +1,89 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+# This Source Code Form is "Incompatible With Secondary Licenses", as
+# defined by the Mozilla Public License, v. 2.0.
+use 5.10.1;
+use strict;
+use warnings;
+use lib qw( . lib local/lib/perl5 );
+use Test::More;
+use Test2::Tools::Mock;
+use Try::Tiny;
+use Capture::Tiny qw(capture_merged);
+use Bugzilla::Test::MockParams;
+
+BEGIN {
+ $ENV{LOCALCONFIG_ENV} = 'BMO';
+ $ENV{BMO_db_driver} = 'sqlite';
+ $ENV{BMO_db_name} = ':memory:';
+};
+use Bugzilla;
+BEGIN { Bugzilla->extensions };
+
+
+isa_ok(Bugzilla->dbh, 'Bugzilla::DB::Sqlite');
+
+use ok 'Bugzilla::Install';
+use ok 'Bugzilla::Install::DB';
+
+my $lives_ok = sub {
+ my ($desc, $code) = @_;
+ my $output;
+ try {
+ $output = capture_merged { $code->() };
+ pass($desc);
+ } catch {
+ diag $_;
+ fail($desc);
+ } finally {
+ diag "OUTPUT: $output" if $output;
+ };
+};
+
+my $output = '';
+$lives_ok->('bz_setup_database' => sub {
+ Bugzilla->dbh->bz_setup_database
+});
+
+$lives_ok->('bz_populate_enum_tables' => sub {
+ # Populate the tables that hold the values for the <select> fields.
+ Bugzilla->dbh->bz_populate_enum_tables();
+});
+
+$lives_ok->('update_fielddefs_definition' => sub {
+ Bugzilla::Install::DB::update_fielddefs_definition();
+});
+
+$lives_ok->('populate_field_definitions' => sub {
+ Bugzilla::Field::populate_field_definitions();
+});
+
+$lives_ok->('init_workflow' => sub {
+ Bugzilla::Install::init_workflow();
+});
+
+$lives_ok->('update_table_definitions' => sub {
+ Bugzilla::Install::DB->update_table_definitions({});
+});
+
+$lives_ok->('update_system_groups' => sub {
+ Bugzilla::Install::update_system_groups();
+});
+
+# "Log In" as the fake superuser who can do everything.
+Bugzilla->set_user(Bugzilla::User->super_user);
+
+$lives_ok->('update_settings' => sub {
+ Bugzilla::Install::update_settings();
+});
+
+SKIP: {
+ skip 'default product cannot be created without default assignee', 1;
+ $lives_ok->('create_default_product' => sub {
+ Bugzilla::Install::create_default_product();
+ });
+}
+
+done_testing;