-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathGitLabTest.php
More file actions
223 lines (178 loc) · 6.25 KB
/
GitLabTest.php
File metadata and controls
223 lines (178 loc) · 6.25 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
namespace Utopia\Tests\Adapter;
use Utopia\Cache\Adapter\None;
use Utopia\Cache\Cache;
use Utopia\System\System;
use Utopia\Tests\Base;
use Utopia\VCS\Adapter\Git;
use Utopia\VCS\Adapter\Git\GitLab;
class GitLabTest extends Base
{
protected static string $accessToken = '';
protected static string $owner = '';
protected static string $defaultBranch = 'main';
protected function createVCSAdapter(): Git
{
return new GitLab(new Cache(new None()));
}
public function setUp(): void
{
if (empty(static::$accessToken)) {
$this->setupGitLab();
}
if (empty(static::$accessToken)) {
$this->markTestSkipped('GitLab access token not available');
}
$adapter = new GitLab(new Cache(new None()));
$gitlabUrl = System::getEnv('TESTS_GITLAB_URL', 'http://gitlab:80');
$adapter->initializeVariables(
installationId: '',
privateKey: '',
appId: '',
accessToken: static::$accessToken,
refreshToken: ''
);
$adapter->setEndpoint($gitlabUrl);
if (empty(static::$owner)) {
$orgName = 'test-org-' . \uniqid();
static::$owner = $adapter->createOrganization($orgName);
}
$this->vcsAdapter = $adapter;
}
protected function setupGitLab(): void
{
$tokenFile = '/gitlab-data/token.txt';
if (file_exists($tokenFile)) {
$contents = file_get_contents($tokenFile);
if ($contents !== false) {
static::$accessToken = trim($contents);
}
}
}
public function testCreateRepository(): void
{
$repositoryName = 'test-create-repository-' . \uniqid();
$result = $this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
try {
$this->assertIsArray($result);
$this->assertArrayHasKey('name', $result);
$this->assertSame($repositoryName, $result['name']);
$this->assertFalse($result['visibility'] === 'private');
$this->assertArrayHasKey('pushed_at', $result);
$this->assertNotFalse(\strtotime($result['pushed_at']));
} finally {
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
}
}
public function testGetRepository(): void
{
$repositoryName = 'test-get-repository-' . \uniqid();
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
try {
$result = $this->vcsAdapter->getRepository(static::$owner, $repositoryName);
$this->assertIsArray($result);
$this->assertSame($repositoryName, $result['name']);
$this->assertArrayHasKey('pushed_at', $result);
$this->assertNotFalse(\strtotime($result['pushed_at']));
} finally {
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
}
}
public function testDeleteRepository(): void
{
$repositoryName = 'test-delete-repository-' . \uniqid();
$this->vcsAdapter->createRepository(static::$owner, $repositoryName, false);
$result = $this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
$this->assertTrue($result);
}
public function testGetDeletedRepositoryFails(): void
{
$repositoryName = 'non-existing-repository-' . \uniqid();
$this->expectException(\Exception::class);
$this->vcsAdapter->getRepository(static::$owner, $repositoryName);
}
public function testGetPullRequestFromBranch(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetOwnerName(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testSearchRepositories(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testCreateComment(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testUpdateComment(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGenerateCloneCommand(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGenerateCloneCommandWithCommitHash(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGenerateCloneCommandWithTag(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGenerateCloneCommandWithInvalidRepository(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testWebhookPushEvent(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testWebhookPullRequestEvent(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetEventPush(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetRepositoryName(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetComment(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetPullRequest(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetPullRequestFiles(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetPullRequestWithInvalidNumber(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testGetRepositoryTree(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testListBranches(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testListRepositoryLanguages(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
public function testListRepositoryContents(): void
{
$this->markTestSkipped('Not implemented for GitLab yet');
}
}