Skip to content

Commit ed24698

Browse files
committed
WIP
1 parent b434bf0 commit ed24698

File tree

11 files changed

+59
-141
lines changed

11 files changed

+59
-141
lines changed

etc/metacpan_testing.pl

Lines changed: 0 additions & 10 deletions
This file was deleted.

lib/MetaCPAN/Config.pm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ sub config {
1414
require_module('Git::Helpers');
1515
$config = _zomg( Git::Helpers::checkout_root() );
1616

17-
return $config if $config;
17+
if ( !$config ) {
18+
die "Couldn't find config file in $FindBin::RealBin/.. or "
19+
. Git::Helpers::checkout_root();
20+
}
21+
22+
if ( defined $config->{logger} && ref $config->{logger} ne 'ARRAY' ) {
23+
$config->{logger} = [ $config->{logger} ];
24+
}
1825

19-
die "Couldn't find config file in $FindBin::RealBin/.. or "
20-
. Git::Helpers::checkout_root();
26+
return $config;
2127
}
2228

2329
sub _zomg {

lib/MetaCPAN/Role/Logger.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package MetaCPAN::Role::Logger;
22

33
use v5.10;
44
use Moose::Role;
5+
56
use MetaCPAN::Types::TypeTiny qw( Logger Str );
67
use Log::Contextual qw( set_logger );
78
use Log::Log4perl ':easy';
@@ -45,8 +46,6 @@ sub set_logger_once {
4546
return;
4647
}
4748

48-
# XXX NOT A MOOSE BUILDER
49-
# XXX This doesn't belong here.
5049
sub _build_logger {
5150
my ($config) = @_;
5251
my $log = Log::Log4perl->get_logger( $ARGV[0]

lib/MetaCPAN/Role/Script.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use ElasticSearchX::Model::Document::Types qw( ES );
77
use File::Path ();
88
use Git::Helpers qw( checkout_root );
99
use IO::Prompt qw( prompt );
10+
use IO::Interactive qw( is_interactive );
1011
use Log::Contextual qw( :log :dlog );
1112
use MetaCPAN::Model ();
1213
use MetaCPAN::Types::TypeTiny qw( Bool HashRef Int Path Str );
@@ -387,7 +388,7 @@ sub are_you_sure {
387388
my ( $self, $msg ) = @_;
388389
my $iconfirmed = 0;
389390

390-
if ( -t *STDOUT ) {
391+
if ( is_interactive() ) {
391392
my $answer
392393
= prompt colored( ['bold red'], "*** Warning ***: $msg" ) . "\n"
393394
. 'Are you sure you want to do this (type "YES" to confirm) ? ';

lib/MetaCPAN/Script/Mapping.pm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ sub delete_all {
254254
|| $runtime_environment eq 'testing';
255255

256256
if ($is_development) {
257-
$self->are_you_sure("ALL Indices will be deleted !!!");
258-
259257
foreach my $name ( keys %{ $self->indices_info } ) {
260258
$self->_delete_index($name);
261259
}

lib/MetaCPAN/Script/Runner.pm

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package MetaCPAN::Script::Runner;
33
use strict;
44
use warnings;
55

6-
use Config::ZOMG ();
7-
use File::Path ();
8-
use Hash::Merge::Simple qw(merge);
9-
use Module::Pluggable search_path => ['MetaCPAN::Script'];
10-
use Module::Runtime ();
11-
use Try::Tiny qw( catch try );
12-
use Term::ANSIColor qw( colored );
6+
use File::Path ();
7+
use IO::Interactive qw(is_interactive);
8+
use MetaCPAN::Config ();
9+
use Module::Pluggable qw( plugins );
10+
use Module::Runtime ();
11+
use Term::ANSIColor qw( colored );
12+
use Try::Tiny qw( catch try );
1313

1414
our $EXIT_CODE = 0;
1515

@@ -21,7 +21,8 @@ sub run {
2121
die "Usage: metacpan [command] [args]" unless ($class);
2222
Module::Runtime::require_module( $plugins{$class} );
2323

24-
my $config = build_config();
24+
my $config = MetaCPAN::Config::config();
25+
$config->{es} = $config->{elasticsearch_servers};
2526

2627
foreach my $logger ( @{ $config->{logger} || [] } ) {
2728
my $path = $logger->{filename} or next;
@@ -75,21 +76,6 @@ sub run {
7576
return ( $EXIT_CODE == 0 );
7677
}
7778

78-
sub build_config {
79-
my $config = Config::ZOMG->new(
80-
name => 'metacpan',
81-
path => 'etc'
82-
)->load;
83-
if ( $ENV{HARNESS_ACTIVE} ) {
84-
my $tconf = Config::ZOMG->new(
85-
name => 'metacpan',
86-
file => 'etc/metacpan_testing.pl'
87-
)->load;
88-
$config = merge $config, $tconf;
89-
}
90-
return $config;
91-
}
92-
9379
# AnyEvent::Run calls the main method
9480
*main = \&run;
9581

metacpan_server.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
git /usr/bin/git
22

3+
level info
34
elasticsearch_servers = :9200
45
minion_dsn = postgresql:///minion_queue
56

7+
<logger>
8+
class Log::Log4perl::Appender::File
9+
filename ../var/log/metacpan.log
10+
syswrite 1
11+
</logger>
12+
613
<controller User::Turing>
714
# required for server startup -- override this in metacpan_server_local.conf
815
private_key 59125ffc09413eed3f2a2c07a37c7a44b95633e2

metacpan_server_testing.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
cpan var/t/tmp/fakecpan
2+
die_on_error 1
3+
level warn
24
source_base var/t/tmp/source
35

4-
elasticsearch_servers = http://elasticsearch_test:9200
6+
elasticsearch_servers = elasticsearch_test:9200
7+
8+
<logger>
9+
class Log::Log4perl::Appender::Screen
10+
name testing
11+
</logger>
512

613
<model CPAN>
714
servers __ENV(ES)__

t/lib/MetaCPAN/TestHelpers.pm

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
package MetaCPAN::TestHelpers;
2+
13
use strict;
24
use warnings;
35

46
package # no_index
57
MetaCPAN::TestHelpers;
68

7-
use Cpanel::JSON::XS;
8-
use File::Copy qw( copy );
9-
use File::pushd qw( pushd );
10-
use FindBin;
11-
use MetaCPAN::Util qw( checkout_root );
12-
use MetaCPAN::Script::Runner;
13-
use Path::Tiny qw( path );
14-
use Test::More;
15-
use Test::Routine::Util;
16-
use Try::Tiny qw( catch try );
9+
use Cpanel::JSON::XS qw( decode_json encode_json );
10+
use File::Copy qw( copy );
11+
use File::pushd qw( pushd );
12+
use MetaCPAN::Config ();
13+
use MetaCPAN::Util qw( checkout_root );
14+
use Path::Tiny qw( path );
15+
use Test::More import => [qw( diag is ok )];
16+
use Test::Routine::Util qw( run_tests );
17+
use Try::Tiny qw( catch finally try );
1718

1819
use base 'Exporter';
1920
our @EXPORT = qw(
@@ -98,13 +99,7 @@ sub test_release {
9899
}
99100

100101
sub get_config {
101-
my $config = do {
102-
103-
# build_config expects test to be t/*.t
104-
local $FindBin::RealBin = path( checkout_root(), 't' );
105-
MetaCPAN::Script::Runner->build_config;
106-
};
107-
return $config;
102+
return MetaCPAN::Config::config();
108103
}
109104

110105
sub tmp_dir {

t/lib/MetaCPAN/TestServer.pm

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,13 @@ has es_client => (
3030
builder => '_build_es_client',
3131
);
3232

33-
has es_server => (
34-
is => 'ro',
35-
isa => 'Search::Elasticsearch::TestServer',
36-
lazy => 1,
37-
builder => '_build_es_server',
38-
);
39-
4033
has _config => (
4134
is => 'ro',
4235
isa => HashRef,
4336
lazy => 1,
4437
builder => '_build_config',
4538
);
4639

47-
has _es_home => (
48-
is => 'ro',
49-
isa => Str,
50-
lazy => 1,
51-
builder => '_build_es_home',
52-
);
53-
5440
has _cpan_dir => (
5541
is => 'ro',
5642
isa => Path,
@@ -63,8 +49,6 @@ sub setup {
6349
my $self = shift;
6450

6551
$self->es_client;
66-
67-
# Deploy project mappings
6852
$self->put_mappings;
6953
}
7054

@@ -79,69 +63,11 @@ sub _build_config {
7963
return $config;
8064
}
8165

82-
sub _build_es_home {
83-
my $self = shift;
84-
85-
my $es_home = MetaCPAN::Config::config()->{elasticsearch_servers};
86-
87-
if ( !$es_home ) {
88-
die <<'USAGE';
89-
Please set elasticsearch_servers to a running instance of Elasticsearch, eg
90-
'localhost:9200'
91-
USAGE
92-
}
93-
94-
return $es_home;
95-
}
96-
97-
=head2 _build_es_server
98-
99-
This starts an Elastisearch server on the fly. It should only be called if the
100-
ES env var contains a path to Elasticsearch. If the variable contains a port
101-
number then we'll assume the server has already been started on this port.
102-
103-
=cut
104-
105-
sub _build_es_server {
106-
my $self = shift;
107-
108-
my $server = Search::Elasticsearch::TestServer->new(
109-
conf => [ 'cluster.name' => 'metacpan-test' ],
110-
es_home => $self->_es_home,
111-
es_port => 9700,
112-
http_port => 9900,
113-
instances => 1,
114-
);
115-
116-
diag 'Connecting to Elasticsearch on ' . $self->_es_home;
117-
118-
try {
119-
$server->start->[0];
120-
}
121-
catch {
122-
diag(<<"EOF");
123-
Failed to connect to the Elasticsearch test instance on ${\$self->_es_home}.
124-
Did you start one up? See https://github.com/metacpan/metacpan-api/wiki/Installation
125-
for more information.
126-
Error: $_
127-
EOF
128-
BAIL_OUT('Test environment not set up properly');
129-
};
130-
131-
diag( 'Connected to the Elasticsearch test instance on '
132-
. $self->_es_home );
133-
}
134-
13566
sub _build_es_client {
13667
my $self = shift;
13768

138-
# Don't try to start a test server if we've been passed the port number of
139-
# a running instance.
140-
141-
$self->es_server unless $self->_es_home =~ m{:};
142-
14369
my $es = Search::Elasticsearch->new(
144-
nodes => $self->_es_home,
70+
nodes => MetaCPAN::Config::config()->{elasticsearch_servers},
14571
( $ENV{ES_TRACE} ? ( trace_to => [ 'File', 'es.log' ] ) : () )
14672
);
14773

@@ -212,7 +138,7 @@ sub check_mappings {
212138
sub put_mappings {
213139
my $self = shift;
214140

215-
local @ARGV = qw(mapping --delete);
141+
local @ARGV = qw(mapping --delete --all);
216142
ok( MetaCPAN::Script::Mapping->new_with_options( $self->_config )->run,
217143
'put mapping' );
218144
$self->check_mappings;

t/script/cover.t

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
use strict;
22
use warnings;
3+
34
use lib 't/lib';
45

5-
use MetaCPAN::Util qw( checkout_root );
6-
use MetaCPAN::Script::Cover ();
7-
use MetaCPAN::Script::Runner ();
8-
use Test::More;
9-
use URI ();
6+
use MetaCPAN::Config ();
7+
use MetaCPAN::Script::Cover ();
8+
use MetaCPAN::Util qw( checkout_root );
9+
use Test::More import => [qw( done_testing ok )];
10+
use URI ();
1011

11-
my $config = MetaCPAN::Script::Runner::build_config;
12+
my $config = MetaCPAN::Config::config();
13+
$config->{es} = $config->{elasticsearch_servers};
14+
$config->{port} = 5000;
1215

1316
my $root = checkout_root();
1417
my $file = URI->new('t/var/cover.json')->abs("file://$root/");

0 commit comments

Comments
 (0)