Skip to content

Commit

Permalink
Merge pull request #20 from digitronik/start_stop_test
Browse files Browse the repository at this point in the history
Start stop test
  • Loading branch information
digitronik authored Apr 19, 2019
2 parents 61a89a7 + f55621b commit d3eb833
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 19 deletions.
18 changes: 18 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import subprocess


def miqsel_cmd(cmd):
"""
Runs a miqsel shell command, and returns the output, err, returncode
"""
ret = subprocess.Popen(
cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
)
out, err = ret.communicate()
returncode = ret.returncode
return out.decode(), err.decode(), returncode
17 changes: 16 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

import pytest
from tests import miqsel_cmd


@pytest.fixture(scope="module")
Expand All @@ -16,3 +17,17 @@ def config():
yield
if os.path.isdir("conf"):
os.rmdir("conf")


@pytest.fixture(scope="module")
def ensure_stopped(config):
out, _, _ = miqsel_cmd("miqsel status")
if out.strip() == "running":
miqsel_cmd("miqsel stop")


@pytest.fixture(scope="module")
def ensure_running(config):
out, _, _ = miqsel_cmd("miqsel status")
if out.strip() != "running":
miqsel_cmd("miqsel start")
18 changes: 18 additions & 0 deletions tests/test_miqsel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from tests import miqsel_cmd


def test_miqsel_start(ensure_stopped):
"""Check start of miqsel"""

out, err, returncode = miqsel_cmd("miqsel start")
assert "miq_sel container started" in out
out, err, returncode = miqsel_cmd("miqsel status")
assert out.strip() == "running"


def test_miqsel_stop(ensure_running):
"""Check stop of miqsel"""

miqsel_cmd("miqsel stop")
out, _, _ = miqsel_cmd("miqsel status")
assert out.strip() == "Not running..."
20 changes: 2 additions & 18 deletions tests/test_status.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
import os
import subprocess


def miqsel_cmd(cmd):
"""
Runs a miqsel shell command, and returns the output, err, returncode
"""
ret = subprocess.Popen(
cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
)
out, err = ret.communicate()
returncode = ret.returncode
return out.decode(), err.decode(), returncode
from tests import miqsel_cmd


def test_miqsel_help():
Expand All @@ -37,7 +21,7 @@ def test_miqsel_unconfigured():
)


def test_miqsel_configured(config):
def test_miqsel_configured(ensure_stopped):
out, err, returncode = miqsel_cmd("miqsel status")
assert returncode == 0
assert out.strip() == "Not running..."

0 comments on commit d3eb833

Please sign in to comment.