Skip to content

Commit 56f0f42

Browse files
committed
WIP
1 parent 3eea576 commit 56f0f42

File tree

11 files changed

+55
-136
lines changed

11 files changed

+55
-136
lines changed

etc/metacpan_testing.pl

Lines changed: 0 additions & 12 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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package MetaCPAN::Role::Logger;
22

33
use v5.10;
44
use Moose::Role;
5-
use Log::Contextual qw( set_logger );
5+
6+
use Log::Contextual qw( set_logger );
67
use Log::Log4perl ':easy';
78
use MetaCPAN::Types::TypeTiny qw( Logger Str );
8-
use Path::Tiny qw( path );
9+
use Path::Tiny qw( path );
910

1011
has level => (
1112
is => 'ro',
@@ -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
@@ -5,6 +5,7 @@ use Moose::Role;
55
use Carp ();
66
use ElasticSearchX::Model::Document::Types qw( ES );
77
use File::Path ();
8+
use IO::Interactive qw( is_interactive );
89
use IO::Prompt ();
910
use Log::Contextual qw( :log :dlog );
1011
use MetaCPAN::Model ();
@@ -389,7 +390,7 @@ sub are_you_sure {
389390
my ( $self, $msg ) = @_;
390391
my $iconfirmed = 0;
391392

392-
if ( -t *STDOUT ) {
393+
if ( is_interactive() ) {
393394
my $answer
394395
= prompt colored( ['bold red'], "*** Warning ***: $msg" ) . "\n"
395396
. '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: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ 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 );
6+
use File::Path ();
7+
use IO::Interactive qw(is_interactive);
8+
use MetaCPAN::Config ();
9+
use Module::Pluggable qw( plugins );
910
use Module::Pluggable search_path => ['MetaCPAN::Script'];
1011
use Module::Runtime ();
1112
use Term::ANSIColor qw( colored );
@@ -21,7 +22,8 @@ sub run {
2122
die "Usage: metacpan [command] [args]" unless ($class);
2223
Module::Runtime::require_module( $plugins{$class} );
2324

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

2628
foreach my $logger ( @{ $config->{logger} || [] } ) {
2729
my $path = $logger->{filename} or next;
@@ -75,21 +77,6 @@ sub run {
7577
return ( $EXIT_CODE == 0 );
7678
}
7779

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-
9380
# AnyEvent::Run calls the main method
9481
*main = \&run;
9582

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: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
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 qw( decode_json encode_json );
8-
use File::Copy qw( copy );
9-
use File::pushd qw( pushd );
10-
use FindBin ();
11-
use MetaCPAN::Script::Runner ();
12-
use MetaCPAN::Util qw( checkout_root );
13-
use Path::Tiny qw( path );
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 );
1415
use Test::More;
16+
use Test::More import => [qw( diag is ok )];
1517
use Test::Routine::Util qw( run_tests );
1618
use Try::Tiny qw( catch finally try );
1719

@@ -98,13 +100,7 @@ sub test_release {
98100
}
99101

100102
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;
103+
return MetaCPAN::Config::config();
108104
}
109105

110106
sub tmp_dir {

t/lib/MetaCPAN/TestServer.pm

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

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

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

6652
$self->es_client;
67-
68-
# Deploy project mappings
6953
$self->put_mappings;
7054
}
7155

@@ -80,69 +64,11 @@ sub _build_config {
8064
return $config;
8165
}
8266

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

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

@@ -213,7 +139,7 @@ sub check_mappings {
213139
sub put_mappings {
214140
my $self = shift;
215141

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

t/script/cover.t

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

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

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

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

0 commit comments

Comments
 (0)