Skip to content

Instantly share code, notes, and snippets.

@pgporada
Created February 21, 2017 04:06
Show Gist options
  • Save pgporada/c753a4fe75038cc07f77f3a00cd3d565 to your computer and use it in GitHub Desktop.
Save pgporada/c753a4fe75038cc07f77f3a00cd3d565 to your computer and use it in GitHub Desktop.
Testing examples
#!/usr/bin/env bats
@test "Kibana is installed" {
run rpm -q kibana
[ "$status" -eq 0 ]
}
@test "Kibana is running" {
run systemctl is-active kibana
[ "$status" -eq 0 ]
}
@test "Kibana is listening on 127.0.0.1:5601" {
run curl -ILk 127.0.0.1:5601
[ "$status" -eq 0 ]
}
@test "Kibana default port 5601 is set as an http port for httpd proxying" {
set -o pipefail
run bash -c "semanage port -l | grep '^http_port_t' | grep 5601"
set +o pipefail
[ "$status" -eq 0 ]
}
require 'spec_helper'
describe 'dnsmasq' do
describe service('dnsmasq') do
it { should_not be_enabled }
it { should_not be_running }
end
end
==> test_packages.py <==
import pytest
@pytest.mark.parametrize("name", [
("stunnel"),
("redis"),
("policycoreutils-python")
])
def test_packages_are_installed(Package, name):
assert Package(name).is_installed
==> test_redis_client.py <==
testinfra_hosts = ["centos-7-stunnel-1"]
def test_runs_only_on_server_(Command):
assert Command('hostname -s').stdout == 'centos-7-stunnel-1'
def test_redis_stopped_and_disabled(Service):
redis = Service("redis")
assert redis.is_enabled is False
==> test_redis_server.py <==
testinfra_hosts = ["centos-7-stunnel-2"]
def test_runs_only_on_server_(Command):
assert Command('hostname -s').stdout == 'centos-7-stunnel-2'
def test_redis_running_and_enabled(Service):
redis = Service("redis")
assert redis.is_running
==> test_stunnel.py <==
def test_stunnel_running_and_enabled(Service):
stunnel = Service("stunnel")
assert stunnel.is_running
assert stunnel.is_enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment