Skip to content

Commit

Permalink
Modify chef_spec.rb when working in multi-node cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
ViMesTor committed Dec 11, 2023
1 parent 3383e17 commit 3ce13ba
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions spec/services/chef_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
]

service = 'chef-client'
serv_consul = 'erchef'
config_file = '/etc/chef/client.rb'
port = 4443

Expand Down Expand Up @@ -47,14 +46,17 @@
end

describe 'Registered in consul' do
serv_consul = 'erchef'
api_endpoint = 'http://localhost:8500/v1'
service_json = command("curl -s #{api_endpoint}/catalog/service/#{serv_consul} | jq -r '.[]'").stdout
health = command("curl -s #{api_endpoint}/health/service/#{serv_consul} | 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
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{serv_consul} | jq -c 'group_by(.ID)[]'").stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{serv_consul} | jq -r '.[].Checks[0].Status'").stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end
end
Expand Down

0 comments on commit 3ce13ba

Please sign in to comment.