Bug 16453: Make Elasticsearch tests be skipped if configuration entry missing
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 5 May 2016 16:19:28 +0000 (13:19 -0300)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Fri, 6 May 2016 03:47:05 +0000 (03:47 +0000)
The current tests fail to run if the configuration entry is missing. This is
problematic on jenkins and should be fixed.

To test:
- On master, having koha-conf.xml without (or commented) an <elasticsearch> entry
- Run:
  $ prove t/db_dependent/Koha_ElasticSearch_Indexer.t \
          t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t -v
=> FAIL: Tests fail due to missing configuration entry
- Apply the patch
- Run:
  $ prove t/db_dependent/Koha_ElasticSearch_Indexer.t \
          t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t -v
=> SUCCESS: Tests pass, and the ES-configuration-dependent tests are skipped
- Have elasticsearch running and the koha-conf.xml entry
- Run:
  $ prove t/db_dependent/Koha_ElasticSearch_Indexer.t \
          t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t -v
=> SUCCESS: Same results as without the patch
- Sign off

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
t/db_dependent/Koha_ElasticSearch_Indexer.t
t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t

index 80539e3..626079d 100644 (file)
@@ -1,6 +1,5 @@
 # Copyright 2015 Catalyst IT
 #
-#
 # This file is part of Koha.
 #
 # Koha is free software; you can redistribute it and/or modify it
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
+
+use Test::More tests => 5;
 
-use Test::More tests => 5;    # last test to print
 use MARC::Record;
 
 use_ok('Koha::ElasticSearch::Indexer');
 
 my $indexer;
 ok(
-    $indexer = Koha::ElasticSearch::Indexer->new(
-        {
-            'nodes' => ['localhost:9200'],
-            'index' => 'mydb'
-        }
-    ),
+    $indexer = Koha::ElasticSearch::Indexer->new({ 'index' => 'biblio' }),
     'Creating new indexer object'
 );
 
 my $marc_record = MARC::Record->new();
-my $field = MARC::Field->new( '001', '1234567' );
-$marc_record->append_fields($field);
-$field = MARC::Field->new( '020', '', '', 'a' => '1234567890123' );
-$marc_record->append_fields($field);
-$field = MARC::Field->new( '245', '', '', 'a' => 'Title' );
-$marc_record->append_fields($field);
+$marc_record->append_fields(
+    MARC::Field->new( '001', '1234567' ),
+    MARC::Field->new( '020', '', '', 'a' => '1234567890123' ),
+    MARC::Field->new( '245', '', '', 'a' => 'Title' )
+);
 
 my $records = [$marc_record];
 ok( my $converted = $indexer->_convert_marc_to_json($records),
@@ -49,4 +42,14 @@ ok( my $converted = $indexer->_convert_marc_to_json($records),
 
 is( $converted->count, 1, 'One converted record' );
 
-ok( $indexer->update_index(undef,$records), 'Update Index' );
+SKIP: {
+
+    eval { $indexer->get_elasticsearch_params; };
+
+    skip 'ElasticSeatch configuration not available', 1
+        if $@;
+
+    ok( $indexer->update_index(undef,$records), 'Update Index' );
+}
+
+1;
index 9361b4c..ac20414 100644 (file)
 #
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
-use strict;
-use warnings;
 
-use Test::More tests => 10;    # last test to print
+use Modern::Perl;
+
+use Test::More tests => 10;
+
 use Koha::SearchEngine::Elasticsearch::QueryBuilder;
 
 my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } );
@@ -35,14 +36,25 @@ is( $searcher->index, 'mydb', 'Testing basic accessor' );
 
 ok( my $query = $builder->build_query('easy'), 'Build a search query');
 
-ok( my $results = $searcher->search( $query) , 'Do a search ' );
+SKIP: {
+
+    eval { $builder->get_elasticsearch_params; };
+
+    skip 'ElasticSeatch configuration not available', 6
+        if $@;
+
+    ok( my $results = $searcher->search( $query) , 'Do a search ' );
+
+    ok( my $marc = $searcher->json2marc( $results->first ), 'Convert JSON to MARC');
+
+    is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results ');
 
-ok( my $marc = $searcher->json2marc( $results->first ), 'Convert JSON to MARC');
+    ok ($results = $searcher->search_compat( $query ), 'Test search_compat' );
 
-is (my $count = $searcher->count( $query ), 0 , 'Get a count of the results, without returning results ');
+    ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' );
 
-ok ($results = $searcher->search_compat( $query ), 'Test search_compat' );
+    is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use');
 
-ok (($results,$count) = $searcher->search_auth_compat ( $query ), 'Test search_auth_compat' );
+}
 
-is ( $count = $searcher->count_auth_use($searcher,1), 0, 'Testing count_auth_use');
+1;