Skip to content

Commit

Permalink
testinfra (#44): improved tests and draft of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Dec 27, 2019
1 parent faf5a3e commit a5f60ce
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 49 deletions.
54 changes: 26 additions & 28 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,40 @@ def test_hosts_file(host):

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert f.group == 'root' or f.group == 'wheel'


def test_haproxy_is_installed_and_running(host):
haproxy = host.package("haproxy")
def test_haproxy_is_installed(host):
assert host.package("haproxy").is_installed

assert haproxy.is_installed
# assert haproxy.is_running
# Error: E AttributeError: 'DebianPackage' object has no attribute
# 'is_running'

def test_haproxy_is_enabled(host):
assert host.service("haproxy").is_enabled

def test_openresty_is_installed_and_running(host):
openresty = host.package("openresty")

assert openresty.is_installed
# assert openresty.is_running
# Error: E AttributeError: 'DebianPackage' object has no attribute
# 'is_running'
def test_haproxy_is_running(host):
assert host.service("haproxy").is_running

# From https://testinfra.readthedocs.io/en/latest/#quick-start
# def test_passwd_file(host):
# passwd = host.file("/etc/passwd")
# assert passwd.contains("root")
# assert passwd.user == "root"
# assert passwd.group == "root"
# assert passwd.mode == 0o644

def test_openresty_is_installed(host):
assert host.package("openresty").is_installed


def test_openresty_is_enabled(host):
assert host.service("openresty").is_enabled


def test_openresty_is_running(host):
assert host.service("openresty").is_running


#def test_ufw_is_installed(host):
# assert host.package("ufw").is_installed
#
#
# def test_nginx_is_installed(host):
# nginx = host.package("nginx")
# assert nginx.is_installed
# assert nginx.version.startswith("1.2")
#def test_ufw_is_enabled(host):
# assert host.service("ufw").is_enabled
#
#
# def test_nginx_running_and_enabled(host):
# nginx = host.service("nginx")
# assert nginx.is_running
# assert nginx.is_enabled
#def test_ufw_is_running(host):
# assert host.service("ufw").is_running
18 changes: 18 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# AP-ALB tests

The files on directory `ap-application-load-balancer/tests` by default will be
be sincronized and be avalible on each host ALB node `/opt/alb/bin/tests/`.

Note, the tests will NOT be installed if a node is not installed as `alb-standard`
e.g. is installed as `alb-minimal` since `alb-minimal` do not create `/opt/alb/`
folder structure.

```bash
py.test ad-hoc-alb-tests/test_alb-standard-node.py --hosts='ansible://all'
py.test tests/test_alb-standard-node.py --ssh-identity-file="~/.ssh/id_rsa-rocha" --hosts="root@aguia-pescadora-foxtrot.etica.ai"
```


## How to run

### Extra backends
- <https://testinfra.readthedocs.io/en/latest/backends.html>
46 changes: 25 additions & 21 deletions tests/test_alb-standard-node.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
# FILE: /opt/alb/bin/tests/test_alb-standard-node.py

def test_passwd_file(host):
passwd = host.file("/etc/passwd")
assert passwd.contains("root")
assert passwd.user == "root"
assert passwd.group == "root"
assert passwd.mode == 0o644
def test_haproxy_is_installed(host):
assert host.package("haproxy").is_installed


def test_haproxy_is_enabled(host):
assert host.service("haproxy").is_enabled


def test_haproxy_is_running(host):
assert host.service("haproxy").is_running


def test_openresty_is_installed(host):
nginx = host.package("openresty")
assert nginx.is_installed
# assert nginx.version.startswith("1.2")
assert host.package("openresty").is_installed


def test_openresty_running_and_enabled(host):
nginx = host.service("openresty")
assert nginx.is_running
assert nginx.is_enabled
def test_openresty_is_enabled(host):
assert host.service("openresty").is_enabled


def test_haproxy_is_installed(host):
nginx = host.package("haproxy")
assert nginx.is_installed
# assert nginx.version.startswith("1.2")
def test_openresty_is_running(host):
assert host.service("openresty").is_running


def test_ufw_is_installed(host):
assert host.package("ufw").is_installed


def test_ufw_is_enabled(host):
assert host.service("ufw").is_enabled


def test_haproxy_running_and_enabled(host):
nginx = host.service("haproxy")
assert nginx.is_running
assert nginx.is_enabled
def test_ufw_is_running(host):
assert host.service("ufw").is_running

0 comments on commit a5f60ce

Please sign in to comment.