From 1e1ca322d35d26e7158faeb34be3aaeada25d13a Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Fri, 7 Sep 2018 15:18:00 +0200 Subject: [PATCH] Bug 19893: Restore and fix removed tests Sponsored-by: Gothenburg University Library Signed-off-by: Ere Maijala Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/SearchEngine/Elasticsearch/Indexer.pm | 1 + t/db_dependent/Koha_Elasticsearch_Indexer.t | 55 +++++++++++++-------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Indexer.pm b/Koha/SearchEngine/Elasticsearch/Indexer.pm index 38b3982b48..a6bd323d30 100644 --- a/Koha/SearchEngine/Elasticsearch/Indexer.pm +++ b/Koha/SearchEngine/Elasticsearch/Indexer.pm @@ -243,6 +243,7 @@ sub drop_index { my $conf = $self->get_elasticsearch_params(); my $elasticsearch = $self->get_elasticsearch(); $elasticsearch->indices->delete(index => $conf->{index_name}); + $self->index_status_recreate_required(1); } } diff --git a/t/db_dependent/Koha_Elasticsearch_Indexer.t b/t/db_dependent/Koha_Elasticsearch_Indexer.t index 235fbb5db0..80bfe79956 100644 --- a/t/db_dependent/Koha_Elasticsearch_Indexer.t +++ b/t/db_dependent/Koha_Elasticsearch_Indexer.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 2; use Test::MockModule; use t::lib::Mocks; @@ -29,26 +29,41 @@ my $schema = Koha::Database->schema(); use_ok('Koha::SearchEngine::Elasticsearch::Indexer'); -my $indexer; -ok( - $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblio' }), - 'Creating new indexer object' -); +subtest 'create_index() tests' => sub { + plan tests => 4; + my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); + $se->mock( 'get_elasticsearch_params', sub { + my ($self, $sub ) = @_; + my $method = $se->original( 'get_elasticsearch_params' ); + my $params = $method->( $self ); + $params->{index_name} .= '__test'; + return $params; + }); -my $marc_record = MARC::Record->new(); -$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]; + my $indexer; + ok( + $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' }), + 'Creating a new indexer object' + ); -SKIP: { + is( + $indexer->create_index(), + Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_OK(), + 'Creating an index' + ); - eval { $indexer->get_elasticsearch_params; }; + my $marc_record = MARC::Record->new(); + $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($indexer->update_index(undef, $records), 'Update Index'); - skip 'Elasticsearch configuration not available', 1 - if $@; - - ok( $indexer->update_index(undef, $records), 'Update Index' ); -} + is( + $indexer->drop_index(), + Koha::SearchEngine::Elasticsearch::Indexer::INDEX_STATUS_RECREATE_REQUIRED(), + 'Dropping the index' + ); +}; -- 2.39.5