Skip to content

Commit

Permalink
started integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Yakubov committed Jan 3, 2017
1 parent 5cf5b0d commit e0a127c
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 6 deletions.
1 change: 1 addition & 0 deletions Tests/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./ps/empty_database
Empty file added Tests/include
Empty file.
4 changes: 4 additions & 0 deletions Tests/ps/empty_database/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exit_code: 0
output:
string: ''
exactly: true
4 changes: 4 additions & 0 deletions Tests/ps/empty_database/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

restart_db.sh

3 changes: 3 additions & 0 deletions Tests/ps/empty_database/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

dcomp ps
4 changes: 4 additions & 0 deletions Tests/ps/help/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exit_code: 0
output:
file: output_orig
exactly: false
13 changes: 13 additions & 0 deletions Tests/ps/help/output_orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Usage:
dcomp ps [OPTIONS]

Show job information
-a Show all jobs includng finished
-compress
get log file compressed
-help
Print usage
-id string
Job Id
-log
Get log file for a specified job
4 changes: 4 additions & 0 deletions Tests/ps/help/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

dcomp ps --help

104 changes: 104 additions & 0 deletions Tests/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/python

import os
import subprocess
from subprocess import Popen, PIPE

import yaml

DEVNULL = open(os.devnull, 'wb')

class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'

failed=[]
include=[]
exclude=[]

try:
with open("./include", 'r') as f:
include=f.read().splitlines()
except:
pass

try:
with open("./exclude", 'r') as f:
exclude=f.read().splitlines()
except:
pass



def check_test(path,fname,exit_code,output):
fullname = os.path.join(dirpath,fname)
with open(fullname, 'r') as stream:
struct=yaml.load(stream)

if struct['exit_code'] != exit_code:
return False

exactly=True
if 'exactly' in struct['output']:
exactly=struct['output']['exactly']

data=""
if 'string' in struct['output']:
data=struct['output']['string']
elif 'file' in struct['output']:
fullname = os.path.join(dirpath,struct['output']['file'])
with open(fullname, 'r') as myfile:
data=myfile.read()

data=data.lower().replace(" ", "").replace('\n','')
output=output.lower().replace(" ", "").replace('\n','')

if exactly:
ok = data == output
else:
ok = output in data or data in output

return ok

for dirpath, dirs, files in os.walk("."):
if dirpath in exclude:
continue
if len(include)>0 and dirpath not in include:
continue


if "run.sh" in files:
print "Testing " + dirpath + "...",
if "init.sh" in files:
fname = os.path.join(dirpath,"init.sh")
subprocess.call([fname],stdout=DEVNULL)
fname = os.path.join(dirpath,"run.sh")

p = Popen([fname], stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT)
output, err = p.communicate()
exit_code = p.returncode

result=check_test(dirpath,"check.yaml",exit_code,output)
if "cleanup.sh" in files:
fname = os.path.join(dirpath,"cleanup.sh")
subprocess.call([fname])
if result:
print bcolors.OKGREEN + "OK" + bcolors.ENDC
else:
print bcolors.FAIL + "FAIL" + bcolors.ENDC
failed.append(dirpath)

if len(failed)>0:
print bcolors.FAIL + "FAILED:" + bcolors.ENDC
for failure in failed:
print bcolors.FAIL + failure + bcolors.ENDC
exit(1)
else:
print bcolors.OKGREEN + "ALL OK" + bcolors.ENDC
exit(0)
4 changes: 4 additions & 0 deletions scripts/restart_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
stop_db.sh
start_db.sh

6 changes: 0 additions & 6 deletions scripts/start_db.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
#docker network create --subnet=172.18.0.0/16 mynet
#docker run --net mynet --ip 172.18.0.2 --name mongodb -p 27017:27017 -d mongo
docker run --name mongodb -p 27017:27017 -d mongo
#docker run --net mynet --ip 172.18.0.3 --name dcompd -P -d yakser/dcompd
#docker run --net mynet --ip 172.18.0.4 --name dcompestd -P -d yakser/dcompestd
#docker run --net mynet --ip 172.18.0.5 --name dcompauthd -P -d yakser/dcompauthd
#docker run --net mynet --ip 172.18.0.6 --name dcompdmd -P -v /dcompdata:/dcompdata -d yakser/dcompdmd

0 comments on commit e0a127c

Please sign in to comment.