Skip to content

Commit f153fb7

Browse files
committed
refactor(tests): extract inline PHP seed into integration_helper.php
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 32a22f3 commit f153fb7

3 files changed

Lines changed: 72 additions & 33 deletions

File tree

.github/workflows/tests-deploy.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,20 +1654,13 @@ jobs:
16541654
16551655
- name: Seed stray ex_deploy_options row for a second app
16561656
# Without a second appid in the table, the Update.php bug from #808 is
1657-
# latent formatDeployOptions() with no $appId filter still produces
1657+
# latent: formatDeployOptions() with no $appId filter still produces
16581658
# the single app's rows by luck. The `zz_` prefix ensures this stray row
16591659
# iterates AFTER `app-skeleton-python`, so the last-wins flattening
16601660
# actually clobbers the skeleton's env_vars entry.
16611661
run: |
1662-
php -r '
1663-
require "lib/base.php";
1664-
OCP\Server::get(OCP\App\IAppManager::class)->loadApp("app_api");
1665-
$svc = OCP\Server::get(OCA\AppAPI\Service\ExAppDeployOptionsService::class);
1666-
$svc->addExAppDeployOptions("zz_fake_second_app", [
1667-
"environment_variables" => ["UNRELATED_VAR" => ["name" => "UNRELATED_VAR", "value" => "x"]],
1668-
"mounts" => [],
1669-
]);
1670-
'
1662+
php apps/${{ env.APP_NAME }}/tests/integration_helper.php \
1663+
set-env zz_fake_second_app UNRELATED_VAR x
16711664
16721665
- name: Build v2 info.xml with bumped version
16731666
# Update.php:153 short-circuits when versions match; bumping to 999.0.0

tests/integration_helper.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
/**
11+
* CLI helper for AppAPI integration tests.
12+
*
13+
* Seeds or clears rows in `ex_deploy_options` directly, without running a full
14+
* `app_api:app:register` cycle. Used to reproduce multi-app states that are
15+
* awkward to set up via OCC alone (e.g. issue #808).
16+
*
17+
* Usage:
18+
* php integration_helper.php set-env <appid> <name> <value>
19+
* php integration_helper.php remove <appid>
20+
*/
21+
22+
require __DIR__ . '/../../../lib/base.php';
23+
24+
OCP\Server::get(OCP\App\IAppManager::class)->loadApp('app_api');
25+
$service = OCP\Server::get(OCA\AppAPI\Service\ExAppDeployOptionsService::class);
26+
27+
$command = $argv[1] ?? '';
28+
$appid = $argv[2] ?? '';
29+
30+
if ($appid === '') {
31+
fwrite(STDERR, "usage: integration_helper.php set-env <appid> <name> <value>\n");
32+
fwrite(STDERR, " integration_helper.php remove <appid>\n");
33+
exit(1);
34+
}
35+
36+
switch ($command) {
37+
case 'set-env':
38+
$name = $argv[3] ?? '';
39+
$value = $argv[4] ?? '';
40+
if ($name === '') {
41+
fwrite(STDERR, "missing <name>\n");
42+
exit(1);
43+
}
44+
$existing = $service->getDeployOption($appid, 'environment_variables');
45+
$envVars = $existing !== null ? $existing->getValue() : [];
46+
$envVars[$name] = ['name' => $name, 'value' => $value];
47+
$service->addExAppDeployOption($appid, 'environment_variables', $envVars);
48+
echo "set {$name}={$value} for {$appid}\n";
49+
break;
50+
51+
case 'remove':
52+
$service->removeExAppDeployOptions($appid);
53+
echo "removed deploy options for {$appid}\n";
54+
break;
55+
56+
default:
57+
fwrite(STDERR, "unknown command '{$command}'\n");
58+
exit(1);
59+
}

tests/test_occ_commands_k8s.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -500,26 +500,19 @@ def test_k8s_update_preserves_deploy_options():
500500
options merge entirely in the JSON path.
501501
3. Run `app_api:app:update`.
502502
4. Assert the env vars declared in info.xml are present on the new
503-
Deployment pod spec TEST_ENV_1 with its default and TEST_ENV_2
503+
Deployment pod spec: TEST_ENV_1 with its default and TEST_ENV_2
504504
with the user-provided value.
505505
"""
506506
print(" test_k8s_update_preserves_deploy_options...", end=" ", flush=True)
507507

508-
seed_code = (
509-
'require "lib/base.php";'
510-
'OCP\\Server::get(OCP\\App\\IAppManager::class)->loadApp("app_api");'
511-
'$svc = OCP\\Server::get(OCA\\AppAPI\\Service\\ExAppDeployOptionsService::class);'
512-
'$svc->addExAppDeployOptions("app-skeleton-python", ['
513-
'"environment_variables" => ["TEST_ENV_2" => ["name" => "TEST_ENV_2", "value" => "user_provided_value"]],'
514-
'"mounts" => [],'
515-
']);'
516-
'$svc->addExAppDeployOptions("zz_fake_second_app", ['
517-
'"environment_variables" => ["UNRELATED_VAR" => ["name" => "UNRELATED_VAR", "value" => "x"]],'
518-
'"mounts" => [],'
519-
']);'
520-
)
521-
r = run(["php", "-r", seed_code], stdout=PIPE, stderr=PIPE)
522-
assert r.returncode == 0, f"Seed failed: {r.stderr.decode()}"
508+
helper = os.path.join(os.path.dirname(os.path.abspath(__file__)), "integration_helper.php")
509+
510+
def seed(appid, name, value):
511+
r = run(["php", helper, "set-env", appid, name, value], stdout=PIPE, stderr=PIPE)
512+
assert r.returncode == 0, f"seed {appid}/{name} failed: {r.stderr.decode()}"
513+
514+
seed("app-skeleton-python", "TEST_ENV_2", "user_provided_value")
515+
seed("zz_fake_second_app", "UNRELATED_VAR", "x")
523516

524517
xml = urllib.request.urlopen(SKELETON_XML_URL, timeout=30).read().decode()
525518
xml_v2 = re.sub(r"<version>[^<]+</version>", "<version>100.0.0</version>", xml, count=1)
@@ -558,13 +551,7 @@ def test_k8s_update_preserves_deploy_options():
558551
f"#808 regression: user-provided TEST_ENV_2 lost after update; env_map={env_map}"
559552
)
560553

561-
cleanup_code = (
562-
'require "lib/base.php";'
563-
'OCP\\Server::get(OCP\\App\\IAppManager::class)->loadApp("app_api");'
564-
'$svc = OCP\\Server::get(OCA\\AppAPI\\Service\\ExAppDeployOptionsService::class);'
565-
'$svc->removeExAppDeployOptions("zz_fake_second_app");'
566-
)
567-
run(["php", "-r", cleanup_code], stdout=PIPE, stderr=PIPE)
554+
run(["php", helper, "remove", "zz_fake_second_app"], stdout=PIPE, stderr=PIPE)
568555

569556
print("OK")
570557

0 commit comments

Comments
 (0)