forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.test.ts
More file actions
245 lines (220 loc) · 8.74 KB
/
command.test.ts
File metadata and controls
245 lines (220 loc) · 8.74 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { Command, CommandText } from '../../src/odo/command';
import { getInstance } from '../../src/odo';
import { KubeConfig } from '@kubernetes/client-node';
import { ComponentKind } from '../../src/odo/componentType';
import * as tmp from 'tmp';
import { extensions } from 'vscode';
import cp = require('child_process');
const ODO = getInstance();
const kc = new KubeConfig();
kc.loadFromDefault();
const newProjectName = `project${Math.round(Math.random() * 1000)}`;
const newAppName = 'integration';
// devfileTypeName = 'nodejs';
async function clone(repositoryURL: string, location: string): Promise<void> {
const gitExtension = extensions.getExtension('vscode.git').exports;
const git = gitExtension.getAPI(1).git.path;
// run 'git clone url location' as external process and return location
return new Promise((resolve, reject) => cp.exec(`${git} clone ${repositoryURL} ${location}`, (error: cp.ExecException) => error ? reject(error) : resolve()));
}
// tests are assuming your current context is already pointing to test cluster
suite('odo commands integration', () => {
test('odoLoginWithUsernamePassword()', () => {
return ODO.execute(
Command.odoLoginWithUsernamePassword(
kc.getCurrentCluster().server,
'developer',
'developer'
)
)
});
test('listProjects()', () => {
// test is assuming your current context is aready pointing to test cluster
return ODO.execute(
Command.listProjects()
)
});
test('listApplications()', () => {
// test is assuming your current context is aready pointing to test cluster
return ODO.execute(
new CommandText('odo project get -o json')
).then(result => {
return JSON.parse(result.stdout).metadata.name;
}).then(project => {
return ODO.execute(
Command.listApplications(project)
);
});
});
test('createProject()', ()=> {
return ODO.execute(
Command.createProject(newProjectName)
);
});
test('deleteProject()', ()=> {
return ODO.execute(
Command.deleteProject(newProjectName)
);
});
test('listRegistries()', ()=> {
return ODO.execute(
Command.listRegistries()
);
});
test('listCatalogComponents()', ()=> {
return ODO.execute(
Command.listCatalogComponents()
);
});
test('listCatalogComponentsJson()', ()=> {
return ODO.execute(
Command.listCatalogComponentsJson()
);
});
test('listCatalogServices()', ()=> {
return ODO.execute(
Command.listCatalogServices()
);
});
test('listCatalogServicesJson()', ()=> {
return ODO.execute(
Command.listCatalogServicesJson()
);
});
test('printOcVersion()', ()=> {
return ODO.execute(
Command.printOcVersion()
);
});
test('printOdoVersion()', ()=> {
return ODO.execute(
Command.printOdoVersion()
);
});
test('showServerUrl()', () => {
return ODO.execute(
Command.showServerUrl()
);
});
test('showConsoleUrl()', async function() {
const canI = await ODO.execute(
new CommandText('oc auth can-i get configmap --namespace openshift-config-managed'),
undefined,
false
).then(result => {
return !result.stdout.startsWith('no')
});
if (!canI) {
this.skip();
} else {
await ODO.execute(
Command.showConsoleUrl()
);
}
});
test('getClusterVersion()', async function() {
const clusterVersionExists = await ODO.execute(
new CommandText('oc api-resources --verbs=list -o name')
).then((resNames) => {
return resNames.stdout.includes('clusterversion');
});
if (!clusterVersionExists) {
this.skip();
} else {
await ODO.execute(
Command.getclusterVersion()
);
}
});
test('describeCatalogComponent()', async function () {
const types = await ODO.getComponentTypes();
const devfileCompType = types.find((compType) => compType.type === ComponentKind.DEVFILE);
if (!devfileCompType) {
this.skip();
} else {
await ODO.execute(Command.describeCatalogComponent(devfileCompType.name));
}
});
test('setOpenShiftContext', async () => {
await ODO.execute(Command.setOpenshiftContext(kc.currentContext));
});
suite('s2i', () => {
const project = kc.getContextObject(kc.getCurrentContext()).namespace;
const newNodeJsComponent = 'nodejs-local-app';
const componentLocation = tmp.dirSync().name;
const newUrlName = 'new-url-name';
const newUrlNameSecure = 'new-url-name-secure';
const newStorageName = 'new-sorage-name';
const nodeJsExGitUrl = 'https://github.com/sclorg/nodejs-ex.git';
test('createLocalComponent()', async () => {
await clone(nodeJsExGitUrl, componentLocation);
await ODO.execute(
Command.createLocalComponent(
project,
newAppName,
'nodejs',
'latest',
undefined,
newNodeJsComponent,
componentLocation
)
);
});
test('describeApplication', async () => {
await ODO.execute(Command.describeApplication(project, newAppName));
});
test('listComponents()', async () => {
await ODO.execute(Command.listComponents(project, newAppName));
});
test('createComponentCustomUrl(unsecure)', async () => {
await ODO.execute(Command.createComponentCustomUrl(newUrlName, '8080', false), componentLocation);
});
test('createComponentCustomUrl(secure)', async () => {
await ODO.execute(Command.createComponentCustomUrl(newUrlNameSecure, '8080', true), componentLocation);
});
test('createStorage(1)', async () => {
await ODO.execute(Command.createStorage(`${newStorageName}1`, '/mnt/storage1', '1Gi'), componentLocation);
});
test('createStorage(2)', async () => {
await ODO.execute(Command.createStorage(`${newStorageName}2`, '/mnt/storage2', '1Gi'), componentLocation);
});
test('listStorageNames()', async () => {
await ODO.execute(Command.listStorageNames(), componentLocation);
});
test('describeComponentJson()', async () => {
await ODO.execute(Command.describeComponentJson(),componentLocation);
});
test('describeComponentNoContextJson()', async () => {
await ODO.execute(Command.describeComponentNoContextJson(project, newAppName, newNodeJsComponent),tmp.dirSync().name);
});
test('pushComponent()', async () => {
await ODO.execute(Command.pushComponent(), componentLocation);
});
test('showLog()', async () => {
await ODO.execute(Command.showLog(), componentLocation);
});
test('createComponentCustomUrl(secure)', async () => {
await ODO.execute(Command.createComponentCustomUrl(`${newUrlNameSecure}2`, '8080', true), componentLocation);
});
test('pushComponent(config, debug)', async () => {
await ODO.execute(Command.pushComponent(true, true), componentLocation);
});
test('deleteComponentUrl', async () => {
await ODO.execute(Command.deleteComponentUrl(newUrlName),componentLocation);
});
test('undeployComponent', async () => {
await ODO.execute(Command.undeployComponent(project, newAppName, newNodeJsComponent), componentLocation);
});
test('deleteStorage()', async () => {
await ODO.execute(Command.deleteStorage(`${newStorageName}1`), componentLocation);
await ODO.execute(Command.waitForStorageToBeGone(project, newAppName, `${newStorageName}1`), componentLocation)
});
test('deleteComponent', async () => {
await ODO.execute(Command.deleteComponent(project, newAppName, newNodeJsComponent, true), componentLocation);
});
});
});