Skip to content

Commit 7d2aaed

Browse files
committed
[API] Refactors testing in elasticsearch-api
Reorganizes directories, removes unnecessary tests. Keeping a minimal integration test suite and counting on YAML test runner for API coverage. Migrating minitest unit tests for api/actions to RSpec.
1 parent b1abea8 commit 7d2aaed

File tree

410 files changed

+99
-6762
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

410 files changed

+99
-6762
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Licensed to Elasticsearch B.V. under one or more contributor
24
# license agreements. See the NOTICE file distributed with
35
# this work for additional information regarding copyright
@@ -16,21 +18,21 @@
1618
# under the License.
1719

1820
require 'base64'
19-
require_relative '../platinum_helper'
21+
require_relative './spec_helper'
2022

2123
describe 'API keys' do
2224
before do
23-
ADMIN_CLIENT.security.put_user(
25+
CLIENT.security.put_user(
2426
username: client_username,
2527
body: { password: 'test-password', roles: ['superuser'] }
2628
)
2729
end
2830

2931
after do
30-
ADMIN_CLIENT.security.delete_user(username: client_username)
32+
CLIENT.security.delete_user(username: client_username)
3133
end
3234

33-
let(:client_username) { "query_api_keys_#{Time.new.to_i}"}
35+
let(:client_username) { "query_api_keys_#{Time.new.to_i}" }
3436
let(:credentials) { Base64.strict_encode64("#{client_username}:test-password") }
3537

3638
let(:client) do
@@ -41,71 +43,71 @@
4143
end
4244

4345
it 'queries API keys' do
44-
key_name_1 = "query-key-1-#{Time.new.to_i}"
46+
key_name1 = "query-key-1-#{Time.new.to_i}"
4547
response = client.security.create_api_key(
4648
body: {
47-
name: key_name_1,
49+
name: key_name1,
4850
role_descriptors: {},
49-
expiration: "1d",
50-
metadata: { search: "this" }
51+
expiration: '1d',
52+
metadata: { search: 'this' }
5153
}
5254
)
53-
expect(response['name']).to eq key_name_1
55+
expect(response['name']).to eq key_name1
5456
expect(response['api_key']).not_to be nil
55-
api_key_id_1 = response['id']
57+
api_key_id1 = response['id']
5658

57-
key_name_2 = "query-key-2-#{Time.new.to_i}"
59+
key_name2 = "query-key-2-#{Time.new.to_i}"
5860
response = client.security.create_api_key(
5961
body: {
60-
name: key_name_2,
61-
expiration: "2d",
62-
role_descriptors: { "role-a" => { "cluster": [ "monitor"] } },
62+
name: key_name2,
63+
expiration: '2d',
64+
role_descriptors: { 'role-a' => { "cluster": ['monitor'] } },
6365
metadata: { search: false }
6466
}
6567
)
66-
expect(response['name']).to eq key_name_2
68+
expect(response['name']).to eq key_name2
6769
expect(response['api_key']).not_to be nil
68-
api_key_id_2 = response['id']
70+
api_key_id2 = response['id']
6971

70-
key_name_3 = "query-key-3#{Time.new.to_i}"
72+
key_name3 = "query-key-3#{Time.new.to_i}"
7173
response = client.security.create_api_key(
7274
body: {
73-
name: key_name_3,
74-
expiration: "3d",
75+
name: key_name3,
76+
expiration: '3d'
7577
}
7678
)
77-
expect(response['name']).to eq key_name_3
79+
expect(response['name']).to eq key_name3
7880
expect(response['api_key']).not_to be nil
79-
api_key_id_3 = response['id']
81+
api_key_id3 = response['id']
8082

8183
response = client.security.authenticate
82-
owner_name = response['username']
84+
response['username']
8385

8486
response = client.security.query_api_keys(
8587
body: {
86-
query: { wildcard: { name: key_name_1 }}
88+
query: { wildcard: { name: key_name1 } }
8789
}
8890
)
8991
expect(response['total']).to eq 1
9092
expect(response['count']).to eq 1
91-
expect(response['api_keys'].first['id']).to eq api_key_id_1
93+
expect(response['api_keys'].first['id']).to eq api_key_id1
9294

9395
response = client.security.query_api_keys(
9496
body: {
95-
query: { wildcard: { name: key_name_2 }}
97+
query: { wildcard: { name: key_name2 } }
9698
}
9799
)
98100
expect(response['total']).to eq 1
99101
expect(response['count']).to eq 1
100-
expect(response['api_keys'].first['id']).to eq api_key_id_2
102+
expect(response['api_keys'].first['id']).to eq api_key_id2
101103

102104
response = client.security.query_api_keys(
103105
body: {
104-
query: { wildcard: { name: key_name_3 }}
106+
query: { wildcard: { name: key_name3 } }
105107
}
106108
)
107109
expect(response['total']).to eq 1
108110
expect(response['count']).to eq 1
109-
expect(response['api_keys'].first['id']).to eq api_key_id_3
111+
expect(response['api_keys'].first['id']).to eq api_key_id3
110112
end
111113
end

elasticsearch-api/spec/platinum/integration/health/health_spec.rb renamed to elasticsearch-api/spec/integration/health_spec.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Licensed to Elasticsearch B.V. under one or more contributor
24
# license agreements. See the NOTICE file distributed with
35
# this work for additional information regarding copyright
@@ -15,12 +17,20 @@
1517
# specific language governing permissions and limitations
1618
# under the License.
1719

18-
require_relative '../platinum_helper'
20+
require_relative './spec_helper'
21+
22+
describe 'Health basic test' do
23+
it 'performs the request' do
24+
response = CLIENT.health_report
25+
expect(response.status).to eq 200
26+
expect(response['cluster_name']).not_to be_nil
27+
expect(response.dig('indicators', 'master_is_stable', 'symptom')).to eq 'The cluster has a stable master node'
28+
expect(response.dig('indicators', 'master_is_stable', 'status')).to eq 'green'
29+
end
1930

20-
describe 'Health API' do
2131
context 'Usage stats on the health API' do
2232
before do
23-
ADMIN_CLIENT.indices.create(
33+
CLIENT.indices.create(
2434
index: 'red_index',
2535
body: {
2636
settings: {
@@ -33,13 +43,13 @@
3343
end
3444

3545
after do
36-
ADMIN_CLIENT.indices.delete(index: 'red_index')
46+
CLIENT.indices.delete(index: 'red_index')
3747
end
3848

3949
it 'responds with health report' do
40-
expect(ADMIN_CLIENT.health_report.status).to eq 200
41-
expect(ADMIN_CLIENT.health_report(feature: 'disk').status).to eq 200
42-
response = ADMIN_CLIENT.xpack.usage
50+
expect(CLIENT.health_report.status).to eq 200
51+
expect(CLIENT.health_report(feature: 'disk').status).to eq 200
52+
response = CLIENT.xpack.usage
4353
expect(response['health_api']['available']).to eq true
4454
expect(response['health_api']['enabled']).to eq true
4555
expect(response['health_api']['invocations']['total']).to be >= 2

elasticsearch-api/spec/platinum/integration/platinum_helper.rb renamed to elasticsearch-api/spec/integration/spec_helper.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# Licensed to Elasticsearch B.V. under one or more contributor
24
# license agreements. See the NOTICE file distributed with
35
# this work for additional information regarding copyright
@@ -14,13 +16,11 @@
1416
# KIND, either express or implied. See the License for the
1517
# specific language governing permissions and limitations
1618
# under the License.
17-
1819
require 'openssl'
1920
require 'elasticsearch'
2021

21-
CERTS_PATH = File.expand_path('./../.buildkite/certs')
22-
23-
host = ENV['TEST_ES_SERVER'] || 'https://localhost:9200'
22+
CERTS_PATH = File.expand_path('./../../../.buildkite/certs', __dir__)
23+
host = ENV['TEST_ES_SERVER'] || 'http://localhost:9200'
2424
raise URI::InvalidURIError unless host =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
2525

2626
password = ENV['ELASTIC_PASSWORD'] || 'changeme'
@@ -31,12 +31,11 @@
3131
key = OpenSSL::PKey::RSA.new(raw_key)
3232
ca_file = File.expand_path("#{CERTS_PATH}/ca.crt")
3333
TRANSPORT_OPTIONS = { ssl: { verify: false, client_cert: certificate, client_key: key, ca_file: ca_file } }
34-
HOST = "https://elastic:#{password}@#{HOST_URI.host}:#{HOST_URI.port}".freeze
35-
36-
ADMIN_CLIENT = Elasticsearch::Client.new(host: HOST, transport_options: TRANSPORT_OPTIONS)
34+
HOST = "https://elastic:#{password}@#{HOST_URI.host}:#{HOST_URI.port}"
35+
CLIENT = Elasticsearch::Client.new(host: HOST, transport_options: TRANSPORT_OPTIONS)
3736

3837
RSpec.configure do |config|
3938
config.add_formatter('documentation')
40-
config.add_formatter('RSpec::Core::Formatters::HtmlFormatter', "tmp/platinum-#{ENV['RUBY_VERSION']}-manual-integration.html")
39+
config.add_formatter('RSpec::Core::Formatters::HtmlFormatter', "tmp/#{ENV['RUBY_VERSION']}-manual-integration.html")
4140
config.color_mode = :on
4241
end

elasticsearch-api/spec/platinum/integration/analytics/usage_spec.rb

Lines changed: 0 additions & 56 deletions
This file was deleted.

elasticsearch-api/spec/platinum/integration/api_key/api_key_admin_user_spec.rb

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)