Skip to content

Commit ad21a6f

Browse files
committed
refactor test for handling different supports on SDKs
1 parent 3138da0 commit ad21a6f

File tree

1 file changed

+122
-39
lines changed

1 file changed

+122
-39
lines changed

tests/SDKTest.php

Lines changed: 122 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,37 @@
1010
ini_set('display_startup_errors', 1);
1111
error_reporting(E_ALL);
1212

13+
const FOO_RESPONSES = [
14+
'GET:/v1/mock/tests/foo:passed',
15+
'POST:/v1/mock/tests/foo:passed',
16+
'PUT:/v1/mock/tests/foo:passed',
17+
'PATCH:/v1/mock/tests/foo:passed',
18+
'DELETE:/v1/mock/tests/foo:passed',
19+
];
20+
21+
const BAR_RESPONSES = [
22+
'GET:/v1/mock/tests/bar:passed',
23+
'POST:/v1/mock/tests/bar:passed',
24+
'PUT:/v1/mock/tests/bar:passed',
25+
'PATCH:/v1/mock/tests/bar:passed',
26+
'DELETE:/v1/mock/tests/bar:passed',
27+
];
28+
29+
const GENERAL_RESPONSES = [
30+
'GET:/v1/mock/tests/general/redirect/done:passed',
31+
'POST:/v1/mock/tests/general/upload:passed',
32+
];
33+
34+
const EXCEPTION_RESPONSES = [
35+
'Mock 400 error',
36+
'Server Error',
37+
'This is a text error',
38+
];
39+
40+
const REALTIME_RESPONSES = [
41+
'WS:/v1/realtime:passed',
42+
];
43+
1344
class SDKTest extends TestCase
1445
{
1546
/**
@@ -25,6 +56,12 @@ class SDKTest extends TestCase
2556
'php-8.0' => 'docker run --rm -v $(pwd):/app -w /app php:8.0-cli-alpine php tests/languages/php/test.php',
2657
],
2758
'supportException' => true,
59+
'expectedOutput' => [
60+
...FOO_RESPONSES,
61+
...BAR_RESPONSES,
62+
...GENERAL_RESPONSES,
63+
...EXCEPTION_RESPONSES,
64+
],
2865
],
2966

3067
'cli' => [
@@ -39,7 +76,11 @@ class SDKTest extends TestCase
3976
'envs' => [
4077
'default' => 'php tests/languages/cli/test.php',
4178
],
42-
'supportException' => false,
79+
'expectedOutput' => [
80+
...FOO_RESPONSES,
81+
...BAR_RESPONSES,
82+
...GENERAL_RESPONSES,
83+
],
4384
],
4485

4586
'dart' => [
@@ -53,7 +94,12 @@ class SDKTest extends TestCase
5394
'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"',
5495
'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"',
5596
],
56-
'supportException' => true,
97+
'expectedOutput' => [
98+
...FOO_RESPONSES,
99+
...BAR_RESPONSES,
100+
...GENERAL_RESPONSES,
101+
...EXCEPTION_RESPONSES,
102+
],
57103
],
58104

59105
'flutter' => [
@@ -65,8 +111,13 @@ class SDKTest extends TestCase
65111
'envs' => [
66112
'flutter-stable' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/flutter --env PUB_CACHE=vendor cirrusci/flutter:stable sh -c "flutter pub get && flutter test test/appwrite_test.dart"',
67113
],
68-
'supportException' => true,
69-
'supportRealtime' => true,
114+
'expectedOutput' => [
115+
...FOO_RESPONSES,
116+
...BAR_RESPONSES,
117+
...GENERAL_RESPONSES,
118+
...EXCEPTION_RESPONSES,
119+
...REALTIME_RESPONSES,
120+
],
70121
],
71122

72123
'android' => [
@@ -79,8 +130,13 @@ class SDKTest extends TestCase
79130
'envs' => [
80131
'java-8' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/android alvrme/alpine-android:latest-jdk8 sh -c "./gradlew :library:testReleaseUnitTest -q && cat library/result.txt"',
81132
],
82-
'supportException' => false,
83-
'supportRealtime' => true,
133+
'expectedOutput' => [
134+
...FOO_RESPONSES,
135+
...BAR_RESPONSES,
136+
...GENERAL_RESPONSES,
137+
...EXCEPTION_RESPONSES,
138+
...REALTIME_RESPONSES,
139+
],
84140
],
85141

86142
'kotlin' => [
@@ -93,7 +149,12 @@ class SDKTest extends TestCase
93149
'envs' => [
94150
'java-8' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/kotlin openjdk:8-jdk-alpine sh -c "./gradlew :test -q && cat result.txt"',
95151
],
96-
'supportException' => false,
152+
'expectedOutput' => [
153+
...FOO_RESPONSES,
154+
...BAR_RESPONSES,
155+
...GENERAL_RESPONSES,
156+
...EXCEPTION_RESPONSES,
157+
],
97158
],
98159

99160
'swift-server' => [
@@ -105,7 +166,12 @@ class SDKTest extends TestCase
105166
'envs' => [
106167
'swift-5.5' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-server swift:5.5 swift test',
107168
],
108-
'supportException' => true,
169+
'expectedOutput' => [
170+
...FOO_RESPONSES,
171+
...BAR_RESPONSES,
172+
...GENERAL_RESPONSES,
173+
...EXCEPTION_RESPONSES,
174+
],
109175
],
110176

111177
'swift-client' => [
@@ -117,8 +183,13 @@ class SDKTest extends TestCase
117183
'envs' => [
118184
'swift-5.5' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-client swift:5.5 swift test',
119185
],
120-
'supportException' => true,
121-
'supportRealtime' => true,
186+
'expectedOutput' => [
187+
...FOO_RESPONSES,
188+
...BAR_RESPONSES,
189+
...GENERAL_RESPONSES,
190+
...EXCEPTION_RESPONSES,
191+
...REALTIME_RESPONSES,
192+
],
122193
],
123194

124195
'dotnet' => [
@@ -133,7 +204,12 @@ class SDKTest extends TestCase
133204
'dotnet-5.0' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dotnet/src/test/ mcr.microsoft.com/dotnet/sdk:5.0-alpine pwsh tests.ps1',
134205
'dotnet-3.1' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/dotnet/src/test/ mcr.microsoft.com/dotnet/sdk:3.1-alpine pwsh tests.ps1',
135206
],
136-
'supportException' => true,
207+
'expectedOutput' => [
208+
...FOO_RESPONSES,
209+
...BAR_RESPONSES,
210+
...GENERAL_RESPONSES,
211+
...EXCEPTION_RESPONSES,
212+
],
137213
],
138214

139215
'web' => [
@@ -150,8 +226,13 @@ class SDKTest extends TestCase
150226
'firefox' => 'docker run --rm -v $(pwd):/app -e BROWSER=firefox -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node tests.js',
151227
'node' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node node.js',
152228
],
153-
'supportException' => true,
154-
'supportRealtime' => true
229+
'expectedOutput' => [
230+
...FOO_RESPONSES,
231+
...BAR_RESPONSES,
232+
...GENERAL_RESPONSES,
233+
...EXCEPTION_RESPONSES,
234+
...REALTIME_RESPONSES,
235+
],
155236
],
156237
'deno' => [
157238
'class' => 'Appwrite\SDK\Language\Deno',
@@ -160,7 +241,12 @@ class SDKTest extends TestCase
160241
'envs' => [
161242
'deno-1.1.3' => 'docker run --rm -v $(pwd):/app -w /app hayd/alpine-deno:1.1.3 run --allow-net --allow-read tests/languages/deno/tests.ts', // TODO: use official image when its out
162243
],
163-
'supportException' => true,
244+
'expectedOutput' => [
245+
...FOO_RESPONSES,
246+
...BAR_RESPONSES,
247+
...GENERAL_RESPONSES,
248+
...EXCEPTION_RESPONSES,
249+
],
164250
],
165251

166252
'node' => [
@@ -173,7 +259,12 @@ class SDKTest extends TestCase
173259
'nodejs-14' => 'docker run --rm -v $(pwd):/app -w /app node:14-alpine node tests/languages/node/test.js',
174260
'nodejs-16' => 'docker run --rm -v $(pwd):/app -w /app node:16-alpine node tests/languages/node/test.js',
175261
],
176-
'supportException' => true,
262+
'expectedOutput' => [
263+
...FOO_RESPONSES,
264+
...BAR_RESPONSES,
265+
...GENERAL_RESPONSES,
266+
...EXCEPTION_RESPONSES,
267+
],
177268
],
178269

179270
'ruby' => [
@@ -184,7 +275,12 @@ class SDKTest extends TestCase
184275
'envs' => [
185276
'ruby-2.7' => 'docker run --rm -v $(pwd):/app -w /app --env GEM_HOME=vendor ruby:2.7-alpine ruby tests/languages/ruby/tests.rb',
186277
],
187-
'supportException' => false,
278+
'expectedOutput' => [
279+
...FOO_RESPONSES,
280+
...BAR_RESPONSES,
281+
...GENERAL_RESPONSES,
282+
...EXCEPTION_RESPONSES,
283+
],
188284
],
189285

190286
'python' => [
@@ -200,7 +296,12 @@ class SDKTest extends TestCase
200296
'python-3.7' => 'docker run --rm -v $(pwd):/app -w /app --env PIP_TARGET=tests/sdks/python/vendor --env PYTHONPATH=tests/sdks/python/vendor python:3.7-alpine python tests/sdks/python/test.py',
201297
'python-3.6' => 'docker run --rm -v $(pwd):/app -w /app --env PIP_TARGET=tests/sdks/python/vendor --env PYTHONPATH=tests/sdks/python/vendor python:3.7-alpine python tests/sdks/python/test.py',
202298
],
203-
'supportException' => true,
299+
'expectedOutput' => [
300+
...FOO_RESPONSES,
301+
...BAR_RESPONSES,
302+
...GENERAL_RESPONSES,
303+
...EXCEPTION_RESPONSES,
304+
],
204305
],
205306
];
206307

@@ -231,6 +332,7 @@ public function testHTTPSuccess()
231332
}
232333

233334
$whitelist = ['php', 'cli', 'node', 'ruby', 'python', 'deno', 'dotnet', 'dart', 'flutter', 'web', 'android', 'kotlin', 'swift-server', 'swift-client'];
335+
$whitelist = ['flutter'];
234336

235337
foreach ($this->languages as $language => $options) {
236338
if (!empty($whitelist) && !in_array($language, $whitelist)) {
@@ -309,29 +411,10 @@ public function testHTTPSuccess()
309411
$removed = array_shift($output);
310412
} while ($removed != 'Test Started' && sizeof($output) != 0);
311413

312-
$this->assertGreaterThan(10, count($output));
313-
314-
$this->assertEquals('GET:/v1/mock/tests/foo:passed', $output[0] ?? '');
315-
$this->assertEquals('POST:/v1/mock/tests/foo:passed', $output[1] ?? '');
316-
$this->assertEquals('PUT:/v1/mock/tests/foo:passed', $output[2] ?? '');
317-
$this->assertEquals('PATCH:/v1/mock/tests/foo:passed', $output[3] ?? '');
318-
$this->assertEquals('DELETE:/v1/mock/tests/foo:passed', $output[4] ?? '');
319-
$this->assertEquals('GET:/v1/mock/tests/bar:passed', $output[5] ?? '');
320-
$this->assertEquals('POST:/v1/mock/tests/bar:passed', $output[6] ?? '');
321-
$this->assertEquals('PUT:/v1/mock/tests/bar:passed', $output[7] ?? '');
322-
$this->assertEquals('PATCH:/v1/mock/tests/bar:passed', $output[8] ?? '');
323-
$this->assertEquals('DELETE:/v1/mock/tests/bar:passed', $output[9] ?? '');
324-
$this->assertEquals('GET:/v1/mock/tests/general/redirect/done:passed', $output[10] ?? '');
325-
$this->assertEquals('POST:/v1/mock/tests/general/upload:passed', $output[11] ?? '');
326-
327-
if ($options['supportException']) {
328-
$this->assertEquals('Mock 400 error',$output[12] ?? '');
329-
$this->assertEquals('Server Error', $output[13] ?? '');
330-
$this->assertEquals('This is a text error', $output[14] ?? '');
331-
}
414+
$this->assertGreaterThanOrEqual(count($options['expectedOutput']), count($output));
332415

333-
if ($options['supportRealtime'] ?? false) {
334-
$this->assertEquals('WS:/v1/realtime:passed', $output[15] ?? '');
416+
foreach ($output as $i => $row) {
417+
$this->assertEquals($options['expectedOutput'][$i], $row);
335418
}
336419
}
337420
}

0 commit comments

Comments
 (0)