diff --git a/spec/acceptance/tests/acceptance_spec.rb b/spec/acceptance/tests/acceptance_spec.rb index c6abb53..e48a8c7 100644 --- a/spec/acceptance/tests/acceptance_spec.rb +++ b/spec/acceptance/tests/acceptance_spec.rb @@ -1,92 +1,92 @@ require 'spec_helper_acceptance' require 'helpers/acceptance/tests/basic_shared_examples.rb' require 'helpers/acceptance/tests/template_shared_examples.rb' require 'helpers/acceptance/tests/removal_shared_examples.rb' require 'helpers/acceptance/tests/pipeline_shared_examples.rb' require 'helpers/acceptance/tests/plugin_shared_examples.rb' require 'helpers/acceptance/tests/plugin_upgrade_shared_examples.rb' require 'helpers/acceptance/tests/snapshot_repository_shared_examples.rb' require 'helpers/acceptance/tests/datadir_shared_examples.rb' require 'helpers/acceptance/tests/package_url_shared_examples.rb' require 'helpers/acceptance/tests/hiera_shared_examples.rb' require 'helpers/acceptance/tests/usergroup_shared_examples.rb' require 'helpers/acceptance/tests/security_shared_examples.rb' describe "elasticsearch v#{v[:elasticsearch_full_version]} class" do es_config = { 'http.port' => 9200, 'node.name' => 'elasticsearch01' } let(:elastic_repo) { not v[:is_snapshot] } let(:manifest) do package = if not v[:is_snapshot] <<-MANIFEST # Hard version set here due to plugin incompatibilities. version => '#{v[:elasticsearch_full_version]}', MANIFEST else <<-MANIFEST manage_repo => false, package_url => '#{v[:snapshot_package]}', MANIFEST end <<-MANIFEST api_timeout => 60, config => { 'cluster.name' => '#{v[:cluster_name]}', 'http.bind_host' => '0.0.0.0', #{es_config.map { |k, v| " '#{k}' => '#{v}'," }.join("\n")} }, jvm_options => [ '-Xms128m', '-Xmx128m', ], oss => #{v[:oss]}, #{package} MANIFEST end context 'testing with' do describe 'simple config' do include_examples('basic acceptance tests', es_config) end include_examples('module removal', es_config) end - # include_examples('template operations', es_config, v[:template]) + include_examples('template operations', es_config, v[:template]) - # include_examples('pipeline operations', es_01, v[:pipeline]) if semver(v[:elasticsearch_full_version]) >= semver('5.0.0') + include_examples('pipeline operations', es_config, v[:pipeline]) # include_examples('plugin acceptance tests', v[:elasticsearch_plugins]) unless v[:elasticsearch_plugins].empty? # # Only pre-5.x versions supported versions differing from core ES # if semver(v[:elasticsearch_full_version]) < semver('5.0.0') # include_examples( # 'plugin upgrade acceptance tests', # :name => 'kopf', # :initial => '2.0.1', # :upgraded => '2.1.2', # :repository => 'lmenezes/elasticsearch' # ) # end # include_examples 'snapshot repository acceptance tests' # include_examples 'datadir acceptance tests' # # Skip this for snapshot testing, as we only have package files anyway. # include_examples 'package_url acceptance tests' unless v[:is_snapshot] # include_examples 'hiera acceptance tests', v[:elasticsearch_plugins] # include_examples 'user/group acceptance tests' # # Security-related tests (shield/x-pack). # # # # Skip OSS-only distributions since they do not bundle x-pack, and skip # # snapshots since we they don't recognize prod licenses. # include_examples 'security acceptance tests', instances unless v[:oss] or v[:is_snapshot] end diff --git a/spec/helpers/acceptance/tests/pipeline_shared_examples.rb b/spec/helpers/acceptance/tests/pipeline_shared_examples.rb index 191e811..181eaf0 100644 --- a/spec/helpers/acceptance/tests/pipeline_shared_examples.rb +++ b/spec/helpers/acceptance/tests/pipeline_shared_examples.rb @@ -1,39 +1,56 @@ require 'json' require 'helpers/acceptance/tests/manifest_shared_examples' require 'helpers/acceptance/tests/bad_manifest_shared_examples' -shared_examples 'pipeline operations' do |instances, pipeline| +shared_examples 'pipeline operations' do |es_config, pipeline| describe 'pipeline resources' do let(:pipeline_name) { 'foo' } context 'present' do let(:extra_manifest) do <<-MANIFEST elasticsearch::pipeline { '#{pipeline_name}': ensure => 'present', content => #{pipeline} } MANIFEST end - include_examples( - 'manifest application', - instances - ) + include_examples('manifest application') - context 'absent' do - let(:extra_manifest) do - <<-MANIFEST - elasticsearch::template { '#{pipeline_name}': - ensure => absent, - } - MANIFEST - end + include_examples('pipeline content', es_config, pipeline) + end + + context 'absent' do + let(:extra_manifest) do + <<-MANIFEST + elasticsearch::template { '#{pipeline_name}': + ensure => absent, + } + MANIFEST + end + + include_examples('manifest application') + end + end +end + +# Verifies the content of a loaded index template. +shared_examples 'pipeline content' do |es_config, pipeline| + elasticsearch_port = es_config['http.port'] + describe port(elasticsearch_port) do + it 'open', :with_retries do + should be_listening + end + end - include_examples( - 'manifest application', - instances - ) + describe server :container do + describe http( + "http://localhost:#{elasticsearch_port}/_ingest/pipeline" + ) do + it 'returns the configured pipelines', :with_retries do + expect(JSON.parse(response.body).values) + .to include(include(pipeline)) end end end end diff --git a/spec/helpers/acceptance/tests/template_shared_examples.rb b/spec/helpers/acceptance/tests/template_shared_examples.rb index 8b92ae0..11044ad 100644 --- a/spec/helpers/acceptance/tests/template_shared_examples.rb +++ b/spec/helpers/acceptance/tests/template_shared_examples.rb @@ -1,111 +1,111 @@ require 'json' require 'helpers/acceptance/tests/manifest_shared_examples' require 'helpers/acceptance/tests/bad_manifest_shared_examples' # Describes how to apply a manifest with a template, verify it, and clean it up shared_examples 'template application' do |es_config, name, template, param| context 'present' do let(:extra_manifest) do <<-MANIFEST elasticsearch::template { '#{name}': ensure => 'present', #{param} } MANIFEST end include_examples('manifest application') - include_examples 'template content', es_config, template + include_examples('template content', es_config, template) end context 'absent' do let(:extra_manifest) do <<-MANIFEST elasticsearch::template { '#{name}': ensure => absent, } MANIFEST end include_examples('manifest application') end end # Verifies the content of a loaded index template. shared_examples 'template content' do |es_config, template| elasticsearch_port = es_config['http.port'] describe port(elasticsearch_port) do it 'open', :with_retries do should be_listening end end describe server :container do describe http( "http://localhost:#{elasticsearch_port}/_template", :params => { 'flat_settings' => 'false' } ) do it 'returns the installed template', :with_retries do expect(JSON.parse(response.body).values) .to include(include(template)) end end end end # Main entrypoint for template tests shared_examples 'template operations' do |es_config, template| describe 'template resources' do before :all do shell "mkdir -p #{default['distmoduledir']}/another/files" create_remote_file( default, "#{default['distmoduledir']}/another/files/good.json", JSON.dump(template) ) create_remote_file( default, "#{default['distmoduledir']}/another/files/bad.json", JSON.dump(template)[0..-5] ) end context 'configured through' do context '`source`' do include_examples( 'template application', es_config, SecureRandom.hex(8), template, "source => 'puppet:///modules/another/good.json'" ) end context '`content`' do include_examples( 'template application', es_config, SecureRandom.hex(8), template, "content => '#{JSON.dump(template)}'" ) end context 'bad json' do let(:extra_manifest) do <<-MANIFEST elasticsearch::template { '#{SecureRandom.hex(8)}': ensure => 'present', file => 'puppet:///modules/another/bad.json' } MANIFEST end include_examples('invalid manifest application') end end end end