Skip to content

Commit

Permalink
make tests run in parallel (atleast somewhat)
Browse files Browse the repository at this point in the history
  • Loading branch information
unglaublicherdude committed Jun 11, 2024
1 parent 9a41de5 commit 638143c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 51 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,7 @@ jobs:
run: ./install.sh

- name: run tests
run: ./test.bats

- name: test upload when vaas does not function
env:
CLIENT_ID: ${{ secrets.VAAS_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.VAAS_CLIENT_SECRET }}
run: |
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"
STATUS_CODE=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
run: bats --jobs 3 ./tests

- uses: actions/upload-artifact@master
with:
Expand Down
40 changes: 0 additions & 40 deletions test.bats

This file was deleted.

46 changes: 46 additions & 0 deletions tests/functionality-parallel.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bats

setup_file() {
echo 'nothingwronghere' > /tmp/clean.txt
echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.com.txt
curl --output /tmp/pup.exe http://amtso.eicar.org/PotentiallyUnwanted.exe
docker exec --env OC_PASS=myfancysecurepassword234 --user www-data nextcloud-container php occ user:add testuser --password-from-env || echo "already exists"
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
}

@test "test admin eicar Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
echo "Actual: $RESULT"
[[ "$RESULT" =~ "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." ]]
}

@test "test admin clean Upload" {
RESULT=$(curl -w "%{http_code}" -u admin:admin -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/admin/clean.txt)
echo "Actual: $RESULT"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test admin pup Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/admin/pup.exe)
echo "Actual: $RESULT"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]]
}

@test "test testuser eicar Upload" {
RESULT=$(curl --silent -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/testuser/eicar.com.txt)
echo "Actual: $RESULT"
[[ "$RESULT" =~ "Virus EICAR-Test-File is detected in the file. Upload cannot be completed." ]]
}

@test "test testuser clean Upload" {
STATUS_CODE=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/clean.txt http://127.0.0.1/remote.php/dav/files/testuser/clean.txt)
echo "Actual: $RESULT"
[[ $STATUS_CODE -ge 200 && $STATUS_CODE -lt 300 ]] || exit 1
}

@test "test testuser pup Upload" {
RESULT=$(curl --silent -w "%{http_code}" -w "%{http_code}" -u testuser:myfancysecurepassword234 -T /tmp/pup.exe http://127.0.0.1/remote.php/dav/files/testuser/pup.exe)
echo "Actual: $RESULT"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]] || exit 1
}

19 changes: 19 additions & 0 deletions tests/functionality-sequential.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bats

setup_file() {
BATS_NO_PARALLELIZE_WITHIN_FILE=true
}

setup() {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="WRONG_PASSWORD"
}

@test "test upload when vaas does not function" {
RESULT=$(curl --silent -w "%{http_code}" -u admin:admin -T /tmp/eicar.com.txt http://127.0.0.1/remote.php/dav/files/admin/eicar.com.txt)
echo "Actual: $RESULT"
[[ $RESULT -ge 200 && $RESULT -lt 300 ]] || exit 1
}

tearddown() {
docker exec --user www-data -i nextcloud-container php occ config:app:set gdatavaas clientSecret --value="$CLIENT_SECRET"
}

0 comments on commit 638143c

Please sign in to comment.