From d82f104e10db3a130e85ec3f383af98694885b26 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Sun, 24 Nov 2019 23:27:21 +0100 Subject: [PATCH] [kitchen] initial confirmation with some service and socket tests --- .gitignore | 3 +++ README.md | 21 +++++++++++++++++++++ bootstrap.sh | 1 + kitchen.yml | 24 ++++++++++++++++++++++++ tests/test_metronome.py | 11 +++++++++++ tests/test_nginx.py | 9 +++++++++ tests/test_rspamd.py | 10 ++++++++++ tests/test_slapd.py | 8 ++++++++ tests/test_ssh.py | 8 ++++++++ tests/test_yunohost_api.py | 8 ++++++++ 10 files changed, 103 insertions(+) create mode 100644 bootstrap.sh create mode 100644 kitchen.yml create mode 100644 tests/test_metronome.py create mode 100644 tests/test_nginx.py create mode 100644 tests/test_rspamd.py create mode 100644 tests/test_slapd.py create mode 100644 tests/test_ssh.py create mode 100644 tests/test_yunohost_api.py diff --git a/.gitignore b/.gitignore index 6a73b99..15acd81 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ *.save *.autosav *.autosave +junit-*.xml +.kitchen +tests/__pycache__/ diff --git a/README.md b/README.md index 99513a7..61a784b 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,27 @@ The [post-installation](https://yunohost.org/#/postinstall) will need to be perf The ```-d ``` switch is mostly for advanced users who want to install the bleeding edge versions of YunoHost packages. +## Test with Kitchen + +To launch tests and an development environment : + +* install VirtualBox https://www.virtualbox.org/ +* install Vagrant https://www.vagrantup.com/ +* install Kitchen https://kitchen.ci/ +* install testinfra with paramiko https://testinfra.readthedocs.io/ + +Run : + +``` +kitchen test +``` + +To login to your environment : + +``` +kitchen login +``` + ## Issues, Feedback Please report issues here : https://github.com/YunoHost/issues/issues diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 0000000..6f720fd --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1 @@ +cd /vagrant && bash install_yunohost -a diff --git a/kitchen.yml b/kitchen.yml new file mode 100644 index 0000000..0aa3a00 --- /dev/null +++ b/kitchen.yml @@ -0,0 +1,24 @@ +--- +driver: + name: vagrant + synced_folders: + - [".", "/vagrant"] + network: + - ["forwarded_port", {guest: 80, host: 8080}] + - ["forwarded_port", {guest: 443, host: 8443}] + +provisioner: + name: shell + +verifier: + name: inspec + +platforms: + - name: debian/buster64 + +suites: + - name: default + +verifier: + name: shell + command: py.test --hosts="paramiko://${KITCHEN_USERNAME}@${KITCHEN_HOSTNAME}:${KITCHEN_PORT}?ssh_identity_file=${KITCHEN_SSH_KEY}" --junit-xml "junit-${KITCHEN_INSTANCE}.xml" "tests/" diff --git a/tests/test_metronome.py b/tests/test_metronome.py new file mode 100644 index 0000000..177d864 --- /dev/null +++ b/tests/test_metronome.py @@ -0,0 +1,11 @@ + +def test_metronome_running_and_enabled(host): + metronome = host.service("metronome") + assert metronome.is_running + assert metronome.is_enabled + +def test_metronome_sockets(host): + # FIXME TODO - no ipv6 ? + assert host.socket("tcp://0.0.0.0:5222").is_listening + assert host.socket("tcp://0.0.0.0:5269").is_listening + diff --git a/tests/test_nginx.py b/tests/test_nginx.py new file mode 100644 index 0000000..d6216be --- /dev/null +++ b/tests/test_nginx.py @@ -0,0 +1,9 @@ + +def test_nginx_running_and_enabled(host): + nginx = host.service("nginx") + assert nginx.is_running + assert nginx.is_enabled + +def test_nginx_sockets(host): + assert host.socket("tcp://80").is_listening + assert host.socket("tcp://443").is_listening diff --git a/tests/test_rspamd.py b/tests/test_rspamd.py new file mode 100644 index 0000000..82e42fd --- /dev/null +++ b/tests/test_rspamd.py @@ -0,0 +1,10 @@ + +def test_rspamd_running_and_enabled(host): + rspamd = host.service("rspamd") + assert rspamd.is_running + assert rspamd.is_enabled + +def test_rspamd_sockets(host): + assert host.socket("tcp://127.0.0.1:11332").is_listening + assert host.socket("tcp://127.0.0.1:11333").is_listening + assert host.socket("tcp://127.0.0.1:11334").is_listening diff --git a/tests/test_slapd.py b/tests/test_slapd.py new file mode 100644 index 0000000..dc17981 --- /dev/null +++ b/tests/test_slapd.py @@ -0,0 +1,8 @@ + +def test_slapd_running_and_enabled(host): + ldap = host.service("slapd") + assert ldap.is_running + assert ldap.is_enabled + +def test_slapd_sockets(host): + assert host.socket("tcp://636").is_listening diff --git a/tests/test_ssh.py b/tests/test_ssh.py new file mode 100644 index 0000000..c15ae09 --- /dev/null +++ b/tests/test_ssh.py @@ -0,0 +1,8 @@ + +def test_ssh_running_and_enabled(host): + ssh = host.service("ssh") + assert ssh.is_running + assert ssh.is_enabled + +def test_ssh_sockets(host): + assert host.socket("tcp://22").is_listening diff --git a/tests/test_yunohost_api.py b/tests/test_yunohost_api.py new file mode 100644 index 0000000..12f2ade --- /dev/null +++ b/tests/test_yunohost_api.py @@ -0,0 +1,8 @@ + +def test_yunohost_api_running_and_enabled(host): + yunohost_api = host.service("yunohost-api") + assert yunohost_api.is_running + assert yunohost_api.is_enabled + +def test_yunohost_api_sockets(host): + assert host.socket("tcp://127.0.0.1:6787").is_listening