Skip to content

Commit 335284c

Browse files
Merge pull request #303 from appwrite/feat-refactor-sdk-tests
refactor test for handling different supports on SDKs
2 parents 0d4cb96 + c05a783 commit 335284c

File tree

1 file changed

+120
-40
lines changed

1 file changed

+120
-40
lines changed

tests/SDKTest.php

Lines changed: 120 additions & 40 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
/**
@@ -24,7 +55,12 @@ class SDKTest extends TestCase
2455
'php-7.4' => 'docker run --rm -v $(pwd):/app -w /app php:7.4-cli-alpine php tests/languages/php/test.php',
2556
'php-8.0' => 'docker run --rm -v $(pwd):/app -w /app php:8.0-cli-alpine php tests/languages/php/test.php',
2657
],
27-
'supportException' => true,
58+
'expectedOutput' => [
59+
...FOO_RESPONSES,
60+
...BAR_RESPONSES,
61+
...GENERAL_RESPONSES,
62+
...EXCEPTION_RESPONSES,
63+
],
2864
],
2965

3066
'cli' => [
@@ -39,7 +75,11 @@ class SDKTest extends TestCase
3975
'envs' => [
4076
'default' => 'php tests/languages/cli/test.php',
4177
],
42-
'supportException' => false,
78+
'expectedOutput' => [
79+
...FOO_RESPONSES,
80+
...BAR_RESPONSES,
81+
...GENERAL_RESPONSES,
82+
],
4383
],
4484

4585
'dart' => [
@@ -53,7 +93,12 @@ class SDKTest extends TestCase
5393
'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"',
5494
'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"',
5595
],
56-
'supportException' => true,
96+
'expectedOutput' => [
97+
...FOO_RESPONSES,
98+
...BAR_RESPONSES,
99+
...GENERAL_RESPONSES,
100+
...EXCEPTION_RESPONSES,
101+
],
57102
],
58103

59104
'flutter' => [
@@ -65,8 +110,13 @@ class SDKTest extends TestCase
65110
'envs' => [
66111
'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"',
67112
],
68-
'supportException' => true,
69-
'supportRealtime' => true,
113+
'expectedOutput' => [
114+
...FOO_RESPONSES,
115+
...BAR_RESPONSES,
116+
...GENERAL_RESPONSES,
117+
...EXCEPTION_RESPONSES,
118+
...REALTIME_RESPONSES,
119+
],
70120
],
71121

72122
'android' => [
@@ -79,8 +129,13 @@ class SDKTest extends TestCase
79129
'envs' => [
80130
'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"',
81131
],
82-
'supportException' => true,
83-
'supportRealtime' => true,
132+
'expectedOutput' => [
133+
...FOO_RESPONSES,
134+
...BAR_RESPONSES,
135+
...GENERAL_RESPONSES,
136+
...EXCEPTION_RESPONSES,
137+
...REALTIME_RESPONSES,
138+
],
84139
],
85140

86141
'kotlin' => [
@@ -93,7 +148,12 @@ class SDKTest extends TestCase
93148
'envs' => [
94149
'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"',
95150
],
96-
'supportException' => true,
151+
'expectedOutput' => [
152+
...FOO_RESPONSES,
153+
...BAR_RESPONSES,
154+
...GENERAL_RESPONSES,
155+
...EXCEPTION_RESPONSES,
156+
],
97157
],
98158

99159
'swift-server' => [
@@ -105,7 +165,12 @@ class SDKTest extends TestCase
105165
'envs' => [
106166
'swift-5.5' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-server swift:5.5 swift test',
107167
],
108-
'supportException' => true,
168+
'expectedOutput' => [
169+
...FOO_RESPONSES,
170+
...BAR_RESPONSES,
171+
...GENERAL_RESPONSES,
172+
...EXCEPTION_RESPONSES,
173+
],
109174
],
110175

111176
'swift-client' => [
@@ -117,8 +182,13 @@ class SDKTest extends TestCase
117182
'envs' => [
118183
'swift-5.5' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/swift-client swift:5.5 swift test',
119184
],
120-
'supportException' => true,
121-
'supportRealtime' => true,
185+
'expectedOutput' => [
186+
...FOO_RESPONSES,
187+
...BAR_RESPONSES,
188+
...GENERAL_RESPONSES,
189+
...EXCEPTION_RESPONSES,
190+
...REALTIME_RESPONSES,
191+
],
122192
],
123193

124194
'dotnet' => [
@@ -133,7 +203,12 @@ class SDKTest extends TestCase
133203
'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',
134204
'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',
135205
],
136-
'supportException' => true,
206+
'expectedOutput' => [
207+
...FOO_RESPONSES,
208+
...BAR_RESPONSES,
209+
...GENERAL_RESPONSES,
210+
...EXCEPTION_RESPONSES,
211+
],
137212
],
138213

139214
'web' => [
@@ -150,8 +225,13 @@ class SDKTest extends TestCase
150225
'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',
151226
'node' => 'docker run --rm -v $(pwd):/app -w /app/tests/sdks/web mcr.microsoft.com/playwright:v1.15.0-focal node node.js',
152227
],
153-
'supportException' => true,
154-
'supportRealtime' => true
228+
'expectedOutput' => [
229+
...FOO_RESPONSES,
230+
...BAR_RESPONSES,
231+
...GENERAL_RESPONSES,
232+
...EXCEPTION_RESPONSES,
233+
...REALTIME_RESPONSES,
234+
],
155235
],
156236
'deno' => [
157237
'class' => 'Appwrite\SDK\Language\Deno',
@@ -160,7 +240,12 @@ class SDKTest extends TestCase
160240
'envs' => [
161241
'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
162242
],
163-
'supportException' => true,
243+
'expectedOutput' => [
244+
...FOO_RESPONSES,
245+
...BAR_RESPONSES,
246+
...GENERAL_RESPONSES,
247+
...EXCEPTION_RESPONSES,
248+
],
164249
],
165250

166251
'node' => [
@@ -173,7 +258,12 @@ class SDKTest extends TestCase
173258
'nodejs-14' => 'docker run --rm -v $(pwd):/app -w /app node:14-alpine node tests/languages/node/test.js',
174259
'nodejs-16' => 'docker run --rm -v $(pwd):/app -w /app node:16-alpine node tests/languages/node/test.js',
175260
],
176-
'supportException' => true,
261+
'expectedOutput' => [
262+
...FOO_RESPONSES,
263+
...BAR_RESPONSES,
264+
...GENERAL_RESPONSES,
265+
...EXCEPTION_RESPONSES,
266+
],
177267
],
178268

179269
'ruby' => [
@@ -184,7 +274,11 @@ class SDKTest extends TestCase
184274
'envs' => [
185275
'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',
186276
],
187-
'supportException' => false,
277+
'expectedOutput' => [
278+
...FOO_RESPONSES,
279+
...BAR_RESPONSES,
280+
...GENERAL_RESPONSES,
281+
],
188282
],
189283

190284
'python' => [
@@ -200,7 +294,12 @@ class SDKTest extends TestCase
200294
'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',
201295
'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',
202296
],
203-
'supportException' => true,
297+
'expectedOutput' => [
298+
...FOO_RESPONSES,
299+
...BAR_RESPONSES,
300+
...GENERAL_RESPONSES,
301+
...EXCEPTION_RESPONSES,
302+
],
204303
],
205304
];
206305

@@ -309,29 +408,10 @@ public function testHTTPSuccess()
309408
$removed = array_shift($output);
310409
} while ($removed != 'Test Started' && sizeof($output) != 0);
311410

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-
}
411+
$this->assertGreaterThanOrEqual(count($options['expectedOutput']), count($output));
332412

333-
if ($options['supportRealtime'] ?? false) {
334-
$this->assertEquals('WS:/v1/realtime:passed', $output[15] ?? '');
413+
foreach ($options['expectedOutput'] as $i => $row) {
414+
$this->assertEquals($output[$i], $row);
335415
}
336416
}
337417
}

0 commit comments

Comments
 (0)