Skip to content

Commit

Permalink
Merge pull request #6 from dockstore-testing/develop
Browse files Browse the repository at this point in the history
Merge to master
  • Loading branch information
garyluu authored Sep 11, 2019
2 parents 0ab8667 + 728a681 commit f7927a5
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 30 deletions.
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
sudo: required

services:
- docker

language: python

python:
- "3.6"

before_install:
# Download Cromwell
- wget -O $TRAVIS_BUILD_DIR/cromwell-42.jar https://github.com/broadinstitute/cromwell/releases/download/42/cromwell-42.jar;
- curl -o requirements.txt "https://dockstore.org/api/metadata/runner_dependencies?client_version=1.6.0&python_version=3"

install:
- pip install -r requirements.txt

script:
- docker build -t test-image -f checker/Dockerfile checker
- >-
sed 's/dockerPull:.*/dockerPull: test-image:latest/g' checker/md5sum-checker.cwl
- >-
sed 's/docker:.*/docker: "test-image:latest"/g' checker/md5sum-checker.wdl
- python -m unittest discover -s .
7 changes: 7 additions & 0 deletions checker-fail-cwl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"input_file": {
"class": "File",
"path": "md5sum.input"
},
"expected_md5": "not a matching md5sum"
}
54 changes: 28 additions & 26 deletions checker/bin/check_md5sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,41 @@ import json
import sys
import os


def main():
parser = argparse.ArgumentParser(description='Checks to see if a given file contains a certain string and then returns a JSON.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input-file', type=str, help='file input')
parser.add_argument('--md5', type=str, help='expected md5')
args = parser.parse_args()
parser = argparse.ArgumentParser(description='Checks to see if a given file contains a certain string and then returns a JSON.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input-file', type=str, help='file input')
parser.add_argument('--md5', type=str, help='expected md5')
args = parser.parse_args()

result_code = check_file(args.input_file, args.md5)

result = check_file(args.input_file, args.md5)
results_file = open("results.json", "w")
if result_code == 0:
results_file.write('{ "overall" : true, "steps" : { "md5sum_check" : true } }')
else:
results_file.write('{ "overall" : false, "steps" : { "md5sum_check" : false } }')
results_file.close()

results_file = open("results.json", "w")
if (result == 0):
results_file.write('{ "overall" : true, "steps" : { "md5sum_check" : true } }')
else:
results_file.write('{ "overall" : false, "steps" : { "md5sum_check" : false } }')
results_file.close()
log_file = open("log.txt", "w")
log_file.write("")
log_file.close()

log_file = open("log.txt", "w")
log_file.write("")
log_file.close()
sys.exit(result_code)

# correct way to do this?
return(result)

def check_file(input_file, md5):
file = open(input_file, "r")
contents = file.read()
contents = contents.rstrip()
print ("FILE CONTENTS: "+contents)
if (contents == md5):
print("Contents match")
return(0)
else:
print("Contents DO NOT match")
return(1)
file = open(input_file, "r")
contents = file.read()
contents = contents.rstrip()
print("FILE CONTENTS: "+contents)
if contents == md5:
print("Contents match")
return 0
else:
print("Contents DO NOT match")
return 1


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion checker/md5sum-checker.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cwlVersion: v1.0

requirements:
- class: DockerRequirement
dockerPull: quay.io/agduncan94/checker-md5sum
dockerPull: quay.io/dockstore-testing/md5sum-checker:1.0.0
- class: InlineJavascriptRequirement

hints:
Expand Down
2 changes: 1 addition & 1 deletion checker/md5sum-checker.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ task checkerTask {
}

runtime {
docker: "quay.io/agduncan94/checker-md5sum"
docker: "quay.io/dockstore-testing/md5sum-checker:1.0.0"
}
}
4 changes: 4 additions & 0 deletions md5sum-fail-wdl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"checkerWorkflow.inputFile": "md5sum.input",
"checkerWorkflow.expectedMd5sum": "not a real md5sum"
}
2 changes: 1 addition & 1 deletion md5sum/md5sum-input-cwl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"input_file": {
"class": "File",
"path": "md5sum.input"
"path": "../md5sum.input"
}
}
2 changes: 1 addition & 1 deletion md5sum/md5sum-wdl.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"ga4ghMd5.inputFile": "md5sum.input"
"ga4ghMd5.inputFile": "../md5sum.input"
}
27 changes: 27 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
import unittest


class TestMd5sumChecker(unittest.TestCase):
# For each workflow, verify that it succeeds when the input file's md5sum matches and fails when it does not
def test_cwl_success(self):
process = subprocess.call(["cwltool", "checker-workflow-wrapping-tool.cwl", "checker-input-cwl.json"])
self.assertEqual(process, 0)

def test_cwl_failure(self):
process = subprocess.call(["cwltool", "checker-workflow-wrapping-tool.cwl", "checker-fail-cwl.json"])
self.assertEqual(process, 1)

def test_wdl_success(self):
process = subprocess.call(["java", "-jar", "cromwell-42.jar", "run", "checker-workflow-wrapping-workflow.wdl",
"-i", "md5sum-wdl.json"])
self.assertEqual(process, 0)

def test_wdl_failure(self):
process = subprocess.call(["java", "-jar", "cromwell-42.jar", "run", "checker-workflow-wrapping-workflow.wdl",
"-i", "md5sum-fail-wdl.json"])
self.assertEqual(process, 1)


if __name__ == '__main__':
unittest.main()

0 comments on commit f7927a5

Please sign in to comment.