From cef1f389ac9ff441192601b728f2735432e97983 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:31:40 +0100 Subject: [PATCH 1/6] Start working on Appwrite Tests --- .github/workflows/tests.yml | 11 +++++-- src/Migration/Cache.php | 4 +-- src/Migration/Source.php | 3 ++ tests/Migration/E2E/Sources/NHostTest.php | 9 +++++ tests/Migration/E2E/Sources/SupabaseTest.php | 8 +++++ .../resources/appwrite/initializeProject.sh | 33 +++++++++++++++++++ .../resources/appwrite/teardownProject.sh | 25 ++++++++++++++ 7 files changed, 89 insertions(+), 4 deletions(-) create mode 100755 tests/Migration/resources/appwrite/initializeProject.sh create mode 100755 tests/Migration/resources/appwrite/teardownProject.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b51d5e71..ee7f2095 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,6 +14,13 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Run Tests + - name: Bring up services + run: docker-compose up -d --build && sleep 5 + + - name: Run Supabase Test Suite + run: | + docker compose exec tests php ./vendor/bin/phpunit --group Supabase + + - name: Run NHost Test Suite run: | - docker-compose up -d --build && sleep 5 && docker compose exec tests php ./vendor/bin/phpunit \ No newline at end of file + docker compose exec tests php ./vendor/bin/phpunit --group NHost \ No newline at end of file diff --git a/src/Migration/Cache.php b/src/Migration/Cache.php index 1eb505c7..7246ad87 100644 --- a/src/Migration/Cache.php +++ b/src/Migration/Cache.php @@ -119,13 +119,13 @@ public function getAll() } /** - * Wipe Cache + * Clear Cache * * Removes all resources from the cache. * * @return void */ - public function wipe() + public function clear() { $this->cache = []; } diff --git a/src/Migration/Source.php b/src/Migration/Source.php index 774eb9ab..9f0cb147 100644 --- a/src/Migration/Source.php +++ b/src/Migration/Source.php @@ -82,6 +82,9 @@ public function exportResources(array $resources, int $batchSize) $this->exportGroupFunctions($batchSize, $resources); break; } + + // Clear the cache after each group + $this->cache->clear(); } } diff --git a/tests/Migration/E2E/Sources/NHostTest.php b/tests/Migration/E2E/Sources/NHostTest.php index 410216fa..59fec97f 100644 --- a/tests/Migration/E2E/Sources/NHostTest.php +++ b/tests/Migration/E2E/Sources/NHostTest.php @@ -77,6 +77,9 @@ protected function setUp(): void $this->transfer = new Transfer($this->source, $this->destination); } + /** + * @group NHost + */ public function testSourceReport() { // Test report all @@ -91,6 +94,7 @@ public function testSourceReport() /** * @depends testSourceReport + * @group NHost */ public function testRunTransfer($state) { @@ -110,10 +114,12 @@ function () { /** * @depends testRunTransfer + * @group NHost */ public function testValidateTransfer($state) { $statusCounters = $state['transfer']->getStatusCounters(); + $this->assertNotEmpty($statusCounters); foreach ($statusCounters as $resource => $counters) { @@ -131,6 +137,7 @@ public function testValidateTransfer($state) /** * @depends testValidateTransfer + * @group NHost */ public function testValidateUserTransfer($state): void { @@ -162,6 +169,7 @@ public function testValidateUserTransfer($state): void /** * @depends testValidateTransfer + * @group NHost */ public function testValidateDatabaseTransfer($state): void { @@ -215,6 +223,7 @@ public function testValidateDatabaseTransfer($state): void /** * @depends testValidateTransfer + * @group NHost */ public function testValidateStorageTransfer($state): void { diff --git a/tests/Migration/E2E/Sources/SupabaseTest.php b/tests/Migration/E2E/Sources/SupabaseTest.php index 832e7835..7a1bce0b 100644 --- a/tests/Migration/E2E/Sources/SupabaseTest.php +++ b/tests/Migration/E2E/Sources/SupabaseTest.php @@ -57,6 +57,9 @@ protected function setUp(): void $this->transfer = new Transfer($this->source, $this->destination); } + /** + * @group Supabase + */ public function testSourceReport() { // Test report all @@ -71,6 +74,7 @@ public function testSourceReport() /** * @depends testSourceReport + * @group Supabase */ public function testRunTransfer($state) { @@ -89,6 +93,7 @@ function () { /** * @depends testRunTransfer + * @group Supabase */ public function testValidateTransfer($state) { @@ -110,6 +115,7 @@ public function testValidateTransfer($state) /** * @depends testValidateTransfer + * @group Supabase */ public function testValidateUserTransfer($state): void { @@ -141,6 +147,7 @@ public function testValidateUserTransfer($state): void /** * @depends testValidateTransfer + * @group Supabase */ public function testValidateDatabaseTransfer($state): void { @@ -220,6 +227,7 @@ public function testValidateDatabaseTransfer($state): void /** * @depends testValidateTransfer + * @group Supabase */ public function testValidateStorageTransfer($state): void { diff --git a/tests/Migration/resources/appwrite/initializeProject.sh b/tests/Migration/resources/appwrite/initializeProject.sh new file mode 100755 index 00000000..593d78be --- /dev/null +++ b/tests/Migration/resources/appwrite/initializeProject.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Create Console Account +curl -s -k 'https://localhost/v1/account' \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --data-raw '{"userId":"admin","email":"admin@appwrite.io","password":"Password123","name":"Admin"}' \ + --compressed \ + --insecure + +# Login +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/account/sessions/email' \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --data-raw '{"email":"admin@appwrite.io","password":"Password123"}' \ + --compressed \ + --insecure + +# Create Team +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/teams' \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --data-raw '{"teamId":"personal","name":"Personal Projects"}' \ + --compressed \ + --insecure + +# Create Project +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/projects' \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --data-raw '{"projectId":"test","name":"Test","teamId":"personal","region":"default"}' \ + --compressed \ + --insecure \ No newline at end of file diff --git a/tests/Migration/resources/appwrite/teardownProject.sh b/tests/Migration/resources/appwrite/teardownProject.sh new file mode 100755 index 00000000..15121421 --- /dev/null +++ b/tests/Migration/resources/appwrite/teardownProject.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# Delete Project +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/projects/test' \ + -X DELETE \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --compressed \ + --insecure + +# Delete Team +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/teams/personal' \ + -X DELETE \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --compressed \ + --insecure + +# Delete Console Account +curl -s -k -b console-cookies.txt -c console-cookies.txt 'https://localhost/v1/account' \ + -X DELETE \ + -H 'content-type: application/json' \ + -H 'x-appwrite-project: console' \ + --compressed \ + --insecure \ No newline at end of file From 7516020f2a8212e4e36043b8b2959153fb6c4bce Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:41:25 +0100 Subject: [PATCH 2/6] Add Appwrite Provisioning --- .github/workflows/tests.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ee7f2095..e2a200ee 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,8 +4,8 @@ on: push: { branches: [main] } jobs: - tests: - name: Run Test Suite + mockapi: + name: Run Mock API Test Suite runs-on: ubuntu-latest env: COMPOSE_FILE: docker-compose.yml @@ -23,4 +23,23 @@ jobs: - name: Run NHost Test Suite run: | - docker compose exec tests php ./vendor/bin/phpunit --group NHost \ No newline at end of file + docker compose exec tests php ./vendor/bin/phpunit --group NHost + appwrite: + name: Run Appwrite Test Suite + runs-on: ubuntu-latest + env: + COMPOSE_FILE: docker-compose.yml + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install Appwrite + run: | + git clone https://github.com/appwrite/appwrite.git && + cd appwrite + docker-compose up -d --build + + - name: Run Appwrite Test Suite + run: | + docker compose exec tests php ./vendor/bin/phpunit --group Appwrite From ab80f809a7e345ae47c22d27ce9bf8932555d98b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:43:49 +0100 Subject: [PATCH 3/6] Update tests.yml --- .github/workflows/tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e2a200ee..4ffd1eb5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,8 +36,9 @@ jobs: - name: Install Appwrite run: | - git clone https://github.com/appwrite/appwrite.git && + git clone https://github.com/appwrite/appwrite.git cd appwrite + cp .env.example .env docker-compose up -d --build - name: Run Appwrite Test Suite From 75ed6f0931d7d1a976b95e64631d5d3c2134755e Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:52:03 +0100 Subject: [PATCH 4/6] Update tests.yml --- .github/workflows/tests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4ffd1eb5..c40fe7d7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v2 - name: Bring up services - run: docker-compose up -d --build && sleep 5 + run: docker-compose up -d --build --detach --wait --wait-timeout 180 && sleep 5 - name: Run Supabase Test Suite run: | @@ -38,7 +38,6 @@ jobs: run: | git clone https://github.com/appwrite/appwrite.git cd appwrite - cp .env.example .env docker-compose up -d --build - name: Run Appwrite Test Suite From b097c6b40766643308f515f4858f0c91bb7e9c0a Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:52:54 +0100 Subject: [PATCH 5/6] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c40fe7d7..c433e085 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v2 - name: Bring up services - run: docker-compose up -d --build --detach --wait --wait-timeout 180 && sleep 5 + run: docker-compose up -d --build && sleep 20 - name: Run Supabase Test Suite run: | From 964a7cbfc28426cc3e6540512b02c5527c8f1aac Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Sep 2023 16:53:24 +0100 Subject: [PATCH 6/6] Run Linter --- tests/Migration/E2E/Sources/NHostTest.php | 5 +++++ tests/Migration/E2E/Sources/SupabaseTest.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/Migration/E2E/Sources/NHostTest.php b/tests/Migration/E2E/Sources/NHostTest.php index 59fec97f..dd28e65f 100644 --- a/tests/Migration/E2E/Sources/NHostTest.php +++ b/tests/Migration/E2E/Sources/NHostTest.php @@ -94,6 +94,7 @@ public function testSourceReport() /** * @depends testSourceReport + * * @group NHost */ public function testRunTransfer($state) @@ -114,6 +115,7 @@ function () { /** * @depends testRunTransfer + * * @group NHost */ public function testValidateTransfer($state) @@ -137,6 +139,7 @@ public function testValidateTransfer($state) /** * @depends testValidateTransfer + * * @group NHost */ public function testValidateUserTransfer($state): void @@ -169,6 +172,7 @@ public function testValidateUserTransfer($state): void /** * @depends testValidateTransfer + * * @group NHost */ public function testValidateDatabaseTransfer($state): void @@ -223,6 +227,7 @@ public function testValidateDatabaseTransfer($state): void /** * @depends testValidateTransfer + * * @group NHost */ public function testValidateStorageTransfer($state): void diff --git a/tests/Migration/E2E/Sources/SupabaseTest.php b/tests/Migration/E2E/Sources/SupabaseTest.php index 7a1bce0b..8e9f54c7 100644 --- a/tests/Migration/E2E/Sources/SupabaseTest.php +++ b/tests/Migration/E2E/Sources/SupabaseTest.php @@ -74,6 +74,7 @@ public function testSourceReport() /** * @depends testSourceReport + * * @group Supabase */ public function testRunTransfer($state) @@ -93,6 +94,7 @@ function () { /** * @depends testRunTransfer + * * @group Supabase */ public function testValidateTransfer($state) @@ -115,6 +117,7 @@ public function testValidateTransfer($state) /** * @depends testValidateTransfer + * * @group Supabase */ public function testValidateUserTransfer($state): void @@ -147,6 +150,7 @@ public function testValidateUserTransfer($state): void /** * @depends testValidateTransfer + * * @group Supabase */ public function testValidateDatabaseTransfer($state): void @@ -227,6 +231,7 @@ public function testValidateDatabaseTransfer($state): void /** * @depends testValidateTransfer + * * @group Supabase */ public function testValidateStorageTransfer($state): void