Skip to content
Merged
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
75 changes: 60 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,35 +179,80 @@ The test algorithm will generate your SDK from a small demo SDK JSON spec file a

To get started, create a language file in this location:

`./tests/languages/tests-for-[MY-LANGUAGE].[MY-LANGUAGE-FILE-EXT]`
`./tests/languages/<language>/test.[MY-LANGUAGE-FILE-EXT]`

In your new language file, init your SDK from a relative path which will be generated here: `./tests/sdks/` from this spec file: `./tests/resources/spec.json`.

After you finish initializing, make a series of HTTP calls using your new generated SDKs method just like in one of these examples:

1. tests/languages/tests-for-php.js
2. tests/languages/tests-for-node.js
1. tests/languages/php/test.php
2. tests/languages/node/test.js

> Note: In your test files, make sure that you begin the test with the following string "\nTest Started\n". We use this string to filter output from the build tool you're using.

Once done, add a Docker command that can execute your test file to the SDK test algorithm `$containers` array in this location: `./tests/SDKTest.php:17`. Make sure to add one command for each language version you wish to support.
Once done, create a new test file `tests/[Language]Test.php` and update as the following.

A good example is the PHP test for 5 different PHP versions:
```php
<?php

namespace Tests;

class [Language]Test extends Base
{
protected string $language = '[language]';
protected string $class = 'Appwrite\SDK\Language\[Language]';
protected array $build = [
//commands required before executing the test
];
protected array $envs = [
// docker commands that can execute test file to the sdk test. Make sure to add
// one command for each lanuage version you wish to support
];

// list of expected outputs from test based on features supported
protected array $expectedOutput = [
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
...Base::EXCEPTION_RESPONSES,
...Base::REALTIME_RESPONSES
];
}
```

A good example is the Dart test:

```php
protected $containers = [
'php-5.6' => 'docker run --rm -v $(pwd):/app -w /app php:5.6-cli php tests/languages/tests-for-php.php',
'php-7.0' => 'docker run --rm -v $(pwd):/app -w /app php:7.0-cli php tests/languages/tests-for-php.php',
'php-7.1' => 'docker run --rm -v $(pwd):/app -w /app php:7.1-cli php tests/languages/tests-for-php.php',
'php-7.2' => 'docker run --rm -v $(pwd):/app -w /app php:7.2-cli php tests/languages/tests-for-php.php',
'php-7.3' => 'docker run --rm -v $(pwd):/app -w /app php:7.3-cli php tests/languages/tests-for-php.php',
'php-7.4' => 'docker run --rm -v $(pwd):/app -w /app php:7.4-cli php tests/languages/tests-for-php.php',
];
<?php

namespace Tests;

class DartTest extends Base
{
protected string $language = 'dart';
protected string $class = 'Appwrite\SDK\Language\Dart';
protected array $build = [
'mkdir -p tests/sdks/dart/tests',
'cp tests/languages/dart/tests.dart tests/sdks/dart/tests/tests.dart',
];
protected array $envs = [
'dart-stable' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:stable sh -c "dart pub get && dart pub run tests/tests.dart"',
'dart-beta' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dart dart:beta sh -c "dart pub get && dart pub run tests/tests.dart"',
];
protected array $expectedOutput = [
...Base::FOO_RESPONSES,
...Base::BAR_RESPONSES,
...Base::GENERAL_RESPONSES,
...Base::EXCEPTION_RESPONSES,
];
}
```

Finally, you can run the tests using
Also in `.travis.yml` add new env `SDK=[Language]` so that travis will run test for this language as well.

Finally, you can run tests using
```sh
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:7.4-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit tests/SDKTest.php"
docker run --rm -v $(pwd):$(pwd):rw -w $(pwd) -v /var/run/docker.sock:/var/run/docker.sock php:7.4-cli-alpine sh -c "apk add docker-cli && vendor/bin/phpunit"
```

## SDK Generator Interface
Expand Down