Skip to content

Commit

Permalink
Update application analysis CI tests
Browse files Browse the repository at this point in the history
Updating structure of test-data and adding kantra anlyze tests also for
java binary and java with maven settings file.

Related to konveyor#233

Signed-off-by: Marek Aufart <[email protected]>
  • Loading branch information
aufi committed Jun 28, 2024
1 parent 1300c6e commit c2689e9
Show file tree
Hide file tree
Showing 19 changed files with 391 additions and 2,722 deletions.
34 changes: 8 additions & 26 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,24 @@ jobs:
run: |
podman build -t localhost/kantra:latest -f Dockerfile .
go build -o kantra main.go
echo "RUNNER_IMG=localhost/kantra:latest" >>$GITHUB_ENV
- name: Run unit tests
run: |
RUNNER_IMG=localhost/kantra:latest go test ./...
go test ./...
- name: Fetch sample applications
run: |
git clone https://github.com/konveyor/example-applications
git clone https://github.com/ivargrimstad/jakartaee-duke
git clone https://github.com/konveyor/example-applications $(pwd)/hack/tmp/example-applications
git clone https://github.com/ivargrimstad/jakartaee-duke $(pwd)/hack/tmp/jakartaee-duke
- name: Run analysis test and copy output
run: |
RUNNER_IMG=localhost/kantra:latest ./kantra analyze --input $(pwd)/example-applications/example-1/ --output ./output/ --rules ./test-data/jni-native-code-test.windup.xml --target cloud-readiness
# TODO (pgaikwad): Change this to a yaml test and run `kantra test`
- name: Fail if analysis output does not match expected
- name: Run analysis test java custom rule
run: |
expected_file=./test-data/analysis-output.yaml
actual_file=./output/output.yaml
function filter_and_sort() {
yq e 'del(.[].skipped) | del(.[].unmatched)' $1 \
| yq e '.[]?.violations |= (. | to_entries | sort_by(.key) | from_entries)' \
| yq e '.[]?.violations[]?.incidents |= sort_by(.uri)' \
| yq e '.[] | (.tags // []) |= sort'
}
filter_and_sort $expected_file > $expected_file
filter_and_sort $actual_file > $actual_file
diff $expected_file $actual_file
./hack/test_analysis.sh test-data/java-testapp-rule-jni-native-code
- name: Fail if dependencies output does not match expected
- name: Run analysis test java binary file
run: |
expected_file=./test-data/deps-output.yaml
actual_file=./output/dependencies.yaml
sed 's/^[ \t-]*//' $expected_file | sort -s > /tmp/expected_file
sed 's/^[ \t-]*//' $actual_file | sort -s > /tmp/actual_file
diff /tmp/expected_file /tmp/actual_file || diff $expected_file $actual_file
./hack/test_analysis.sh test-data/java-binary
# run tests using conainer image / binary already published to quay
test-published:
Expand Down
50 changes: 50 additions & 0 deletions hack/test_analysis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/sh
#
# Usage: run_analysis_test <test-data-directory>
#
set -e

if [ ! -d $1 ]; then
echo "ERROR: Missing or invalid test-data directory."
exit 1
fi
test_dir=$1
cd ${test_dir}

# Setup variables
RUNNER_IMG="${RUNNER_IMG:-quay.io/konveyor/kantra:latest}"
KANTRA_CMD="${KANTRA_CMD:-../../kantra}"
TEST_APPS_ROOT="${TEST_APPS_ROOT:-../../hack/tmp}"

# Run the analysis calling kantra
. ./cmd
kantra_exit=$?
if [ "$kantra_exit" != 0 ]; then
echo "ERROR: kantra command execution failed."
exit $kantra_exit
fi

# Check analysis result
expected_file=output.yaml
actual_file=output/output.yaml
function filter_and_sort() {
yq e 'del(.[].skipped) | del(.[].unmatched)' $1 \
| yq e '.[]?.violations |= (. | to_entries | sort_by(.key) | from_entries)' \
| yq e '.[]?.violations[]?.incidents |= sort_by(.uri)' \
| yq e '.[] | (.tags // []) |= sort'
}
filter_and_sort $expected_file > $expected_file
filter_and_sort $actual_file > $actual_file
diff $expected_file $actual_file


# Check dependencies
if [ -f dependencies.yaml ]; then
expected_file=dependencies.yaml
actual_file=output/dependencies.yaml
sed 's/^[ \t-]*//' $expected_file | sort -s > /tmp/expected_file
sed 's/^[ \t-]*//' $actual_file | sort -s > /tmp/actual_file
diff /tmp/expected_file /tmp/actual_file || diff $expected_file $actual_file
fi

exit 0
21 changes: 21 additions & 0 deletions test-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Analysis test data

Subdirectories contain kantra analysis testcases files. The following structure is expected:

```
cmd (kantra analyze command with options specific for given test case)
output.yaml (expected analysis output yaml file)
dependencies.yaml (optional, expected dependencies files created by analysis)
```

A script `hack/run_analysis_test.sh` runs the kantra command and checks outputs. Exit code 0 is success, other failure. The script changes directory to the provided test-dir, so all paths there should be relative.

## Tests execution

Example usage from kantra project directory:

```
$ ./hack/run_analysis_test.sh test-data/analysis/<test-dir>
```
Loading

0 comments on commit c2689e9

Please sign in to comment.