Skip to content

Commit 3eed59d

Browse files
committed
also test s3 external with versioning enabled
Signed-off-by: Robin Appelman <[email protected]>
1 parent 0f5ec0f commit 3eed59d

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

.github/workflows/s3-external.yml

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
APP_NAME: files_external
1515

1616
jobs:
17-
s3-external-tests:
17+
s3-external-tests-minio:
1818
runs-on: ubuntu-latest
1919

2020
strategy:
@@ -23,7 +23,7 @@ jobs:
2323
matrix:
2424
php-versions: ['7.4', '8.0']
2525

26-
name: php${{ matrix.php-versions }}-${{ matrix.ftpd }}
26+
name: php${{ matrix.php-versions }}-minio
2727

2828
services:
2929
minio:
@@ -57,17 +57,68 @@ jobs:
5757
run: |
5858
echo "<?php return ['run' => true,'hostname' => 'localhost','key' => 'minio','secret' => 'minio123', 'bucket' => 'bucket', 'port' => 9000, 'use_ssl' => false, 'autocreate' => true, 'use_path_style' => true];" > apps/${{ env.APP_NAME }}/tests/config.amazons3.php
5959
phpunit --configuration tests/phpunit-autotest-external.xml apps/files_external/tests/Storage/Amazons3Test.php
60+
phpunit --configuration tests/phpunit-autotest-external.xml apps/files_external/tests/Storage/VersionedAmazonS3Test.php
6061
- name: S3 logs
6162
if: always()
6263
run: |
6364
docker ps -a
6465
docker logs $(docker ps -aq)
66+
s3-external-tests-localstack:
67+
runs-on: ubuntu-latest
68+
69+
strategy:
70+
# do not stop on another job's failure
71+
fail-fast: false
72+
matrix:
73+
php-versions: ['7.4', '8.0']
74+
75+
name: php${{ matrix.php-versions }}-localstack
76+
77+
services:
78+
minio:
79+
env:
80+
SERVICES: s3
81+
DEBUG: 1
82+
image: localstack/localstack:0.12.7
83+
ports:
84+
- "4566:4566"
85+
86+
steps:
87+
- name: Checkout server
88+
uses: actions/checkout@v2
89+
with:
90+
submodules: true
91+
92+
- name: Set up php ${{ matrix.php-versions }}
93+
uses: shivammathur/setup-php@v2
94+
with:
95+
php-version: ${{ matrix.php-versions }}
96+
tools: phpunit
97+
extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, zip, gd
98+
99+
- name: Set up Nextcloud
100+
run: |
101+
mkdir data
102+
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
103+
./occ app:enable --force ${{ env.APP_NAME }}
104+
php -S localhost:8080 &
105+
- name: PHPUnit
106+
run: |
107+
echo "<?php return ['run' => true,'hostname' => 'localhost','key' => 'ignored','secret' => 'ignored', 'bucket' => 'bucket', 'port' => 4566, 'use_ssl' => false, 'autocreate' => true, 'use_path_style' => true];" > apps/${{ env.APP_NAME }}/tests/config.amazons3.php
108+
phpunit --configuration tests/phpunit-autotest-external.xml apps/files_external/tests/Storage/Amazons3Test.php
109+
phpunit --configuration tests/phpunit-autotest-external.xml apps/files_external/tests/Storage/VersionedAmazonS3Test.php
110+
- name: S3 logs
111+
if: always()
112+
run: |
113+
docker ps -a
114+
docker logs $(docker ps -aq)
115+
65116
s3-external-summary:
66117
runs-on: ubuntu-latest
67-
needs: s3-external-tests
118+
needs: [s3-external-tests-minio, s3-external-tests-localstack]
68119

69120
if: always()
70121

71122
steps:
72123
- name: Summary status
73-
run: if ${{ needs.s3-external-tests.result != 'success' }}; then exit 1; fi
124+
run: if ${{ needs.s3-external-tests-minio.result != 'success' }} || ${{ needs.s3-external-tests-localstack.result != 'success' }}; then exit 1; fi
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2021 Robin Appelman <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\files_external\tests\Storage;
25+
26+
27+
use OCA\Files_External\Lib\Storage\AmazonS3;
28+
29+
/**
30+
* @group DB
31+
*/
32+
class VersionedAmazonS3Test extends \Test\Files\Storage\Storage {
33+
private $config;
34+
35+
protected function setUp(): void {
36+
parent::setUp();
37+
38+
$this->config = include('files_external/tests/config.amazons3.php');
39+
if (!is_array($this->config) or !$this->config['run']) {
40+
$this->markTestSkipped('AmazonS3 backend not configured');
41+
}
42+
$this->instance = new AmazonS3($this->config);
43+
try {
44+
$this->instance->getConnection()->putBucketVersioning([
45+
'Bucket' => $this->instance->getBucket(),
46+
'VersioningConfiguration' => [
47+
'Status' => 'Enabled',
48+
],
49+
]);
50+
} catch (\Exception $e) {
51+
$this->markTestSkipped("s3 backend doesn't seem to support versioning");
52+
}
53+
}
54+
55+
protected function tearDown(): void {
56+
if ($this->instance) {
57+
$this->instance->rmdir('');
58+
}
59+
60+
parent::tearDown();
61+
}
62+
63+
public function testStat() {
64+
$this->markTestSkipped('S3 doesn\'t update the parents folder mtime');
65+
}
66+
}

tests/lib/Files/Storage/Storage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ public function testRenameDirectory() {
498498
$this->assertTrue($this->instance->file_exists('target/subfolder'));
499499
$this->assertTrue($this->instance->file_exists('target/subfolder/test.txt'));
500500

501+
$contents = iterator_to_array($this->instance->getDirectoryContent(''));
502+
$this->assertCount(1, $contents);
503+
501504
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
502505
$this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt'));
503506
$this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt'));

0 commit comments

Comments
 (0)