require 'spec_helper'

describe service('puppetserver') do
  it { should_not be_enabled }
  it { should_not be_running }
end

describe port(8140) do
  it { should_not be_listening }
end

describe command('timeout 60 puppetserver foreground') do
  its(:exit_status) { should eq 124 }
  its(:stdout) { should contain('Not submitting module metrics via Dropsonde -- submission is disabled.') }
  its(:stdout) { should contain('Puppet Server has successfully started and is now ready to handle requests') }
end

describe command('puppet resource service puppetserver ensure=running') do
  its(:exit_status) { should eq 0 }
end

describe service('puppetserver') do
  it { should be_running }
end

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

describe command('curl --silent --cacert "/etc/puppet/puppetserver/ca/ca_crt.pem" "https://$(hostname):8140/status/v1/simple"') do
  its(:exit_status) { should eq 0 }
  its(:stdout) { should eq 'running' }
end

describe command('puppet resource host puppet ip=127.0.81.40') do
  its(:exit_status) { should eq 0 }
end


describe command('puppet agent --test') do
  its(:exit_status) { should eq 0 }
  its(:stdout) { should contain('Notice: Applied catalog') }
end
