Skip to content

Commit

Permalink
test: Fix failed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Nov 20, 2023
1 parent aeb2f8d commit 15a90a1
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 379 deletions.
2 changes: 1 addition & 1 deletion test/plugin/test_elasticsearch_fallback_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup
def stub_elastic(url="http://localhost:9200/_bulk")
stub_request(:post, url).with do |req|
@index_cmds = req.body.split("\n").map {|r| JSON.parse(r) }
end
end.to_return({:status => 200, :body => "{}", :headers => { 'Content-Type' => 'json', 'x-elastic-product' => 'Elasticsearch' } })
end

def elasticsearch_version
Expand Down
12 changes: 6 additions & 6 deletions test/plugin/test_elasticsearch_index_lifecycle_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def stub_elastic_info(url="http://localhost:9200/", version=elasticsearch_versio

def test_xpack_info
stub_request(:get, "http://localhost:9200/_xpack").
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json", 'x-elastic-product' => 'Elasticsearch' })
stub_elastic_info
expected = {"features"=>{"ilm"=>{"available"=>true, "enabled"=>true}}}
if xpack_info.is_a?(Elasticsearch::API::Response)
Expand All @@ -72,32 +72,32 @@ def test_xpack_info

def test_verify_ilm_working
stub_request(:get, "http://localhost:9200/_xpack").
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json" })
to_return(:status => 200, :body => '{"features":{"ilm":{"available":true,"enabled":true}}}', :headers => {"Content-Type"=> "application/json", 'x-elastic-product' => 'Elasticsearch' })
stub_elastic_info
assert_nothing_raised { verify_ilm_working }
end

def test_ilm_policy_doesnt_exists
stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluentd-policy")}").
to_return(:status => 404, :body => "", :headers => {})
to_return(:status => 404, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
stub_elastic_info
assert_false(ilm_policy_exists?("fluentd-policy"))
end

def test_ilm_policy_exists
stub_request(:get, "http://localhost:9200/#{ilm_existence_endpoint("fluent-policy")}").
to_return(:status => 200, :body => "", :headers => {})
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
stub_elastic_info
assert_true(ilm_policy_exists?("fluent-policy"))
end

def test_create_ilm_policy
stub_request(:get, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
to_return(:status => 404, :body => "", :headers => {})
to_return(:status => 404, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
stub_request(:put, "http://localhost:9200/#{ilm_creation_endpoint("fluent-policy")}").
with(:body => "{\"policy\":{\"phases\":{\"hot\":{\"actions\":{\"rollover\":{\"max_size\":\"50gb\",\"max_age\":\"30d\"}}}}}}",
:headers => {'Content-Type'=>'application/json'}).
to_return(:status => 200, :body => "", :headers => {})
to_return(:status => 200, :body => "", :headers => {'x-elastic-product' => 'Elasticsearch'})
stub_elastic_info
create_ilm_policy("fluent-policy")

Expand Down
20 changes: 10 additions & 10 deletions test/plugin/test_in_elasticsearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def test_emit
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_response.to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG)
Expand All @@ -350,7 +350,7 @@ def test_emit_with_custom_index_name
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_response(index_name).to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG + %[index_name #{index_name}])
Expand All @@ -366,7 +366,7 @@ def test_emit_with_parse_timestamp
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_response(index_name).to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG + %[parse_timestamp])
Expand All @@ -385,7 +385,7 @@ def test_emit_with_parse_timestamp_and_timstamp_format
stub_request(@http_method, "http://localhost:9200/#{index_name}/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_response(index_name).to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG + %[parse_timestamp true
Expand All @@ -405,7 +405,7 @@ def test_emit_with_docinfo
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_response.to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG + %[docinfo true])
Expand All @@ -425,11 +425,11 @@ def test_emit_with_slices
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":0,\"max\":2}}").
to_return(status: 200, body: sample_response.to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1000").
with(body: "{\"sort\":[\"_doc\"],\"slice\":{\"id\":1,\"max\":2}}").
to_return(status: 200, body: sample_response.to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
stub_elastic_info

driver(CONFIG + %[num_slices 2])
Expand All @@ -446,7 +446,7 @@ def test_emit_with_size
stub_request(@http_method, "http://localhost:9200/fluentd/_search?scroll=1m&size=1").
with(body: "{\"sort\":[\"_doc\"]}").
to_return(status: 200, body: sample_scroll_response.to_s,
headers: {'Content-Type' => 'application/json'})
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'})
connection = 0
scroll_request = stub_request(@http_method, "http://localhost:9200/_search/scroll?scroll=1m").
with(
Expand All @@ -457,10 +457,10 @@ def test_emit_with_size
scroll_request.to_return(lambda do |req|
if connection <= 1
{status: 200, body: sample_scroll_response_2.to_s,
headers: {'Content-Type' => 'application/json'}}
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'}}
else
{status: 200, body: sample_scroll_response_terminate.to_s,
headers: {'Content-Type' => 'application/json'}}
headers: {'Content-Type' => 'application/json', 'X-elastic-product' => 'Elasticsearch'}}
end
end)
stub_request(:delete, "http://localhost:9200/_search/scroll/WomkoUKG0QPB679Ulo6TqQgh3pIGRUmrl9qXXGK3EeiQh9rbYNasTkspZQcJ01uz").
Expand Down
Loading

0 comments on commit 15a90a1

Please sign in to comment.