Skip to content

Instantly share code, notes, and snippets.

@anokun7
Created January 9, 2015 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anokun7/12e80d8fb41e513bf590 to your computer and use it in GitHub Desktop.
Save anokun7/12e80d8fb41e513bf590 to your computer and use it in GitHub Desktop.
Beaker Demo - Write your own tests (Anoop Kumar's submission)
require 'spec_helper_acceptance'
describe "file content tests" do
step "Create file with content"
hosts.each do |host|
# confine :except, :platform => 'windows'
content = "foo\nfoo\nfoo\n"
the_file = "/tmp/demo.txt"
create_remote_file host, the_file, content
# describe file(#{the_file}) do
# its(:content) { should match /foo/ }
# end
on(host, "grep foo #{the_file}") { assert_equal(0, exit_code) }
result = on(host, "grep bar #{the_file}") { assert_equal(1, exit_code) }
result.stdout.strip
end
end
require 'spec_helper_acceptance'
describe "Apply Manifest Verification" do
step "Apply manifests"
hosts.each do |host|
manifest = "user {'foo': ensure => present,}"
apply_manifest manifest, {:expect_changes => true}
manifest = "user {'foo': ensure => absent,}"
apply_manifest manifest, {:expect_changes => true}
manifest = "user {'root': ensure => present,}"
# root user is always present, so we do not expect changes
apply_manifest manifest, {:expect_changes => false}
end
end
require 'spec_helper_acceptance'
describe "Verify file contents" do
step "Apply manifest"
hosts.each do |host|
the_file = '/tmp/demo.txt'
the_content = 'This is my file'
manifest = "file { '#{the_file}': ensure => file, content => '#{the_content}' }"
apply_manifest manifest, { :catch_failures => true }
describe file("#{the_file}") do
it { should be_file }
end
describe file("#{the_file}") do
it { should contain "#{the_content}" }
end
end
end
require 'spec_helper_acceptance'
describe "Verify sshd is running" do
describe service('sshd') do
it { should be_running }
end
end
require 'spec_helper_acceptance'
describe "Verify users" do
describe user('root') do
it { should exist }
end
describe user('foo') do
it { should_not exist }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment