Skip to content

Commit

Permalink
Merge pull request #48 from redBorder/feature/basic_test_for_mongodb
Browse files Browse the repository at this point in the history
Added mongodb basic test
  • Loading branch information
manegron authored Dec 5, 2023
2 parents eb73dc7 + 151e9f1 commit c0384e0
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions spec/services/mongodb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

require 'spec_helper'
set :os, family: 'redhat', release: '9', arch: 'x86_64'

packages = %w[
cookbook-mongodb
]
service = 'mongodb'
port = 27_017

describe "Checking packages for #{service}..." do
packages.each do |package|
describe package(package) do
before do
skip("#{package} is not installed, skipping...") unless package(package).installed?
end

it 'is expected to be installed' do
expect(package(package).installed?).to be true
end
end
end
end

service_status = command("systemctl is-enabled #{service}").stdout
service_status = service_status.strip

if service_status == 'enabled'
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
end

describe port(port) do
it { should be_listening }
end

describe 'Registered in consul' do
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{service} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{service} | jq -r '.[].Checks[0].Status'").stdout
health = health.strip
registered = JSON.parse(service_json).key?('Address') && health == 'passing' ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end

0 comments on commit c0384e0

Please sign in to comment.