summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Brahmer <info@b-brahmer.de>2022-10-24 17:16:08 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2023-01-29 19:25:35 +0100
commite7881a76cf457c912635658da8a6c6fb0f0d17af (patch)
tree8d84239d0e8600b9cd12baffe4170cf86f4abc42
parent9ae22c246f842bc53d32bfc09bd708251491c3b6 (diff)
Create the basis to enable tests for the updating and purging functions.
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
-rw-r--r--.github/workflows/updater-test.yml109
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
m---------tests/test_helper/php-feed-generator0
-rw-r--r--tests/updater/helpers/settings.bash6
-rw-r--r--tests/updater/update.bats76
6 files changed, 195 insertions, 0 deletions
diff --git a/.github/workflows/updater-test.yml b/.github/workflows/updater-test.yml
new file mode 100644
index 000000000..f723b19c6
--- /dev/null
+++ b/.github/workflows/updater-test.yml
@@ -0,0 +1,109 @@
+name: Updater Tests
+on:
+ pull_request
+
+env:
+ POSTGRES_PASSWORD: nc_test_db
+ MYSQL_USER: nc_test
+ MYSQL_PASSWORD: nc_test_db
+ MYSQL_DATABASE: nc_test
+ MYSQL_PORT: 3800
+
+jobs:
+ integration:
+ runs-on: ubuntu-latest
+ continue-on-error: ${{ matrix.experimental }}
+ name: "Update Test: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }}"
+ strategy:
+ matrix:
+ php-versions: ['8.1']
+ nextcloud: ['stable25']
+ database: ['sqlite']
+ experimental: [false]
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ submodules: recursive
+
+ - name: Setup PHP
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ extensions: pdo_sqlite,pdo_mysql,pdo_pgsql,gd,zip
+ coverage: none
+
+ - name: Setup BATS & httpie
+ run: sudo apt-get install -y httpie && npm install -g bats@1.7.0
+
+ - name: Set up server
+ uses: SMillerDev/nextcloud-actions/setup-nextcloud@main
+ with:
+ version: ${{ matrix.nextcloud }}
+ cron: true
+ database-type: ${{ matrix.database }}
+ database-host: localhost
+ database-port: 5432
+ database-name: postgres
+ database-user: postgres
+ database-password: ${{ env.POSTGRES_PASSWORD }}
+
+ - name: Prime app build
+ run: make
+
+ - name: Configure server with app
+ uses: SMillerDev/nextcloud-actions/setup-nextcloud-app@main
+ with:
+ app: 'news'
+ check-code: false
+ force: ${{ matrix.experimental }}
+
+ - name: Install composer install php-feed-generator
+ working-directory: ../server
+ run: composer install -d apps/news/tests/test_helper/php-feed-generator
+
+ - name: Run API tests
+ working-directory: ../server
+ run: |
+ php -S localhost:8080 &> /tmp/webserver.log &
+ cd apps/news/tests/test_helper/feeds && php -S localhost:8090 &> /tmp/feedserver.log &
+
+ sleep 2
+
+ cd ${{ github.workspace }}/../server
+
+ bats apps/news/tests/api
+
+ # Kill php server
+ kill %1
+ kill %2
+
+ - name: Setup problem matchers for PHP
+ run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
+
+ - name: Functional tests maintenance
+ working-directory: ../server
+ run: |
+ ./occ maintenance:repair
+
+ - name: Functional tests
+ working-directory: ../server
+ run: |
+ cd apps/news/tests/test_helper/feeds && php -S localhost:8090 &> /tmp/feedserver.log &
+
+ sleep 2
+
+ cd ${{ github.workspace }}/../server
+
+ bats apps/news/tests/command
+
+ kill %1
+
+ - name: Prep PHP tests
+ working-directory: ../server/apps/news
+ run: make php-test-dependencies
+
+ - name: Feed tests
+ working-directory: ../server/apps/news
+ run: make feed-test
+
diff --git a/.gitignore b/.gitignore
index 7f9ed3550..487fce669 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ site/
#bats
tests/api/helpers/settings-override.bash
+tests/test_helper/feeds/test.xml
# python
PKG-INFO
diff --git a/.gitmodules b/.gitmodules
index d74af0778..b3b42f3c2 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,6 @@
[submodule "tests/test_helper/bats-assert"]
path = tests/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
+[submodule "tests/test_helper/php-feed-generator"]
+ path = tests/test_helper/php-feed-generator
+ url = https://github.com/Grotax/php-feed-generator.git
diff --git a/tests/test_helper/php-feed-generator b/tests/test_helper/php-feed-generator
new file mode 160000
+Subproject 5ba7f911244de1d8a1f5d2f5abaec7e39eafcd9
diff --git a/tests/updater/helpers/settings.bash b/tests/updater/helpers/settings.bash
new file mode 100644
index 000000000..3053687d1
--- /dev/null
+++ b/tests/updater/helpers/settings.bash
@@ -0,0 +1,6 @@
+export user=admin
+export NC_FEED="http://localhost:8090/Nextcloud.rss"
+export HEISE_FEED="http://localhost:8090/heise.xml"
+export BASE_URLv1="http://localhost:8080/index.php/apps/news/api/v1-2"
+export NC_HOST="http://localhost:8080"
+export TEST_FEED="http://localhost:8090/test.xml" \ No newline at end of file
diff --git a/tests/updater/update.bats b/tests/updater/update.bats
new file mode 100644
index 000000000..9b3504bdd
--- /dev/null
+++ b/tests/updater/update.bats
@@ -0,0 +1,76 @@
+#!/usr/bin/env bats
+
+setup_file(){
+ load "helpers/settings"
+
+ if test -f "tests/api/helpers/settings-override.bash"; then
+ load "helpers/settings-override"
+ fi
+
+ export APP_PASSWORD=$(NC_PASS=${user} ./occ user:add-app-password ${user} --password-from-env | grep -Po '([A-Z|a-z|0-9]{72})')
+}
+
+teardown_file(){
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${NC_HOST}/ocs/v2.php/core/apppassword OCS-APIRequest:true
+}
+
+setup() {
+ load "../test_helper/bats-support/load"
+ load "../test_helper/bats-assert/load"
+ php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 50 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
+}
+
+TESTSUITE="Update"
+
+#
+# This testsuite is not intended to test the api but rather the update and purge functions.
+#
+
+teardown() {
+ # delete all feeds
+ FEED_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+ for i in $FEED_IDS; do
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/feeds/$i > /dev/null
+ done
+
+ # delete all folders
+ FOLDER_IDS=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/folders | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+ for i in $FOLDER_IDS; do
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} DELETE ${BASE_URLv1}/folders/$i > /dev/null
+ done
+
+
+}
+
+@test "[$TESTSUITE] Test simple update" {
+ # Create Feed
+ FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
+ # Get Items
+ ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+ # Trigger Update
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
+ # Get Items again
+ ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+
+ assert_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
+}
+
+@test "[$TESTSUITE] Test simple update with new content" {
+ # Create Feed
+ FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
+ # Get Items
+ ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+
+ php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 60 -s 41 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
+
+ # Trigger Update
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
+ # Get Items again
+ ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+
+ output="${ID_LIST2[*]}"
+
+ # Check that they are not equal but that they match partially.
+ assert_not_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
+ assert_output --partial "${ID_LIST1[*]}"
+} \ No newline at end of file