From b8649698432652f4d198b47ccd7f6eed64a135ee Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Thu, 17 Jan 2019 23:43:04 +0100 Subject: Parallelize QA tests Test projects are now given as a parameter to the test command --- .gitlab-ci.yml | 21 +++++++++++++++++++-- run.sh | 6 +++--- test/test.sh | 58 +++++++++++++++++++++++++++++++++++----------------------- 3 files changed, 57 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1190750..2c63d4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -60,14 +60,31 @@ container_scanning: reports: container_scanning: gl-container-scanning-report.json -QA: +.QA: image: docker:stable stage: test script: - docker info - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - docker pull $TMP_IMAGE - - docker run $TMP_IMAGE test + - mkdir results + - docker run --volume `pwd`/results:/results $TMP_IMAGE test $QA_PROJECT $QA_REF + artifacts: + paths: + - results/ + when: always + +QA:java-maven: + extends: .QA + variables: + QA_PROJECT: java-maven + QA_REF: ccec8318 + +QA:ruby-bundler: + extends: .QA + variables: + QA_PROJECT: ruby-bundler + QA_REF: 6b858821 .docker_tag: image: docker:stable diff --git a/run.sh b/run.sh index d82d133..bba4771 100755 --- a/run.sh +++ b/run.sh @@ -7,7 +7,7 @@ $(basename "$0") [-h] $(basename "$0") analyze PROJECT_PATH -$(basename "$0") test +$(basename "$0") test PROJECT_NAME PROJECT_REF where: -h show this help text @@ -60,7 +60,7 @@ if [ "$COMMAND" = "analyze" -a $# -ne 1 ] ; then exit 1 fi -if [ "$COMMAND" = "test" -a $# -ne 0 ] ; then +if [ "$COMMAND" = "test" -a $# -ne 2 ] ; then echo "$usage" exit 1 fi @@ -69,7 +69,7 @@ fi case "$COMMAND" in test) # Run integration tests. - exec /test/test.sh + exec /test/test.sh $1 $2 ;; analyze) diff --git a/test/test.sh b/test/test.sh index 53c1805..bbf66f7 100755 --- a/test/test.sh +++ b/test/test.sh @@ -2,26 +2,38 @@ set -e -for project in ruby-bundler-rails java-maven; do - # Clone the test repository. - echo "Cloning the test repository https://gitlab.com/gitlab-org/security-products/tests/$project.git" - git clone "https://gitlab.com/gitlab-org/security-products/tests/$project.git" "/code/$project" - - # Run license management on it. - echo "Running license management on the $project" - cd "/code/$project" - /run.sh analyze . - - # Compare results with expected results. - set +e - diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" > /diff.txt - set -e - - if [ -s /diff.txt ] ; then - echo "Unexpected result. Here is the diff between actual results and those expected :" - cat /diff.txt - exit 1 - fi -done - -echo "All tests are OK." +project=$1 +ref=$2 +url="https://gitlab.com/gitlab-org/security-products/tests/$project.git" + +# Clone the test repository. +echo "Cloning the test project $project from $url" +git clone "$url" "/code/$project" + +# Run license management on it. +echo "Running license management on the $project with ref $ref" +cd "/code/$project" +git checkout "$ref" 2> /dev/null +/run.sh analyze . + +mkdir -p /results/ +# In order to upload the artifact always +cp "/code/$project/gl-license-management-report.json" "/results/$project-gl-license-management-report.json" + +# Compare results with expected results. +set +e + +diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" > /diff.txt +error=$? +if [[ $error -eq 0 ]]; then + echo "The report matches the fixture." + exit 0 +elif [[ $error -eq 1 ]]; then + echo "Unexpected result. Here is the diff between actual results and those expected :" + cat /diff.txt + mv /diff.txt "/results/$project-diff.txt" +else + echo "Could not compare the fixture to the generated report" +fi + +exit 1 -- cgit v1.2.3 From 76385b533e179f1faf51ad3da8e1b07abb427526 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Thu, 17 Jan 2019 23:43:57 +0100 Subject: Add test for python-pip --- .gitlab-ci.yml | 6 ++ test/results/python-pip.json | 195 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 test/results/python-pip.json diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2c63d4b..7a908c2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -80,6 +80,12 @@ QA:java-maven: QA_PROJECT: java-maven QA_REF: ccec8318 +QA:python-pip: + extends: .QA + variables: + QA_PROJECT: python-pip + QA_REF: 04dce91b + QA:ruby-bundler: extends: .QA variables: diff --git a/test/results/python-pip.json b/test/results/python-pip.json new file mode 100644 index 0000000..b5e724a --- /dev/null +++ b/test/results/python-pip.json @@ -0,0 +1,195 @@ +{ + "licenses": [ + { + "count": 4, + "name": "BSD" + }, + { + "count": 4, + "name": "MIT" + }, + { + "count": 1, + "name": "Copyright (c) 2015, Julien Fache" + }, + { + "count": 1, + "name": "New BSD License" + }, + { + "count": 1, + "name": "Python Software Foundation License" + }, + { + "count": 1, + "name": "Standard PIL License" + } + ], + "dependencies": [ + { + "license": { + "name": "BSD", + "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" + }, + "dependency": { + "name": "Django", + "url": "https://www.djangoproject.com/", + "description": "A high-level Python Web framework that encourages rapid development and clean, pragmatic design.", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "Standard PIL License" + }, + "dependency": { + "name": "Pillow", + "url": "https://python-pillow.org", + "description": "Python Imaging Library (Fork)", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "MIT", + "url": "http://opensource.org/licenses/mit-license" + }, + "dependency": { + "name": "beautifulsoup4", + "url": "http://www.crummy.com/software/BeautifulSoup/bs4/", + "description": "Screen-scraping library", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "BSD", + "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" + }, + "dependency": { + "name": "django-contrib-comments", + "url": "https://github.com/django/django-contrib-comments", + "description": "The code formerly known as django.contrib.comments.", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "BSD", + "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" + }, + "dependency": { + "name": "django-js-asset", + "url": "https://github.com/matthiask/django-js-asset/", + "description": "script tag with additional attributes for django.forms.Media", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "MIT", + "url": "http://opensource.org/licenses/mit-license" + }, + "dependency": { + "name": "django-mptt", + "url": "http://github.com/django-mptt/django-mptt", + "description": "Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances.", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "BSD", + "url": "http://en.wikipedia.org/wiki/BSD_licenses#4-clause_license_.28original_.22BSD_License.22.29" + }, + "dependency": { + "name": "django-tagging", + "url": "https://github.com/Fantomas42/django-tagging", + "description": "Generic tagging application for Django", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "New BSD License" + }, + "dependency": { + "name": "django-xmlrpc", + "url": "https://github.com/Fantomas42/django-xmlrpc", + "description": "XML-RPC Server App for the Django framework.", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "Copyright (c) 2015, Julien Fache" + }, + "dependency": { + "name": "mots-vides", + "url": "https://github.com/Fantomas42/mots-vides", + "description": "Python library for managing stop words in many languages.", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "MIT", + "url": "http://opensource.org/licenses/mit-license" + }, + "dependency": { + "name": "pyparsing", + "url": "http://pyparsing.wikispaces.com/", + "description": "Python parsing module", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "MIT", + "url": "http://opensource.org/licenses/mit-license" + }, + "dependency": { + "name": "pytz", + "url": "http://pythonhosted.org/pytz", + "description": "World timezone definitions, modern and historical", + "pathes": [ + "." + ] + } + }, + { + "license": { + "name": "Python Software Foundation License", + "url": "http://hg.python.org/cpython/raw-file/89ce323357db/LICENSE" + }, + "dependency": { + "name": "regex", + "url": "https://bitbucket.org/mrabarnett/mrab-regex", + "description": "Alternative regular expression module, to replace re.", + "pathes": [ + "." + ] + } + } + ] +} -- cgit v1.2.3 From 8c29c7be6f18f54fdd99504ef025c72b0ab16ef7 Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Tue, 5 Feb 2019 20:58:05 +0100 Subject: Simplify test script by ending with diff directly --- test/test.sh | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/test/test.sh b/test/test.sh index bbf66f7..2b6326c 100755 --- a/test/test.sh +++ b/test/test.sh @@ -16,24 +16,9 @@ cd "/code/$project" git checkout "$ref" 2> /dev/null /run.sh analyze . +# In order to upload the artifact to check it manually mkdir -p /results/ -# In order to upload the artifact always cp "/code/$project/gl-license-management-report.json" "/results/$project-gl-license-management-report.json" # Compare results with expected results. -set +e - -diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" > /diff.txt -error=$? -if [[ $error -eq 0 ]]; then - echo "The report matches the fixture." - exit 0 -elif [[ $error -eq 1 ]]; then - echo "Unexpected result. Here is the diff between actual results and those expected :" - cat /diff.txt - mv /diff.txt "/results/$project-diff.txt" -else - echo "Could not compare the fixture to the generated report" -fi - -exit 1 +diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" -- cgit v1.2.3 From 094281bd8b2a6ca9d4bb5aec720f165694ee472e Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Tue, 5 Feb 2019 21:06:07 +0100 Subject: Use unified diff --- test/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.sh b/test/test.sh index 2b6326c..40c29f0 100755 --- a/test/test.sh +++ b/test/test.sh @@ -21,4 +21,4 @@ mkdir -p /results/ cp "/code/$project/gl-license-management-report.json" "/results/$project-gl-license-management-report.json" # Compare results with expected results. -diff "/code/$project/gl-license-management-report.json" "/test/results/$project.json" +diff -u "/code/$project/gl-license-management-report.json" "/test/results/$project.json" -- cgit v1.2.3