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

Update TYPE_ENVVAR to TYPE_ENVIRONMENT_VARIABLES and fix tests #26

Merged
merged 4 commits into from
Feb 23, 2024
Merged
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
26 changes: 5 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
FROM supabase/postgres:15.1.0.96 as supabase-db
COPY ./tests/Migration/resources/supabase/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY ./tests/Migration/resources/supabase/2_main.sql /docker-entrypoint-initdb.d/2_main.sql
COPY tests/Migration/resources/supabase/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY tests/Migration/resources/supabase/2_main.sql /docker-entrypoint-initdb.d/2_main.sql
RUN rm -rf /docker-entrypoint-initdb.d/migrate.sh

FROM postgres:alpine3.18 as nhost-db
COPY ./tests/Migration/resources/nhost/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY ./tests/Migration/resources/nhost/2_main.sql /docker-entrypoint-initdb.d/2_main.sql

# Use my fork of mockoon while waiting for range headers to be merged
FROM node:20.4-alpine3.17 as mock-api
WORKDIR /app
RUN apk add --no-cache git
RUN git clone https://github.com/PineappleIOnic/mockoon.git
WORKDIR /app/mockoon
RUN git checkout origin/feat-implement-range
RUN apk add python3 make gcc g++
RUN npm run bootstrap
RUN npm run build:libs
RUN npm run build:cli
RUN cd packages/cli && npm install -g .
RUN adduser --shell /bin/sh --disabled-password --gecos "" mockoon
USER mockoon
CMD mockoon-cli start --data /mockoon/api.json --port 80 --disable-log-to-file && tail -f /dev/null
COPY tests/Migration/resources/nhost/1_globals.sql /docker-entrypoint-initdb.d/1_globals.sql
COPY tests/Migration/resources/nhost/2_main.sql /docker-entrypoint-initdb.d/2_main.sql

FROM composer:2.0 as composer
WORKDIR /usr/local/src/
Expand All @@ -37,4 +21,4 @@ RUN set -ex \
COPY ./src /app/src
COPY ./tests /app/src/tests
COPY --from=composer /usr/local/src/vendor /app/vendor
CMD tail -f /dev/null
CMD tail -f /dev/null
14 changes: 6 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,18 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres

nhost-storage:
build:
context: .
target: mock-api
image: mockoon/cli:latest
command: ["--data", "/mockoon/api.json", "--port", "80", "--disable-log-to-file"]
networks:
- tests
volumes:
- ./tests/Migration/resources/nhost:/mockoon

supabase-api:
build:
context: .
target: mock-api
image: mockoon/cli:latest
command: ["--data", "/mockoon/api.json", "--port", "80", "--disable-log-to-file"]
networks:
- tests
volumes:
Expand All @@ -65,4 +63,4 @@ services:
- SUPABASE_DB_URL=postgres://postgres:postgres@supabase-db:5432/postgres

networks:
tests:
tests:
4 changes: 2 additions & 2 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function getSupportedResources(): array
// Functions
Resource::TYPE_FUNCTION,
Resource::TYPE_DEPLOYMENT,
Resource::TYPE_ENVVAR,
Resource::TYPE_ENVIRONMENT_VARIABLE,

// Settings
];
Expand Down Expand Up @@ -693,7 +693,7 @@ public function importFunctionResource(Resource $resource): Resource
$resource->getEnabled()
);
break;
case Resource::TYPE_ENVVAR:
case Resource::TYPE_ENVIRONMENT_VARIABLE:
/** @var EnvVar $resource */
$functions->createVariable(
$resource->getFunc()->getId(),
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Destinations/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function getSupportedResources(): array
Resource::TYPE_DATABASE,
Resource::TYPE_DEPLOYMENT,
Resource::TYPE_DOCUMENT,
Resource::TYPE_ENVVAR,
Resource::TYPE_ENVIRONMENT_VARIABLE,
Resource::TYPE_FILE,
Resource::TYPE_FUNCTION,
Resource::TYPE_HASH,
Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class Resource

public const TYPE_HASH = 'hash';

public const TYPE_ENVVAR = 'envvar';
public const TYPE_ENVIRONMENT_VARIABLE = 'environment variable';

public const ALL_RESOURCES = [
self::TYPE_ATTRIBUTE,
Expand All @@ -66,7 +66,7 @@ abstract class Resource
self::TYPE_HASH,
self::TYPE_INDEX,
self::TYPE_USER,
self::TYPE_ENVVAR,
self::TYPE_ENVIRONMENT_VARIABLE,
self::TYPE_TEAM,
self::TYPE_MEMBERSHIP,
];
Expand Down
2 changes: 1 addition & 1 deletion src/Migration/Resources/Functions/EnvVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(Func $func, string $key, string $value)

public static function getName(): string
{
return Resource::TYPE_ENVVAR;
return Resource::TYPE_ENVIRONMENT_VARIABLE;
}

public function getGroup(): string
Expand Down
8 changes: 4 additions & 4 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function getSupportedResources(): array
// Functions
Resource::TYPE_FUNCTION,
Resource::TYPE_DEPLOYMENT,
Resource::TYPE_ENVVAR,
Resource::TYPE_ENVIRONMENT_VARIABLE,

// Settings
];
Expand Down Expand Up @@ -252,11 +252,11 @@ public function report(array $resources = []): array
}
}

