* migrate to Docker * tests/test_check.py: use junitxml * bin/generate_tests.sh: support DEST_DIR will use DEST_DIR as base dir destination * rename scenarios_disabled -> disabled * fix \t at XXXX_test.yml.tt2 templates Change-Id: I845588ee4692f157f370a000abab75a05e701839changes/31/9331/6
parent
561070ce1c
commit
97c350026e
@ -1,27 +1,23 @@
|
||||
SCENARIOS:=$(shell find -maxdepth 1 -type d -name 'scenarios*'|sed 's_\./__g')
|
||||
TESTS=$(addprefix test_,$(SCENARIOS))
|
||||
|
||||
RESULTS ?= reports
|
||||
|
||||
# do nothing as default
|
||||
all:
|
||||
|
||||
.ONESHELL:
|
||||
SHELL = /bin/bash
|
||||
venv: requirements.txt
|
||||
virtualenv --python=python2.7 venv
|
||||
source ./venv/bin/activate && \
|
||||
pip install -r ./requirements.txt >install.log
|
||||
# python-junitxml 0.6 has this bug
|
||||
# https://bugs.launchpad.net/pyjunitxml/+bug/892293
|
||||
$(TESTS):
|
||||
@mkdir -p $(RESULTS)
|
||||
$(eval SCEN_DIR := $(@:test_%=%))
|
||||
./tests/do_test_yaml_format.sh $(SCEN_DIR)
|
||||
|
||||
test_check: venv tests/test_check.py
|
||||
mkdir -p reports
|
||||
source ./venv/bin/activate && \
|
||||
./tests/test_check.py > reports/$(@).xml
|
||||
test_check: tests/test_check.py
|
||||
mkdir -p $(RESULTS)
|
||||
./tests/test_check.py > $(RESULTS)/$(@).xml
|
||||
|
||||
# run this in parallel!! -j is your friend
|
||||
test: test_check
|
||||
|
||||
# get rid of test files
|
||||
clean:
|
||||
rm -rf install.log
|
||||
|
||||
# also get rid of pip environment
|
||||
dist-clean: clean
|
||||
rm -rf venv
|
||||
test: $(TESTS) test_check
|
||||
|
||||
.PHONY: all
|
||||
.PHONY: all $(TESTS)
|
||||
|
@ -1,2 +0,0 @@
|
||||
unittest-xml-reporting
|
||||
pyaml
|
@ -0,0 +1,32 @@
|
||||
# DOCKER_NAME=kamailio-config-tests-jessie
|
||||
FROM docker.mgm.sipwise.com/sipwise-jessie:latest
|
||||
|
||||
# Important! Update this no-op ENV variable when this Dockerfile
|
||||
# is updated with the current date. It will force refresh of all
|
||||
# of the base images and things like `apt-get update` won't be using
|
||||
# old cached versions when the Dockerfile is built.
|
||||
ENV REFRESHED_AT 2016-11-04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install --assume-yes python-yaml python-junitxml \
|
||||
make libtemplate-perl libyaml-perl
|
||||
|
||||
RUN echo './t/testrunner' >>/root/.bash_history
|
||||
|
||||
WORKDIR /code/
|
||||
|
||||
################################################################################
|
||||
# Instructions for usage
|
||||
# ----------------------
|
||||
# When you want to build the base image from scratch (jump to the next section if you don't want to build yourself!):
|
||||
# % docker build --tag="kamailio-config-tests-jessie" .
|
||||
# % docker run --rm -i -t -v $(pwd)/..:/code:rw kamailio-config-tests-jessie:latest bash
|
||||
#
|
||||
# Use the existing docker image:
|
||||
# % docker pull docker.mgm.sipwise.com/kamailio-config-tests-jessie
|
||||
# % docker run --rm -i -t -v $(pwd)/:/code:rw docker.mgm.sipwise.com/kamailio-config-tests-jessie:latest bash
|
||||
#
|
||||
# Inside docker (the command is in history, just press UP button):
|
||||
# ./t/testrunner
|
||||
#
|
||||
################################################################################
|
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# This script is used for running the tests with proper arguments
|
||||
# from within Jenkins
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
if [ -d /results ] ; then
|
||||
# Running from Jenkins (RW)
|
||||
RESULTS="/results"
|
||||
|
||||
cd "/code"
|
||||
else
|
||||
# Running locally in Docker
|
||||
RESULTS="./results"
|
||||
mkdir -p "${RESULTS}"
|
||||
fi
|
||||
|
||||
RESULTS=${RESULTS} make -j test
|
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
export BASE_DIR=$(pwd) DEST_DIR=${RESULTS}
|
||||
|
||||
./bin/generate_tests.sh -d "$1" tests/fixtures/scenario_ids.yml PRO
|
||||
find "${RESULTS}/$1" -type f -name '*_test.yml' | while read -r i; do
|
||||
./tests/test_yaml_format.py "$i" | sed -e 's/skip>/skipped>/g' > "$i.xml"
|
||||
done
|
||||
|
||||
# exclude templates
|
||||
rm -rf "${RESULTS}/$1/templates"
|
@ -0,0 +1,14 @@
|
||||
---
|
||||
customer_test:
|
||||
id: 7
|
||||
peer_00_host0:
|
||||
id: 31
|
||||
peer_00_host1:
|
||||
id: 32
|
||||
spce_test:
|
||||
testuser1001:
|
||||
uuid: UUID1001
|
||||
testuser1002:
|
||||
uuid: UUID1002
|
||||
testuser1003:
|
||||
uuid: UUID1003
|
@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright: 2013-2015 Sipwise Development Team <support@sipwise.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This package is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# On Debian systems, the complete text of the GNU General
|
||||
# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||
#
|
||||
from yaml import load
|
||||
import junitxml
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
import fnmatch
|
||||
try:
|
||||
from yaml import CLoader as Loader
|
||||
except ImportError:
|
||||
from yaml import Loader
|
||||
|
||||
|
||||
class ParametrizedTestCase(unittest.TestCase):
|
||||
|
||||
""" TestCase classes that want to be parametrized should
|
||||
inherit from this class.
|
||||
http://eli.thegreenplace.net/
|
||||
2011/08/02/python-unit-testing-parametrized-test-cases
|
||||
"""
|
||||
|
||||
def __init__(self, methodName='runTest', param=None):
|
||||
super(ParametrizedTestCase, self).__init__(methodName)
|
||||
self.param = param
|
||||
self.scenario = os.path.dirname(self.param)
|
||||
|
||||
def id(self):
|
||||
return "%s_%s" % (super(ParametrizedTestCase, self).id(),
|
||||
self.scenario)
|
||||
|
||||
@staticmethod
|
||||
def parametrize(testcase_klass, param=None):
|
||||
""" Create a suite containing all tests taken from the given
|
||||
subclass, passing them the parameter 'param'.
|
||||
"""
|
||||
testloader = unittest.TestLoader()
|
||||
testnames = testloader.getTestCaseNames(testcase_klass)
|
||||
suite = unittest.TestSuite()
|
||||
for name in testnames:
|
||||
suite.addTest(testcase_klass(name, param=param))
|
||||
return suite
|
||||
|
||||
|
||||
class TestYmlLint(ParametrizedTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.yaml = load(file(self.param, 'r'))
|
||||
|
||||
def testFlow(self):
|
||||
self.assertTrue('flow' in self.yaml)
|
||||
self.assertIsInstance(self.yaml['flow'], list)
|
||||
|
||||
def testSipIn(self):
|
||||
self.assertTrue('sip_in' in self.yaml)
|
||||
self.assertIsInstance(self.yaml['sip_in'], list)
|
||||
|
||||
def testSipOut(self):
|
||||
self.assertTrue('sip_out' in self.yaml)
|
||||
self.assertIsInstance(self.yaml['sip_out'], list)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert len(sys.argv) == 2
|
||||
assert os.path.exists(sys.argv[1])
|
||||
suite = unittest.TestSuite()
|
||||
suite.addTest(
|
||||
ParametrizedTestCase.parametrize(TestYmlLint,
|
||||
param=sys.argv[1]))
|
||||
result = junitxml.JUnitXmlResult(sys.stdout)
|
||||
result.startTestRun()
|
||||
suite.run(result)
|
||||
result.stopTestRun()
|
Loading…
Reference in new issue