Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Appwrite Tests and large project support #19

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +14,32 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Run Tests
- name: Bring up services
run: docker-compose up -d --build && sleep 20

- name: Run Supabase Test Suite
run: |
docker compose exec tests php ./vendor/bin/phpunit --group Supabase

- name: Run NHost Test Suite
run: |
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 up -d --build && sleep 5 && docker compose exec tests php ./vendor/bin/phpunit
docker compose exec tests php ./vendor/bin/phpunit --group Appwrite
4 changes: 2 additions & 2 deletions src/Migration/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
Expand Down
3 changes: 3 additions & 0 deletions src/Migration/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Migration/E2E/Sources/NHostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ protected function setUp(): void
$this->transfer = new Transfer($this->source, $this->destination);
}

/**
* @group NHost
*/
public function testSourceReport()
{
// Test report all
Expand All @@ -91,6 +94,8 @@ public function testSourceReport()

/**
* @depends testSourceReport
*
* @group NHost
*/
public function testRunTransfer($state)
{
Expand All @@ -110,10 +115,13 @@ function () {

/**
* @depends testRunTransfer
*
* @group NHost
*/
public function testValidateTransfer($state)
{
$statusCounters = $state['transfer']->getStatusCounters();

$this->assertNotEmpty($statusCounters);

foreach ($statusCounters as $resource => $counters) {
Expand All @@ -131,6 +139,8 @@ public function testValidateTransfer($state)

/**
* @depends testValidateTransfer
*
* @group NHost
*/
public function testValidateUserTransfer($state): void
{
Expand Down Expand Up @@ -162,6 +172,8 @@ public function testValidateUserTransfer($state): void

/**
* @depends testValidateTransfer
*
* @group NHost
*/
public function testValidateDatabaseTransfer($state): void
{
Expand Down Expand Up @@ -215,6 +227,8 @@ public function testValidateDatabaseTransfer($state): void

/**
* @depends testValidateTransfer
*
* @group NHost
*/
public function testValidateStorageTransfer($state): void
{
Expand Down
13 changes: 13 additions & 0 deletions tests/Migration/E2E/Sources/SupabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ protected function setUp(): void
$this->transfer = new Transfer($this->source, $this->destination);
}

/**
* @group Supabase
*/
public function testSourceReport()
{
// Test report all
Expand All @@ -71,6 +74,8 @@ public function testSourceReport()

/**
* @depends testSourceReport
*
* @group Supabase
*/
public function testRunTransfer($state)
{
Expand All @@ -89,6 +94,8 @@ function () {

/**
* @depends testRunTransfer
*
* @group Supabase
*/
public function testValidateTransfer($state)
{
Expand All @@ -110,6 +117,8 @@ public function testValidateTransfer($state)

/**
* @depends testValidateTransfer
*
* @group Supabase
*/
public function testValidateUserTransfer($state): void
{
Expand Down Expand Up @@ -141,6 +150,8 @@ public function testValidateUserTransfer($state): void

/**
* @depends testValidateTransfer
*
* @group Supabase
*/
public function testValidateDatabaseTransfer($state): void
{
Expand Down Expand Up @@ -220,6 +231,8 @@ public function testValidateDatabaseTransfer($state): void

/**
* @depends testValidateTransfer
*
* @group Supabase
*/
public function testValidateStorageTransfer($state): void
{
Expand Down
33 changes: 33 additions & 0 deletions tests/Migration/resources/appwrite/initializeProject.sh
Original file line number Diff line number Diff line change
@@ -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":"[email protected]","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":"[email protected]","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
25 changes: 25 additions & 0 deletions tests/Migration/resources/appwrite/teardownProject.sh
Original file line number Diff line number Diff line change
@@ -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