if (in_array(Resource::TYPE_ENVVAR, $resources)) {
$report[Resource::TYPE_ENVVAR] = 0;
if (in_array(Resource::TYPE_ENVIRONMENT_VARIABLE, $resources)) {
$report[Resource::TYPE_ENVIRONMENT_VARIABLE] = 0;
$functions = $functionsClient->list()['functions'];
foreach ($functions as $function) {
$report[Resource::TYPE_ENVVAR] += $functionsClient->listVariables($function['$id'])['total'];
$report[Resource::TYPE_ENVIRONMENT_VARIABLE] += $functionsClient->listVariables($function['$id'])['total'];
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Transfer

public const GROUP_STORAGE_RESOURCES = [Resource::TYPE_FILE, Resource::TYPE_BUCKET];

public const GROUP_FUNCTIONS_RESOURCES = [Resource::TYPE_FUNCTION, Resource::TYPE_ENVVAR, Resource::TYPE_DEPLOYMENT];
public const GROUP_FUNCTIONS_RESOURCES = [Resource::TYPE_FUNCTION, Resource::TYPE_ENVIRONMENT_VARIABLE, Resource::TYPE_DEPLOYMENT];

public const GROUP_DATABASES_RESOURCES = [Resource::TYPE_DATABASE, Resource::TYPE_COLLECTION, Resource::TYPE_INDEX, Resource::TYPE_ATTRIBUTE, Resource::TYPE_DOCUMENT];

Expand All @@ -30,7 +30,7 @@ class Transfer
Resource::TYPE_USER, Resource::TYPE_TEAM,
Resource::TYPE_MEMBERSHIP, Resource::TYPE_FILE,
Resource::TYPE_BUCKET, Resource::TYPE_FUNCTION,
Resource::TYPE_ENVVAR, Resource::TYPE_DEPLOYMENT,
Resource::TYPE_ENVIRONMENT_VARIABLE, Resource::TYPE_DEPLOYMENT,
Resource::TYPE_DATABASE, Resource::TYPE_COLLECTION,
Resource::TYPE_INDEX, Resource::TYPE_ATTRIBUTE,
Resource::TYPE_DOCUMENT,
Expand Down
2 changes: 1 addition & 1 deletion tests/Migration/E2E/Adapters/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function getSupportedResources(): array
Resource::TYPE_HASH,
Resource::TYPE_INDEX,
Resource::TYPE_USER,
Resource::TYPE_ENVVAR,
Resource::TYPE_ENVIRONMENT_VARIABLE,
Resource::TYPE_TEAM,
Resource::TYPE_MEMBERSHIP,
];
Expand Down
2 changes: 1 addition & 1 deletion tests/Migration/E2E/Sources/NHostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function testValidateUserTransfer($state): void
$this->assertEquals('$2a$10$ARQ/f.K6OmCjZ8XF0U.6fezPMlxDqsmcl0Rs6xQVkvj62u7gcSzOW', $foundUser->getPasswordHash()->getHash());
$this->assertEquals('bcrypt', $foundUser->getPasswordHash()->getAlgorithm());
$this->assertEquals('test@test.com', $foundUser->getUsername());
$this->assertEquals(['email'], $foundUser->getTypes());
$this->assertEquals(['password'], $foundUser->getTypes());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Migration/E2E/Sources/SupabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testValidateUserTransfer($state): void
$this->assertEquals('success', $foundUser->getStatus());
$this->assertEquals('$2a$10$NGZAAOfXeheUoH9V3dnRoeR.r3J5ynnSZ6KjvHxOUlV8XUrulJzQa', $foundUser->getPasswordHash()->getHash());
$this->assertEquals('bcrypt', $foundUser->getPasswordHash()->getAlgorithm());
$this->assertEquals(['email'], $foundUser->getTypes());
$this->assertEquals(['password'], $foundUser->getTypes());
}

/**
Expand Down
Loading