-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alessio Greggi <[email protected]>
- Loading branch information
Showing
3 changed files
with
114 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
unit-test: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Run Unit-Test | ||
run: | | ||
mkdir /tmp/unit/ | ||
go test \ | ||
-v \ | ||
-cover ./... \ | ||
-args -test.gocoverdir=/tmp/unit/ | ||
- name: Upload cover profiles | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: unit-test | ||
path: /tmp/unit/ | ||
|
||
integration-test: | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Build coverage-instrumented binary | ||
run: | | ||
go build \ | ||
-cover \ | ||
-v \ | ||
-o fwdctl . | ||
- name: Run integration test | ||
run: | | ||
sudo ./hack/integration-test.sh | ||
- name: Upload cover profiles | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: integration-test | ||
path: /tmp/integration/ | ||
|
||
code-coverage: | ||
|
||
runs-on: ubuntu-latest | ||
needs: [unit-test,integration-test] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: unit-test | ||
path: /tmp/unit-test | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: integration-test | ||
path: /tmp/integration-test | ||
|
||
- name: list files | ||
run: | | ||
ls -lah /tmp/unit-test | ||
ls -lah /tmp/integration-test | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Calculate total coverage | ||
run: | | ||
go tool \ | ||
covdata \ | ||
textfmt \ | ||
-i=/tmp/unit-test,/tmp/integration-test \ | ||
-o code-coverage | ||
go tool \ | ||
cover \ | ||
-func code-coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
# | ||
set -e | ||
|
||
# create directory to store cover profiles | ||
INTEGDIR=/tmp/integration | ||
mkdir -p $INTEGDIR | ||
export GOCOVERDIR=$INTEGDIR | ||
|
||
# list of subcommands we want to test | ||
command_list="version|list|help|generate rules -O /tmp/|generate systemd -O /tmp/ -f /tmp/rules.yaml -p /tmp/ -t fork|add -d 8080 -i lo -P tcp -s 127.0.0.1 -p 9090|delete -n 1" | ||
|
||
IFS="|" | ||
for cmd in $command_list; | ||
do | ||
command="./fwdctl $cmd" | ||
echo "$command" | ||
eval "$command" | ||
done |