Commit 9c682486 authored by Aleksandr Guljajev's avatar Aleksandr Guljajev

Added proper TAG support. Minor test updates

parent ff3ac664
import argparse
import sys
import unittest
import os
from util.Api import Api
from time import sleep
......@@ -39,7 +40,11 @@ class CartContainerTest(unittest.TestCase):
limit = limit - 1
sleep(1)
out = Dredd().test_against_endpoint("cart", "http://cart/", links=[self.mongo_container_name, self.container_name], env=[("MONGO_ENDPOINT", "mongodb://cart-db:27017/data")])
out = Dredd().test_against_endpoint(
"cart", "http://cart/",
links=[self.mongo_container_name, self.container_name],
env=[("MONGO_ENDPOINT", "mongodb://cart-db:27017/data")],
dump_streams=True)
self.assertGreater(out.find("0 failing"), -1)
self.assertGreater(out.find("0 errors"), -1)
print(out)
......@@ -50,6 +55,12 @@ if __name__ == '__main__':
parser.add_argument('unittest_args', nargs='*')
args = parser.parse_args()
CartContainerTest.TAG = args.tag
try:
CartContainerTest.TAG = os.environ["TAG"]
except KeyError as e:
pass
# Now set the sys.argv to the unittest_args (leaving sys.argv[0] alone)
sys.argv[1:] = args.unittest_args
unittest.main()
......@@ -30,5 +30,6 @@ $DOCKER_CMD run \
-e TRAVIS_BRANCH=$TRAVIS_BRANCH \
-e TRAVIS_PULL_REQUEST=$TRAVIS_PULL_REQUEST \
-e TRAVIS=$TRAVIS \
-e TAG=$TAG \
test-container \
sh -c "export PYTHONPATH=\$PYTHONPATH:\$PWD/test ; python test/$@"
......@@ -6,7 +6,12 @@ from random import random
class Docker:
def kill_and_remove(self, ctr_name):
command = ['docker', 'rm', '-f', ctr_name]
self.execute(command)
try:
self.execute(command)
return True
except RuntimeError as e:
print(e)
return False
def random_container_name(self, prefix):
retstr = prefix + '-'
......@@ -20,17 +25,17 @@ class Docker:
ctr_name]
return re.sub(r'[^0-9.]*', '', self.execute(command))
def execute(self, command):
def execute(self, command, dump_streams=False):
print("Running: " + ' '.join(command))
p = Popen(command, stdout=PIPE, stderr=PIPE)
p.wait()
out = p.stdout.read()
stderr = p.stderr.read()
if p.wait() != 0:
p.stdout.close()
p.stderr.close()
raise RuntimeError(str(stderr.decode('utf-8')))
err = p.stderr.read()
p.stdout.close()
p.stderr.close()
if dump_streams == True:
print(out.decode('utf-8'))
print(err.decode('utf-8'))
return str(out.decode('utf-8'))
def start_container(self, container_name="", image="", cmd="", host=""):
......
......@@ -4,9 +4,9 @@ import os
import unittest
class Dredd:
image = 'weaveworksdemos/openapi:d18f10abf792775b21b1ac555c7c83dbec40119f'
image = 'weaveworksdemos/openapi'
container_name = ''
def test_against_endpoint(self, service, api_endpoint, links=[], env=[]):
def test_against_endpoint(self, service, api_endpoint, links=[], env=[], dump_streams=False):
self.container_name = Docker().random_container_name('openapi')
command = ['docker', 'run',
'-h', 'openapi',
......@@ -24,7 +24,7 @@ class Dredd:
api_endpoint,
"-f",
"/tmp/specs/hooks.js".format(service)])
out = Docker().execute(command)
out = Docker().execute(command, dump_streams=dump_streams)
Docker().kill_and_remove(self.container_name)
return out
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment