-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Convert indices tests to rspec (#549)
- Loading branch information
Showing
90 changed files
with
2,952 additions
and
2,388 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
elasticsearch-api/spec/elasticsearch/api/actions/indices/analyze_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
require 'spec_helper' | ||
|
||
describe 'client.indices#analyze' do | ||
|
||
let(:expected_args) do | ||
[ | ||
'GET', | ||
url, | ||
params, | ||
body, | ||
nil | ||
] | ||
end | ||
|
||
let(:body) do | ||
nil | ||
end | ||
|
||
let(:url) do | ||
'_analyze' | ||
end | ||
|
||
let(:params) do | ||
{} | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze).to eq({}) | ||
end | ||
|
||
context 'when an index is specified' do | ||
|
||
let(:url) do | ||
'foo/_analyze' | ||
end | ||
|
||
let(:params) do | ||
{ index: 'foo' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze(index: 'foo')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when an url params are specified' do | ||
|
||
let(:params) do | ||
{ text: 'foo', analyzer: 'bar' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze(text: 'foo', analyzer: 'bar')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when a body is specified' do | ||
|
||
let(:body) do | ||
'foo' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze(body: 'foo')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when filters are specified' do | ||
|
||
let(:params) do | ||
{ filters: 'foo,bar', text: 'Test', tokenizer: 'whitespace' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze(text: 'Test', tokenizer: 'whitespace', filters: ['foo,bar'])).to eq({}) | ||
end | ||
end | ||
|
||
context 'when path must be URL-escaped' do | ||
|
||
let(:url) do | ||
'foo%5Ebar/_analyze' | ||
end | ||
|
||
let(:params) do | ||
{ text: 'Test', index: 'foo^bar' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.analyze(index: 'foo^bar', text: 'Test')).to eq({}) | ||
end | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
elasticsearch-api/spec/elasticsearch/api/actions/indices/clear_cache_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
|
||
describe 'client.indices#clear_cache' do | ||
|
||
let(:expected_args) do | ||
[ | ||
'POST', | ||
url, | ||
params, | ||
nil, | ||
nil | ||
] | ||
end | ||
|
||
let(:url) do | ||
'_cache/clear' | ||
end | ||
|
||
let(:params) do | ||
{} | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.clear_cache).to eq({}) | ||
end | ||
|
||
context 'when an index is specified' do | ||
|
||
let(:url) do | ||
'foo/_cache/clear' | ||
end | ||
|
||
let(:params) do | ||
{ index: 'foo' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.clear_cache(index: 'foo')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when params are specified' do | ||
|
||
let(:params) do | ||
{ field_data: true } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.clear_cache(field_data: true)).to eq({}) | ||
end | ||
end | ||
|
||
context 'when the path must be URL-escaped' do | ||
|
||
let(:url) do | ||
'foo%5Ebar/_cache/clear' | ||
end | ||
|
||
let(:params) do | ||
{ index: 'foo^bar' } | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.clear_cache(index: 'foo^bar')).to eq({}) | ||
end | ||
end | ||
end |
68 changes: 68 additions & 0 deletions
68
elasticsearch-api/spec/elasticsearch/api/actions/indices/close_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'spec_helper' | ||
|
||
describe 'client.indices#close' do | ||
|
||
let(:expected_args) do | ||
[ | ||
'POST', | ||
url, | ||
params, | ||
nil, | ||
nil | ||
] | ||
end | ||
|
||
let(:params) do | ||
{} | ||
end | ||
|
||
context 'when there is no index specified' do | ||
|
||
let(:client) do | ||
Class.new { include Elasticsearch::API }.new | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { | ||
client.indices.close | ||
}.to raise_exception(ArgumentError) | ||
end | ||
end | ||
|
||
context 'when an index is specified' do | ||
|
||
let(:url) do | ||
'foo/_close' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.close(index: 'foo')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when params are specified' do | ||
|
||
let(:params) do | ||
{ timeout: '1s' } | ||
end | ||
|
||
let(:url) do | ||
'foo/_close' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.close(index: 'foo', timeout: '1s')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when the path must be URL-escaped' do | ||
|
||
let(:url) do | ||
'foo%5Ebar/_close' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.close(index: 'foo^bar')).to eq({}) | ||
end | ||
end | ||
end |
68 changes: 68 additions & 0 deletions
68
elasticsearch-api/spec/elasticsearch/api/actions/indices/create_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'spec_helper' | ||
|
||
describe 'client.indices#create' do | ||
|
||
let(:expected_args) do | ||
[ | ||
'PUT', | ||
url, | ||
params, | ||
nil, | ||
nil | ||
] | ||
end | ||
|
||
let(:params) do | ||
{} | ||
end | ||
|
||
context 'when there is no index specified' do | ||
|
||
let(:client) do | ||
Class.new { include Elasticsearch::API }.new | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { | ||
client.indices.create | ||
}.to raise_exception(ArgumentError) | ||
end | ||
end | ||
|
||
context 'when an index is specified' do | ||
|
||
let(:url) do | ||
'foo' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.create(index: 'foo')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when params are specified' do | ||
|
||
let(:params) do | ||
{ timeout: '1s' } | ||
end | ||
|
||
let(:url) do | ||
'foo' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.create(index: 'foo', timeout: '1s')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when the path must be URL-escaped' do | ||
|
||
let(:url) do | ||
'foo%5Ebar' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.create(index: 'foo^bar')).to eq({}) | ||
end | ||
end | ||
end |
66 changes: 66 additions & 0 deletions
66
elasticsearch-api/spec/elasticsearch/api/actions/indices/delete_alias_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe 'client.indices#delete_alias' do | ||
|
||
let(:expected_args) do | ||
[ | ||
'DELETE', | ||
url, | ||
params, | ||
nil, | ||
nil | ||
] | ||
end | ||
|
||
let(:params) do | ||
{} | ||
end | ||
|
||
context 'when there is no index specified' do | ||
|
||
let(:client) do | ||
Class.new { include Elasticsearch::API }.new | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { | ||
client.indices.delete_alias(name: 'foo') | ||
}.to raise_exception(ArgumentError) | ||
end | ||
end | ||
|
||
context 'when there is no name specified' do | ||
|
||
let(:client) do | ||
Class.new { include Elasticsearch::API }.new | ||
end | ||
|
||
it 'raises an exception' do | ||
expect { | ||
client.indices.delete_alias(index: 'foo') | ||
}.to raise_exception(ArgumentError) | ||
end | ||
end | ||
|
||
context 'when an index and name are specified' do | ||
|
||
let(:url) do | ||
'foo/_alias/bar' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.delete_alias(index: 'foo', name: 'bar')).to eq({}) | ||
end | ||
end | ||
|
||
context 'when the path must be URL-escaped' do | ||
|
||
let(:url) do | ||
'foo%5Ebar/_alias/bar%2Fbam' | ||
end | ||
|
||
it 'performs the request' do | ||
expect(client_double.indices.delete_alias(index: 'foo^bar', name: 'bar/bam')).to eq({}) | ||
end | ||
end | ||
end |
Oops, something went wrong.