Centralized Elasticsearch and searchindex logic into single support helper module. This fixes an issue on the CI env that is caused by not removed ES indexes.
This commit is contained in:
parent
7f4c540fa0
commit
c50d6a49ed
10 changed files with 82 additions and 235 deletions
|
@ -1,43 +1,16 @@
|
|||
|
||||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class FormControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
@headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json', 'REMOTE_ADDR' => '1.2.3.4' }
|
||||
|
||||
if ENV['ES_URL'].present?
|
||||
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
end
|
||||
configure_elasticsearch
|
||||
|
||||
Ticket.destroy_all
|
||||
|
||||
# drop/create indexes
|
||||
Setting.reload
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
end
|
||||
|
||||
teardown do
|
||||
if ENV['ES_URL'].present?
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
rebuild_searchindex
|
||||
end
|
||||
|
||||
test '01 - get config call' do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class OrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
|
@ -73,32 +73,11 @@ class OrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
organization_id: @organization.id,
|
||||
)
|
||||
|
||||
# configure es
|
||||
if ENV['ES_URL'].present?
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
configure_elasticsearch do
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class ReportsControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
|
@ -69,31 +70,12 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
|
|||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
if ENV['ES_URL'].present?
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
configure_elasticsearch do
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
@ -101,11 +83,6 @@ class ReportsControllerTest < ActionDispatch::IntegrationTest
|
|||
sleep 6
|
||||
end
|
||||
end
|
||||
teardown do
|
||||
if ENV['ES_URL'].present?
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
|
||||
test '01.01 report example - admin access' do
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class SearchControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set current user
|
||||
|
@ -142,35 +142,11 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
type: Ticket::Article::Type.where(name: 'email').first,
|
||||
)
|
||||
|
||||
# configure es
|
||||
if ENV['ES_URL'].present?
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
|
||||
# set max attachment size in mb
|
||||
Setting.set('es_attachment_max_size_in_mb', 1)
|
||||
configure_elasticsearch do
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
@ -179,12 +155,6 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
teardown do
|
||||
if ENV['ES_URL'].present?
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
|
||||
test 'settings index with nobody' do
|
||||
params = {
|
||||
query: 'test 1234',
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class UserControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
|
@ -84,40 +84,19 @@ class UserControllerTest < ActionDispatch::IntegrationTest
|
|||
organization_id: @organization.id,
|
||||
)
|
||||
|
||||
# configure es
|
||||
if ENV['ES_URL'].present?
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
configure_elasticsearch do
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
||||
sleep 6
|
||||
end
|
||||
UserInfo.current_user_id = nil
|
||||
|
||||
UserInfo.current_user_id = nil
|
||||
end
|
||||
|
||||
test 'user create tests - no user' do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
require 'test_helper'
|
||||
require 'rake'
|
||||
|
||||
class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set accept header
|
||||
|
@ -84,39 +84,17 @@ class UserOrganizationControllerTest < ActionDispatch::IntegrationTest
|
|||
organization_id: @organization.id,
|
||||
)
|
||||
|
||||
# configure es
|
||||
if ENV['ES_URL'].present?
|
||||
#fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
configure_elasticsearch do
|
||||
|
||||
travel 1.minute
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
||||
sleep 6
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
test 'user create tests - no user' do
|
||||
|
|
|
@ -1,38 +1,13 @@
|
|||
|
||||
require 'integration_test_helper'
|
||||
require 'rake'
|
||||
|
||||
class ElasticsearchTest < ActiveSupport::TestCase
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set config
|
||||
if ENV['ES_URL'].blank?
|
||||
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
end
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
configure_elasticsearch(required: true)
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
# set max attachment size in mb
|
||||
Setting.set('es_attachment_max_size_in_mb', 1)
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
groups = Group.where(name: 'Users')
|
||||
roles = Role.where(name: 'Agent')
|
||||
|
@ -100,12 +75,6 @@ class ElasticsearchTest < ActiveSupport::TestCase
|
|||
)
|
||||
end
|
||||
|
||||
teardown do
|
||||
if ENV['ES_URL'].present?
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
|
||||
# check search attributes
|
||||
test 'a - objects' do
|
||||
|
||||
|
|
|
@ -1,37 +1,15 @@
|
|||
|
||||
require 'integration_test_helper'
|
||||
require 'rake'
|
||||
|
||||
class ReportTest < ActiveSupport::TestCase
|
||||
include SearchindexHelper
|
||||
|
||||
setup do
|
||||
|
||||
# set config
|
||||
if ENV['ES_URL'].blank?
|
||||
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
end
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
# Setting.set('es_attachment_max_size_in_mb', 1)
|
||||
configure_elasticsearch(required: true)
|
||||
|
||||
Ticket.destroy_all
|
||||
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
rebuild_searchindex
|
||||
|
||||
group1 = Group.lookup(name: 'Users')
|
||||
group2 = Group.create_if_not_exists(
|
||||
|
@ -275,13 +253,6 @@ class ReportTest < ActiveSupport::TestCase
|
|||
|
||||
# execute background jobs
|
||||
Scheduler.worker(true)
|
||||
|
||||
end
|
||||
|
||||
teardown do
|
||||
if ENV['ES_URL'].present?
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
|
||||
test 'compare' do
|
||||
|
|
|
@ -3,6 +3,8 @@ require File.expand_path('../config/environment', __dir__)
|
|||
require 'rails/test_help'
|
||||
require 'cache'
|
||||
|
||||
require 'test_support_helper'
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
|
||||
# disable transactions / to work with own database connections for each thread
|
||||
|
|
49
test/support/searchindex_helper.rb
Normal file
49
test/support/searchindex_helper.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require 'rake'
|
||||
|
||||
module SearchindexHelper
|
||||
|
||||
def self.included(base)
|
||||
|
||||
base.teardown do
|
||||
next if ENV['ES_URL'].blank?
|
||||
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
|
||||
def configure_elasticsearch(required: false)
|
||||
if ENV['ES_URL'].blank?
|
||||
return if !required
|
||||
raise "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
|
||||
end
|
||||
|
||||
Setting.set('es_url', ENV['ES_URL'])
|
||||
|
||||
# Setting.set('es_url', 'http://127.0.0.1:9200')
|
||||
# Setting.set('es_index', 'estest.local_zammad')
|
||||
# Setting.set('es_user', 'elasticsearch')
|
||||
# Setting.set('es_password', 'zammad')
|
||||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
|
||||
end
|
||||
Setting.set('es_index', ENV['ES_INDEX'])
|
||||
|
||||
# set max attachment size in mb
|
||||
Setting.set('es_attachment_max_size_in_mb', 1)
|
||||
|
||||
yield if block_given?
|
||||
end
|
||||
|
||||
def rebuild_searchindex
|
||||
# drop/create indexes
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
#Rake::Task["searchindex:drop"].execute
|
||||
#Rake::Task["searchindex:create"].execute
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue