Skip to content
Snippets Groups Projects
Commit 10d9c574 authored by Erick Banks's avatar Erick Banks Committed by Ramya Authappan
Browse files

Add tests for each individual search index

parent 1dae49eb
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -18,12 +18,14 @@ class Issue < Base
:iid,
:assignee_ids,
:labels,
:title
:title,
:description
 
def initialize
@assignee_ids = []
@labels = []
@title = "Issue title #{SecureRandom.hex(8)}"
@description = "Issue description #{SecureRandom.hex(8)}"
end
 
def fabricate!
Loading
Loading
@@ -34,7 +36,7 @@ def fabricate!
Page::Project::Issue::New.perform do |new_page|
new_page.fill_title(@title)
new_page.choose_template(@template) if @template
new_page.fill_description(@description) if @description
new_page.fill_description(@description) if @description && !@template
new_page.choose_milestone(@milestone) if @milestone
new_page.create_new_issue
end
Loading
Loading
@@ -64,6 +66,7 @@ def api_post_body
}.tap do |hash|
hash[:milestone_id] = @milestone.id if @milestone
hash[:weight] = @weight if @weight
hash[:description] = @description if @description
end
end
 
Loading
Loading
Loading
Loading
@@ -8,6 +8,10 @@ module Search
extend self
extend Support::Api
 
RETRY_MAX_ITERATION = 10
RETRY_SLEEP_INTERVAL = 12
INSERT_RECALL_THRESHOLD = RETRY_MAX_ITERATION * RETRY_SLEEP_INTERVAL
ElasticSearchServerError = Class.new(RuntimeError)
 
def assert_elasticsearch_responding
Loading
Loading
@@ -85,7 +89,7 @@ def find_project(project, search_term)
private
 
def find_target_in_scope(scope, search_term)
QA::Support::Retrier.retry_until(max_attempts: 10, sleep_interval: 10, raise_on_failure: true, retry_on_exception: true) do
QA::Support::Retrier.retry_until(max_attempts: RETRY_MAX_ITERATION, sleep_interval: RETRY_SLEEP_INTERVAL, raise_on_failure: true, retry_on_exception: true) do
result = search(scope, search_term)
result && result.any? { |record| yield record }
end
Loading
Loading
# frozen_string_literal: true
require 'airborne'
require 'securerandom'
module QA
RSpec.describe 'Enablement:Search' do
describe 'When using elasticsearch API to search for a public issue', :orchestrated, :elasticsearch do
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:issue) do
Resource::Issue.fabricate_via_api! do |issue|
issue.title = 'Issue for issue index test'
issue.description = "Some issue description #{SecureRandom.hex(8)}"
end
end
let(:elasticsearch_original_state_on?) { Runtime::Search.elasticsearch_on?(api_client) }
before do
unless elasticsearch_original_state_on?
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api!
end
end
after do
if !elasticsearch_original_state_on? && !api_client.nil?
Runtime::Search.disable_elasticsearch(api_client)
end
issue.project.remove_via_api!
end
it 'finds issue that matches description', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1870' do
QA::Support::Retrier.retry_on_exception(max_attempts: Runtime::Search::RETRY_MAX_ITERATION, sleep_interval: Runtime::Search::RETRY_SLEEP_INTERVAL) do
get Runtime::Search.create_search_request(api_client, 'issues', issue.description).url
expect_status(QA::Support::Api::HTTP_STATUS_OK)
raise 'Empty search result returned' if json_body.empty?
expect(json_body[0][:description]).to eq(issue.description)
expect(json_body[0][:project_id]).to equal(issue.project.id)
end
end
end
end
end
# frozen_string_literal: true
require 'airborne'
require 'securerandom'
module QA
RSpec.describe 'Enablement:Search' do
describe 'When using elasticsearch API to search for a public blob', :orchestrated, :elasticsearch do
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = "test-project-for-blob-index"
end
end
let(:project_file_content) { "File content for blob index test #{SecureRandom.hex(8)}" }
let(:elasticsearch_original_state_on?) { Runtime::Search.elasticsearch_on?(api_client) }
before do
unless elasticsearch_original_state_on?
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api!
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.add_files([
{ file_path: 'README.md', content: project_file_content }
])
end
end
after do
if !elasticsearch_original_state_on? && !api_client.nil?
Runtime::Search.disable_elasticsearch(api_client)
end
project.remove_via_api!
end
it 'finds blob that matches file content', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1869' do
QA::Support::Retrier.retry_on_exception(max_attempts: Runtime::Search::RETRY_MAX_ITERATION, sleep_interval: Runtime::Search::RETRY_SLEEP_INTERVAL) do
get Runtime::Search.create_search_request(api_client, 'blobs', project_file_content).url
expect_status(QA::Support::Api::HTTP_STATUS_OK)
raise 'Empty search result returned' if json_body.empty?
expect(json_body[0][:data]).to match(project_file_content)
expect(json_body[0][:project_id]).to equal(project.id)
end
end
end
end
end
# frozen_string_literal: true
require 'airborne'
require 'securerandom'
module QA
RSpec.describe 'Enablement:Search' do
describe 'When using elasticsearch API to search for a public merge request', :orchestrated, :elasticsearch do
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:merge_request) do
Resource::MergeRequest.fabricate_via_api! do |mr|
mr.title = 'Merge request for merge request index test'
mr.description = "Some merge request description #{SecureRandom.hex(8)}"
end
end
let(:elasticsearch_original_state_on?) { Runtime::Search.elasticsearch_on?(api_client) }
before do
unless elasticsearch_original_state_on?
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api!
end
end
after do
if !elasticsearch_original_state_on? && !api_client.nil?
Runtime::Search.disable_elasticsearch(api_client)
end
merge_request.project.remove_via_api!
end
it 'finds merge request that matches description', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1867' do
QA::Support::Retrier.retry_on_exception(max_attempts: Runtime::Search::RETRY_MAX_ITERATION, sleep_interval: Runtime::Search::RETRY_SLEEP_INTERVAL) do
get Runtime::Search.create_search_request(api_client, 'merge_requests', merge_request.description).url
expect_status(QA::Support::Api::HTTP_STATUS_OK)
raise 'Empty search result returned' if json_body.empty?
expect(json_body[0][:description]).to eq(merge_request.description)
expect(json_body[0][:project_id]).to eq(merge_request.project.id)
end
end
end
end
end
# frozen_string_literal: true
require 'airborne'
require 'securerandom'
module QA
RSpec.describe 'Enablement:Search' do
describe 'When using elasticsearch API to search for a public note', :orchestrated, :elasticsearch do
let(:api_client) { Runtime::API::Client.new(:gitlab) }
let(:issue) do
Resource::Issue.fabricate_via_api! do |issue|
issue.title = 'Issue for note index test'
end
end
let(:note) do
Resource::ProjectIssueNote.fabricate_via_api! do |project_issue_note|
project_issue_note.project = issue.project
project_issue_note.issue = issue
project_issue_note.body = "This is a comment with a unique number #{SecureRandom.hex(8)}"
end
end
let(:elasticsearch_original_state_on?) { Runtime::Search.elasticsearch_on?(api_client) }
before do
unless elasticsearch_original_state_on?
QA::EE::Resource::Settings::Elasticsearch.fabricate_via_api!
end
end
after do
if !elasticsearch_original_state_on? && !api_client.nil?
Runtime::Search.disable_elasticsearch(api_client)
end
issue.project.remove_via_api!
end
it 'finds note that matches note body', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1868' do
QA::Support::Retrier.retry_on_exception(max_attempts: Runtime::Search::RETRY_MAX_ITERATION, sleep_interval: Runtime::Search::RETRY_SLEEP_INTERVAL) do
get Runtime::Search.create_search_request(api_client, 'notes', note.body).url
expect_status(QA::Support::Api::HTTP_STATUS_OK)
raise 'Empty search result returned' if json_body.empty?
expect(json_body[0][:body]).to eq(note.body)
expect(json_body[0][:noteable_id]).to eq(issue.id)
end
end
end
end
end
Loading
Loading
@@ -25,6 +25,8 @@ module QA
end
 
Resource::Issue.fabricate_via_api! do |issue|
# Clears default description so as not to overwrite default template
issue.description = nil
issue.project = default_template_project
end.visit!
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment