-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathDockerActionsTest.php
More file actions
102 lines (81 loc) · 3.13 KB
/
Copy pathDockerActionsTest.php
File metadata and controls
102 lines (81 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AppAPI\Tests\php\DeployActions;
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\DeployActions\DockerActions;
use OCA\AppAPI\Service\AppAPICommonService;
use OCA\AppAPI\Service\ExAppDeployOptionsService;
use OCA\AppAPI\Service\ExAppService;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\ITempManager;
use OCP\IURLGenerator;
use OCP\Security\ICrypto;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class DockerActionsTest extends TestCase {
private DockerActions $dockerActions;
private IAppConfig&MockObject $appConfig;
protected function setUp(): void {
parent::setUp();
$this->appConfig = $this->createMock(IAppConfig::class);
$this->dockerActions = new DockerActions(
$this->createMock(LoggerInterface::class),
$this->appConfig,
$this->createMock(IConfig::class),
$this->createMock(ICertificateManager::class),
$this->createMock(IAppManager::class),
$this->createMock(IURLGenerator::class),
$this->createMock(AppAPICommonService::class),
$this->createMock(ExAppService::class),
$this->createMock(ITempManager::class),
$this->createMock(ICrypto::class),
$this->createMock(ExAppDeployOptionsService::class),
);
}
public function testGetDockerApiVersionReturnsDefaultWhenNoConfigSet(): void {
$this->appConfig->expects(self::once())
->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('');
self::assertSame(DockerActions::DOCKER_API_VERSION, $this->dockerActions->getDockerApiVersion());
}
public function testGetDockerApiVersionReturnsCustomVersionFromConfig(): void {
$this->appConfig->expects(self::once())
->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.43');
self::assertSame('v1.43', $this->dockerActions->getDockerApiVersion());
}
public function testBuildApiUrlUsesDefaultVersion(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('');
$url = $this->dockerActions->buildApiUrl('http://localhost', '_ping');
self::assertSame('http://localhost/' . DockerActions::DOCKER_API_VERSION . '/_ping', $url);
}
public function testBuildApiUrlUsesCustomVersion(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.43');
$url = $this->dockerActions->buildApiUrl('http://localhost', '_ping');
self::assertSame('http://localhost/v1.43/_ping', $url);
}
public function testBuildApiUrlWithContainerRoute(): void {
$this->appConfig->method('getValueString')
->with(Application::APP_ID, 'docker_api_version', '', true)
->willReturn('v1.41');
$url = $this->dockerActions->buildApiUrl(
'http://localhost:8780',
sprintf('containers/%s/json', 'nc_app_test')
);
self::assertSame('http://localhost:8780/v1.41/containers/nc_app_test/json', $url);
}
}