summaryrefslogtreecommitdiff
path: root/test/test.sh
blob: bbf66f72e9fb9be629b062c5b62f3661947c99f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

set -e

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