]> git.ipfire.org Git - thirdparty/suricata-update.git/commitdiff
test: centos 7 based docker live test
authorJason Ish <ish@unx.ca>
Wed, 6 Dec 2017 20:09:40 +0000 (14:09 -0600)
committerJason Ish <ish@unx.ca>
Thu, 7 Dec 2017 22:01:31 +0000 (16:01 -0600)
This is a test that runs in a Docker image. It installs
suricata-update and executes a sequence of commands looking for
failures.

The test sequence is done with Python 2 and Python 3 as provided
in CentOS 7.

tests/docker-centos-7/Dockerfile [new file with mode: 0644]
tests/docker-centos-7/Makefile [new file with mode: 0644]
tests/docker-centos-7/README.md [new file with mode: 0644]
tests/docker-centos-7/run.sh [new file with mode: 0755]

diff --git a/tests/docker-centos-7/Dockerfile b/tests/docker-centos-7/Dockerfile
new file mode 100644 (file)
index 0000000..fdf1814
--- /dev/null
@@ -0,0 +1,25 @@
+FROM centos:7
+
+RUN yum -y install epel-release
+RUN yum -y install \
+    git \
+    python-yaml \
+    python-pip \
+    pytest \
+    python34-yaml \
+    python34-pytest \
+    python34-pip \
+    findutils
+
+COPY / /src
+RUN find /src -name \*.pyc -delete
+
+ENV PYTEST2 py.test
+ENV PYTEST3 py.test-3
+
+ENV PIP2 pip2
+ENV PIP3 pip3
+
+WORKDIR /src
+
+CMD ["./tests/docker-centos-7/run.sh"]
diff --git a/tests/docker-centos-7/Makefile b/tests/docker-centos-7/Makefile
new file mode 100644 (file)
index 0000000..619f3f2
--- /dev/null
@@ -0,0 +1,6 @@
+TAG := suricata-update/tests/centos-7
+
+all:
+       docker build -t $(TAG) -f Dockerfile ../..
+       docker run --rm -it $(TAG)
+
diff --git a/tests/docker-centos-7/README.md b/tests/docker-centos-7/README.md
new file mode 100644 (file)
index 0000000..c0b6664
--- /dev/null
@@ -0,0 +1,11 @@
+This is a live test of Suricata-Update in a CentOS 7 Docker image.
+
+The following tests are performed:
+- Unit tests with Python 2 and Python 3.
+- Installation with Python 2 pip.
+- Various commands run as a user might with Python 2 install.
+- Installation with Python 3 pip.
+- Various commands run as a user might with Python 3 install.
+
+This test is "live" as the index and rule files will be downloaded
+from the internet.
diff --git a/tests/docker-centos-7/run.sh b/tests/docker-centos-7/run.sh
new file mode 100755 (executable)
index 0000000..c4599b8
--- /dev/null
@@ -0,0 +1,54 @@
+#! /bin/sh
+
+set -e
+set -x
+
+# Test the commands in a scenario a user might.
+test_commands() {
+    # Cleanup.
+    rm -rf /var/lib/suricata
+
+    suricata-update
+    test -e /var/lib/suricata/rules/suricata.rules
+
+    suricata-update update-sources
+    test -e /var/lib/suricata/rules/.cache/index.yaml
+
+    suricata-update enable-source oisf/trafficid
+    test -e /var/lib/suricata/update/sources/et-open.yaml
+    test -e /var/lib/suricata/update/sources/oisf-trafficid.yaml
+    suricata-update
+
+    suricata-update disable-source oisf/trafficid
+    test ! -e /var/lib/suricata/update/sources/oisf-trafficid.yaml
+    test -e /var/lib/suricata/update/sources/oisf-trafficid.yaml.disabled
+
+    suricata-update remove-source oisf/trafficid
+    test ! -e /var/lib/suricata/update/sources/oisf-trafficid.yaml.disabled
+}
+
+# Python 2 unit tests.
+PYTHONPATH=. ${PYTEST2}
+
+# Python 3 unit tests.
+PYTHONPATH=. ${PYTEST3}
+
+# Install with Python 2.
+${PIP2} install .
+test -e /usr/bin/suricata-update
+
+test_commands
+
+# Uninstall Python 2 version.
+${PIP2} uninstall --yes suricata-update
+test ! -e /usr/bin/suricata-update
+
+# Install and run with Python 3.
+${PIP3} install .
+test -e /usr/bin/suricata-update
+grep python3 -s /usr/bin/suricata-update
+
+test_commands
+
+${PIP3} uninstall --yes suricata-update
+test ! -e /usr/local/bin/suricata-update