Skip to content

Commit d84f414

Browse files
committed
WIP
1 parent a056507 commit d84f414

File tree

11 files changed

+58
-151
lines changed

11 files changed

+58
-151
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ has aliases_info => (
117117
has port => (
118118
isa => Int,
119119
is => 'ro',
120-
required => 1,
120+
lazy => 1,
121+
required => 0,
122+
default => 5000,
121123
documentation => 'Port for the proxy, defaults to 5000',
122124
);
123125

lib/MetaCPAN/Script/Mapping.pm

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

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

lib/MetaCPAN/Script/Runner.pm

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +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 IO::Interactive qw(is_interactive);
10-
use Module::Pluggable search_path => ['MetaCPAN::Script'];
11-
use Module::Runtime ();
12-
use Try::Tiny qw( catch try );
13-
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 );
1413

1514
our $EXIT_CODE = 0;
1615

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

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

2727
foreach my $logger ( @{ $config->{logger} || [] } ) {
2828
my $path = $logger->{filename} or next;
@@ -76,28 +76,6 @@ sub run {
7676
return ( $EXIT_CODE == 0 );
7777
}
7878

79-
sub build_config {
80-
my $config = Config::ZOMG->new(
81-
name => 'metacpan',
82-
path => 'etc'
83-
)->load;
84-
if ( $ENV{HARNESS_ACTIVE} ) {
85-
my $tconf = Config::ZOMG->new(
86-
name => 'metacpan',
87-
file => 'etc/metacpan_testing.pl'
88-
)->load;
89-
$config = merge $config, $tconf;
90-
}
91-
elsif ( is_interactive() ) {
92-
my $iconf = Config::ZOMG->new(
93-
name => 'metacpan',
94-
file => 'etc/metacpan_interactive.pl'
95-
)->load;
96-
$config = merge $config, $iconf;
97-
}
98-
return $config;
99-
}
100-
10179
# AnyEvent::Run calls the main method
10280
*main = \&run;
10381

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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1+
package MetaCPAN::TestHelpers;
2+
13
use strict;
24
use warnings;
35

4-
package # no_index
5-
MetaCPAN::TestHelpers;
6-
7-
use Cpanel::JSON::XS;
8-
use File::Copy qw( copy );
9-
use File::pushd qw( pushd );
10-
use FindBin;
11-
use Git::Helpers 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 );
6+
use Cpanel::JSON::XS qw( decode_json encode_json );
7+
use File::Copy qw( copy );
8+
use File::pushd qw( pushd );
9+
use Git::Helpers qw( checkout_root );
10+
use MetaCPAN::Config ();
11+
use Path::Tiny qw( path );
12+
use Test::More import => [qw( diag is ok )];
13+
use Test::Routine::Util qw( run_tests );
14+
use Try::Tiny qw( catch finally try );
1715

1816
use base 'Exporter';
1917
our @EXPORT = qw(
@@ -98,13 +96,7 @@ sub test_release {
9896
}
9997

10098
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;
99+
return MetaCPAN::Config::config();
108100
}
109101

110102
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: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use strict;
22
use warnings;
3+
34
use lib 't/lib';
45

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

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

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

0 commit comments

Comments
 (0)