Skip to content

Commit

Permalink
Merge pull request #747 from appwrite/fix-cli
Browse files Browse the repository at this point in the history
fix: cli
  • Loading branch information
lohanidamodar authored Dec 24, 2023
2 parents c7405b6 + 5e0f726 commit 21743f4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
php-version: ['8.1']
sdk: [Android11Java8, Android11Java11, Android12Java8, Android12Java11, CLINode14, CLINode16, DartBeta, DartStable, Deno1193, Deno1303, DotNet60, DotNet70, FlutterStable, FlutterBeta, Go112, Go118, KotlinJava8, KotlinJava11, KotlinJava17, Node12, Node14, Node16, PHP74, PHP80, Python38, Python39, Python310, Ruby27, Ruby30, Ruby31, AppleSwift55, Swift55, WebChromium, WebNode]
sdk: [Android11Java8, Android11Java11, Android12Java8, Android12Java11, CLINode16, CLINode18, DartBeta, DartStable, Deno1193, Deno1303, DotNet60, DotNet70, FlutterStable, FlutterBeta, Go112, Go118, KotlinJava8, KotlinJava11, KotlinJava17, Node12, Node14, Node16, PHP74, PHP80, Python38, Python39, Python310, Ruby27, Ruby30, Ruby31, AppleSwift55, Swift55, WebChromium, WebNode]

steps:
- name: Checkout repository
Expand Down
12 changes: 12 additions & 0 deletions mock-server/app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
->action(function ($x, $y, $z) {
});

// Version Route for CLI
App::get('/v1/health/version')
->desc('Get version')
->groups(['api', 'health'])
->label('scope', 'public')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->inject('response')
->action(function (UtopiaSwooleResponse $response) {
$response->json([ 'version' => '1.0.0' ]);
});

App::post('/v1/mock/tests/foo')
->desc('Post Foo')
->groups(['mock'])
Expand Down
6 changes: 3 additions & 3 deletions tests/CLINode14Test.php → tests/CLINode18Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Appwrite\SDK\Language;
use Appwrite\SDK\Language\CLI;

class CLINode14Test extends Base
class CLINode18Test extends Base
{
protected string $sdkName = 'cli';
protected string $sdkPlatform = 'server';
Expand All @@ -15,11 +15,11 @@ class CLINode14Test extends Base
protected string $language = 'cli';
protected string $class = 'Appwrite\SDK\Language\CLI';
protected array $build = [
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/cli node:16-alpine npm install',
'docker run --rm -v $(pwd):/app -w /app/tests/sdks/cli node:18-alpine npm install',
'cp tests/languages/cli/test.js tests/sdks/cli/test.js'
];
protected string $command =
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/cli node:14-alpine node test.js';
'docker run --network="mockapi" --rm -v $(pwd):/app -w /app/tests/sdks/cli node:18-alpine node test.js';

protected array $expectedOutput = [
...Base::FOO_RESPONSES,
Expand Down
123 changes: 81 additions & 42 deletions tests/languages/cli/test.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,96 @@
const { exec, execSync } = require('child_process');
const { exec, execSync } = require("child_process");

execSync("node index client --endpoint 'https://qa.appwrite.org/v1' --projectId console --key=35y3h5h345 --selfSigned true", { stdio: 'inherit' });
execSync(
"node index client --endpoint 'http://mockapi/v1' --projectId console --key=35y3h5h345 --selfSigned true",
{ stdio: "inherit" }
);

var output;
console.log('\nTest Started');
console.log("\nTest Started");

// Foo
output = execSync("node index foo get --x string --y 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index foo post --x string --y 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index foo put --x string --y 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index foo patch --x string --y 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index foo delete --x string --y 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync(
"node index foo get --x string --y 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index foo post --x string --y 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index foo put --x string --y 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index foo patch --x string --y 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index foo delete --x string --y 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

// Bar
output = execSync("node index bar get --required string --xdefault 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index bar post --required string --xdefault 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index bar put --required string --xdefault 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index bar patch --required string --xdefault 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);

output = execSync("node index bar delete --required string --xdefault 123 --z string in array", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync(
"node index bar get --required string --xdefault 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index bar post --required string --xdefault 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index bar put --required string --xdefault 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index bar patch --required string --xdefault 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync(
"node index bar delete --required string --xdefault 123 --z string in array",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

// General
output = execSync("node index general redirect", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync("node index general redirect", { stdio: "pipe" }).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync("node index general upload --x string --y 123 --z string in array --file ../../resources/file.png", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync(
"node index general upload --x string --y 123 --z string in array --file ../../resources/file.png",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

output = execSync("node index general upload --x string --y 123 --z string in array --file ../../resources/large_file.mp4", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync(
"node index general upload --x string --y 123 --z string in array --file ../../resources/large_file.mp4",
{ stdio: "pipe" }
).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

// Skip extra tests for CLI
console.log('POST:/v1/mock/tests/general/upload:passed')
console.log('POST:/v1/mock/tests/general/upload:passed')
console.log("POST:/v1/mock/tests/general/upload:passed");
console.log("POST:/v1/mock/tests/general/upload:passed");

execSync("node index general empty", { stdio: 'pipe'});
execSync("node index general empty", { stdio: "pipe" });

output = execSync("node index general headers", { stdio: 'pipe'}).toString();
console.log(output.split('\n')[0].split(" : ")[1]);
output = execSync("node index general headers", { stdio: "pipe" }).toString();
console.log(output.split("\n")[0].split(" : ")[1]);

0 comments on commit 21743f4

Please sign in to comment.