Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Brahmer <[email protected]>
  • Loading branch information
Grotax committed Dec 29, 2024
1 parent 476c97b commit 3bee890
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions tests/updater/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ teardown() {
@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]+)')

sleep 2

# 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
Expand All @@ -65,7 +65,7 @@ teardown() {
@test "[$TESTSUITE] Test if nextUpdateTime is updated" {
# Create Feed
FEED=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED)

UpdateTime1=$(echo $FEED | jq '.feeds | .[0].nextUpdateTime')
FEEDID=$(echo $FEED | jq '.feeds | .[0].id')

Expand All @@ -87,7 +87,7 @@ teardown() {
sleep 2

UpdateTime2=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds | jq '.feeds | .[0].nextUpdateTime')

# Assert that UpdateTime2 is within the expected range
run bash -c "[[ $UpdateTime2 -ge $expected_time_min && $UpdateTime2 -le $expected_time_max ]]"
assert_success
Expand All @@ -100,17 +100,17 @@ teardown() {

# Create Feed
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')

sleep 2

# 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 15 -s 9 -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

sleep 2

# Get Items again
Expand All @@ -127,9 +127,9 @@ teardown() {
#@test "[$TESTSUITE] Test feed with 'outdated' items https://github.com/nextcloud/news/issues/2236 " {
# # Create Feed, for the first fetch a timestamp today -1 year is used.
# FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
#
#
# sleep 2
#
#
# # Get Items
# ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
#
Expand All @@ -138,7 +138,7 @@ teardown() {
#
# # Trigger Update
# http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
#
#
# sleep 2
#
# # Get Items again
Expand All @@ -152,6 +152,9 @@ teardown() {
#}

@test "[$TESTSUITE] Test purge with small feed" {
# Disable useNextUpdateTime
./occ config:app:set news useNextUpdateTime --value=false

# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 50 -s 0 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
# Create Feed
Expand Down Expand Up @@ -191,10 +194,10 @@ teardown() {
for n in "${ID_LIST[@]}" ; do
((n > max)) && max=$n
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')

# cleanup, purge items
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/cleanup/after-update

Expand All @@ -213,13 +216,16 @@ teardown() {
}

@test "[$TESTSUITE] Test purge with more items than default limit 200" {
# Disable useNextUpdateTime
./occ config:app:set news useNextUpdateTime --value=false

# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 210 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
# Create Feed
FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')

sleep 2

# Get Items
ID_LIST=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))

Expand All @@ -228,10 +234,10 @@ teardown() {
for n in "${ID_LIST[@]}" ; do
((n > max)) && max=$n
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')

# cleanup, purge items
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/cleanup/after-update

Expand All @@ -248,6 +254,9 @@ teardown() {
}

@test "[$TESTSUITE] Test Update and pruge with feed item>200; items<200" {
# Disable useNextUpdateTime
./occ config:app:set news useNextUpdateTime --value=false

# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 210 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml
# Create Feed
Expand All @@ -260,7 +269,7 @@ teardown() {
for n in "${ID_LIST[@]}" ; do
((n > max)) && max=$n
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')
# cleanup, purge items
Expand All @@ -282,7 +291,7 @@ teardown() {
for n in "${ID_LIST[@]}" ; do
((n > max)) && max=$n
done

# mark all items of feed as read, returns nothing
STATUS_CODE=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEEDID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')

Expand All @@ -301,11 +310,14 @@ teardown() {
}

@test "[$TESTSUITE] Test purge with two feeds with different item count limit" {
# Disable useNextUpdateTime
./occ config:app:set news useNextUpdateTime --value=false

# Generate Feed with 260 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 260 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/feed1.xml
# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 210 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/feed2.xml

# Create Feeds
FEED1ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$FEED1 | grep -Po '"id":\K([0-9]+)')
FEED2ID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$FEED2 | grep -Po '"id":\K([0-9]+)')
Expand All @@ -317,11 +329,11 @@ teardown() {
for n in "${ID_LIST[@]}" ; do
((n > max)) && max=$n
done

# mark all items of both feeds as read, returns nothing
STATUS_CODE1=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEED1ID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')
STATUS_CODE2=$(http --ignore-stdin -hdo /tmp/body -a ${user}:${APP_PASSWORD} PUT ${BASE_URLv1}/feeds/$FEED2ID/read newestItemId="$max" 2>&1| grep -Po '(?<=HTTP\/1\.1 )[0-9]{3}(?= OK)')

# cleanup, purge items
http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/cleanup/after-update

Expand Down

0 comments on commit 3bee890

Please sign in to comment.