@eclipse-che/che-e2e 7.74.0-dev-1d09cb7 → 7.74.0-dev-aace77a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/.eslintignore +10 -0
  2. package/.eslintrc.js +197 -0
  3. package/.prettierignore +10 -0
  4. package/.prettierrc.json +10 -0
  5. package/CODE_STYLE.md +144 -0
  6. package/README.md +47 -47
  7. package/configs/inversify.config.ts +39 -14
  8. package/configs/inversify.types.ts +44 -30
  9. package/configs/mocharc.ts +21 -24
  10. package/constants/API_TEST_CONSTANTS.ts +67 -0
  11. package/constants/BASE_TEST_CONSTANTS.ts +80 -0
  12. package/constants/CHROME_DRIVER_CONSTANTS.ts +42 -0
  13. package/constants/FACTORY_TEST_CONSTANTS.ts +61 -0
  14. package/constants/MONACO_CONSTANTS.ts +25 -0
  15. package/constants/OAUTH_CONSTANTS.ts +67 -0
  16. package/constants/PLUGIN_TEST_CONSTANTS.ts +15 -0
  17. package/constants/REPORTER_CONSTANTS.ts +53 -0
  18. package/constants/TIMEOUT_CONSTANTS.ts +131 -0
  19. package/dist/configs/inversify.config.js +36 -9
  20. package/dist/configs/inversify.config.js.map +1 -1
  21. package/dist/configs/inversify.types.js +19 -5
  22. package/dist/configs/inversify.types.js.map +1 -1
  23. package/dist/configs/mocharc.js +13 -16
  24. package/dist/configs/mocharc.js.map +1 -1
  25. package/dist/constants/{APITestConstants.js → API_TEST_CONSTANTS.js} +12 -12
  26. package/dist/constants/API_TEST_CONSTANTS.js.map +1 -0
  27. package/dist/constants/{BaseTestConstants.js → BASE_TEST_CONSTANTS.js} +16 -16
  28. package/dist/constants/BASE_TEST_CONSTANTS.js.map +1 -0
  29. package/dist/constants/CHROME_DRIVER_CONSTANTS.js +36 -0
  30. package/dist/constants/CHROME_DRIVER_CONSTANTS.js.map +1 -0
  31. package/dist/constants/{FactoryTestConstants.js → FACTORY_TEST_CONSTANTS.js} +14 -13
  32. package/dist/constants/FACTORY_TEST_CONSTANTS.js.map +1 -0
  33. package/dist/constants/{MonacoConstants.js → MONACO_CONSTANTS.js} +7 -7
  34. package/dist/constants/MONACO_CONSTANTS.js.map +1 -0
  35. package/dist/constants/{OAuthConstants.js → OAUTH_CONSTANTS.js} +14 -14
  36. package/dist/constants/OAUTH_CONSTANTS.js.map +1 -0
  37. package/dist/constants/{PluginsTestConstants.js → PLUGIN_TEST_CONSTANTS.js} +7 -7
  38. package/dist/constants/PLUGIN_TEST_CONSTANTS.js.map +1 -0
  39. package/dist/constants/{ReporterConstants.js → REPORTER_CONSTANTS.js} +12 -12
  40. package/dist/constants/REPORTER_CONSTANTS.js.map +1 -0
  41. package/dist/constants/{TimeoutConstants.js → TIMEOUT_CONSTANTS.js} +24 -24
  42. package/dist/constants/TIMEOUT_CONSTANTS.js.map +1 -0
  43. package/dist/driver/ChromeDriver.js +12 -22
  44. package/dist/driver/ChromeDriver.js.map +1 -1
  45. package/dist/index.js +18 -12
  46. package/dist/index.js.map +1 -1
  47. package/dist/pageobjects/dashboard/CreateWorkspace.js +15 -15
  48. package/dist/pageobjects/dashboard/CreateWorkspace.js.map +1 -1
  49. package/dist/pageobjects/dashboard/Dashboard.js +20 -21
  50. package/dist/pageobjects/dashboard/Dashboard.js.map +1 -1
  51. package/dist/pageobjects/dashboard/Workspaces.js +55 -60
  52. package/dist/pageobjects/dashboard/Workspaces.js.map +1 -1
  53. package/dist/pageobjects/dashboard/workspace-details/WorkspaceDetails.js +58 -48
  54. package/dist/pageobjects/dashboard/workspace-details/WorkspaceDetails.js.map +1 -1
  55. package/dist/pageobjects/git-providers/OauthPage.js +22 -20
  56. package/dist/pageobjects/git-providers/OauthPage.js.map +1 -1
  57. package/dist/pageobjects/ide/CheCodeLocatorLoader.js +26 -12
  58. package/dist/pageobjects/ide/CheCodeLocatorLoader.js.map +1 -1
  59. package/dist/pageobjects/login/interfaces/ICheLoginPage.js +2 -2
  60. package/dist/pageobjects/login/interfaces/IOcpLoginPage.js +2 -2
  61. package/dist/pageobjects/login/kubernetes/DexLoginPage.js +14 -14
  62. package/dist/pageobjects/login/kubernetes/DexLoginPage.js.map +1 -1
  63. package/dist/pageobjects/login/kubernetes/KubernetesLoginPage.js +7 -7
  64. package/dist/pageobjects/login/kubernetes/KubernetesLoginPage.js.map +1 -1
  65. package/dist/pageobjects/login/openshift/OcpLoginPage.js +24 -28
  66. package/dist/pageobjects/login/openshift/OcpLoginPage.js.map +1 -1
  67. package/dist/pageobjects/login/openshift/OcpRedHatLoginPage.js +13 -16
  68. package/dist/pageobjects/login/openshift/OcpRedHatLoginPage.js.map +1 -1
  69. package/dist/pageobjects/login/openshift/OcpUserLoginPage.js +9 -9
  70. package/dist/pageobjects/login/openshift/OcpUserLoginPage.js.map +1 -1
  71. package/dist/pageobjects/login/openshift/RedHatLoginPage.js +19 -23
  72. package/dist/pageobjects/login/openshift/RedHatLoginPage.js.map +1 -1
  73. package/dist/pageobjects/login/openshift/RegularUserOcpCheLoginPage.js +20 -19
  74. package/dist/pageobjects/login/openshift/RegularUserOcpCheLoginPage.js.map +1 -1
  75. package/dist/pageobjects/openshift/OcpApplicationPage.js +11 -11
  76. package/dist/pageobjects/openshift/OcpApplicationPage.js.map +1 -1
  77. package/dist/pageobjects/openshift/OcpImportFromGitPage.js +24 -24
  78. package/dist/pageobjects/openshift/OcpImportFromGitPage.js.map +1 -1
  79. package/dist/pageobjects/openshift/OcpMainPage.js +30 -30
  80. package/dist/pageobjects/openshift/OcpMainPage.js.map +1 -1
  81. package/dist/specs/MochaHooks.js +33 -27
  82. package/dist/specs/MochaHooks.js.map +1 -1
  83. package/dist/specs/SmokeTest.spec.js +17 -17
  84. package/dist/specs/SmokeTest.spec.js.map +1 -1
  85. package/dist/specs/api/ContainerOverridesAPI.spec.js +8 -6
  86. package/dist/specs/api/ContainerOverridesAPI.spec.js.map +1 -1
  87. package/dist/specs/api/DevfileAcceptanceTestAPI.spec.js +27 -24
  88. package/dist/specs/api/DevfileAcceptanceTestAPI.spec.js.map +1 -1
  89. package/dist/specs/api/EmptyWorkspaceAPI.spec.js +17 -17
  90. package/dist/specs/api/EmptyWorkspaceAPI.spec.js.map +1 -1
  91. package/dist/specs/api/PodOverridesAPI.spec.js +10 -8
  92. package/dist/specs/api/PodOverridesAPI.spec.js.map +1 -1
  93. package/dist/specs/dashboard-samples/EmptyWorkspace.spec.js +10 -10
  94. package/dist/specs/dashboard-samples/EmptyWorkspace.spec.js.map +1 -1
  95. package/dist/specs/dashboard-samples/Quarkus.spec.js +13 -13
  96. package/dist/specs/dashboard-samples/Quarkus.spec.js.map +1 -1
  97. package/dist/specs/dashboard-samples/RecommendedExtensions.spec.js +52 -52
  98. package/dist/specs/dashboard-samples/RecommendedExtensions.spec.js.map +1 -1
  99. package/dist/specs/devconsole-intergration/DevConsoleIntegration.spec.js +23 -19
  100. package/dist/specs/devconsole-intergration/DevConsoleIntegration.spec.js.map +1 -1
  101. package/dist/specs/factory/Factory.spec.js +38 -41
  102. package/dist/specs/factory/Factory.spec.js.map +1 -1
  103. package/dist/specs/factory/NoSetupRepoFactory.spec.js +52 -50
  104. package/dist/specs/factory/NoSetupRepoFactory.spec.js.map +1 -1
  105. package/dist/specs/factory/RefusedOAuthFactory.spec.js +49 -51
  106. package/dist/specs/factory/RefusedOAuthFactory.spec.js.map +1 -1
  107. package/dist/specs/miscellaneous/PredefinedNamespace.spec.js +45 -42
  108. package/dist/specs/miscellaneous/PredefinedNamespace.spec.js.map +1 -1
  109. package/dist/tests-library/LoginTests.js +13 -13
  110. package/dist/tests-library/LoginTests.js.map +1 -1
  111. package/dist/tests-library/ProjectAndFileTests.js +9 -7
  112. package/dist/tests-library/ProjectAndFileTests.js.map +1 -1
  113. package/dist/tests-library/WorkspaceHandlingTests.js +22 -19
  114. package/dist/tests-library/WorkspaceHandlingTests.js.map +1 -1
  115. package/dist/utils/BrowserTabsUtil.js +21 -21
  116. package/dist/utils/BrowserTabsUtil.js.map +1 -1
  117. package/dist/utils/CheReporter.js +91 -65
  118. package/dist/utils/CheReporter.js.map +1 -1
  119. package/dist/utils/DevWorkspaceConfigurationHelper.js +34 -15
  120. package/dist/utils/DevWorkspaceConfigurationHelper.js.map +1 -1
  121. package/dist/utils/DevfilesRegistryHelper.js +34 -18
  122. package/dist/utils/DevfilesRegistryHelper.js.map +1 -1
  123. package/dist/utils/DriverHelper.js +73 -68
  124. package/dist/utils/DriverHelper.js.map +1 -1
  125. package/dist/utils/IContextParams.js +12 -0
  126. package/dist/utils/IContextParams.js.map +1 -0
  127. package/dist/utils/IKubernetesCommandLineToolsExecutor.js +3 -0
  128. package/dist/utils/IKubernetesCommandLineToolsExecutor.js.map +1 -0
  129. package/dist/utils/KubernetesCommandLineToolsExecutor.js +146 -107
  130. package/dist/utils/KubernetesCommandLineToolsExecutor.js.map +1 -1
  131. package/dist/utils/Logger.js +18 -19
  132. package/dist/utils/Logger.js.map +1 -1
  133. package/dist/utils/ScreenCatcher.js +26 -16
  134. package/dist/utils/ScreenCatcher.js.map +1 -1
  135. package/dist/utils/ShellExecutor.js +29 -9
  136. package/dist/utils/ShellExecutor.js.map +1 -1
  137. package/dist/utils/StringUtil.js +19 -9
  138. package/dist/utils/StringUtil.js.map +1 -1
  139. package/dist/utils/request-handlers/CheApiRequestHandler.js +29 -29
  140. package/dist/utils/request-handlers/CheApiRequestHandler.js.map +1 -1
  141. package/dist/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.js +12 -8
  142. package/dist/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.js.map +1 -1
  143. package/dist/utils/request-handlers/headers/IAuthorizationHeaderHandler.js +2 -2
  144. package/dist/utils/workspace/ApiUrlResolver.js +5 -5
  145. package/dist/utils/workspace/ApiUrlResolver.js.map +1 -1
  146. package/dist/utils/workspace/ITestWorkspaceUtil.js +2 -2
  147. package/dist/utils/workspace/TestWorkspaceUtil.js +25 -23
  148. package/dist/utils/workspace/TestWorkspaceUtil.js.map +1 -1
  149. package/dist/utils/workspace/WorkspaceStatus.js +2 -2
  150. package/dist/utils/workspace/WorkspaceStatus.js.map +1 -1
  151. package/driver/ChromeDriver.ts +45 -58
  152. package/driver/IDriver.ts +3 -3
  153. package/index.ts +11 -9
  154. package/package.json +59 -49
  155. package/pageobjects/dashboard/CreateWorkspace.ts +65 -55
  156. package/pageobjects/dashboard/Dashboard.ts +100 -100
  157. package/pageobjects/dashboard/Workspaces.ts +210 -186
  158. package/pageobjects/dashboard/workspace-details/WorkspaceDetails.ts +153 -131
  159. package/pageobjects/git-providers/OauthPage.ts +177 -166
  160. package/pageobjects/ide/CheCodeLocatorLoader.ts +51 -46
  161. package/pageobjects/login/interfaces/ICheLoginPage.ts +3 -3
  162. package/pageobjects/login/interfaces/IOcpLoginPage.ts +3 -3
  163. package/pageobjects/login/kubernetes/DexLoginPage.ts +31 -30
  164. package/pageobjects/login/kubernetes/KubernetesLoginPage.ts +15 -14
  165. package/pageobjects/login/openshift/OcpLoginPage.ts +51 -56
  166. package/pageobjects/login/openshift/OcpRedHatLoginPage.ts +27 -27
  167. package/pageobjects/login/openshift/OcpUserLoginPage.ts +15 -18
  168. package/pageobjects/login/openshift/RedHatLoginPage.ts +49 -46
  169. package/pageobjects/login/openshift/RegularUserOcpCheLoginPage.ts +43 -34
  170. package/pageobjects/openshift/OcpApplicationPage.ts +21 -19
  171. package/pageobjects/openshift/OcpImportFromGitPage.ts +68 -68
  172. package/pageobjects/openshift/OcpMainPage.ts +69 -69
  173. package/specs/MochaHooks.ts +59 -52
  174. package/specs/SmokeTest.spec.ts +47 -45
  175. package/specs/api/ContainerOverridesAPI.spec.ts +39 -26
  176. package/specs/api/DevfileAcceptanceTestAPI.spec.ts +110 -97
  177. package/specs/api/EmptyWorkspaceAPI.spec.ts +67 -58
  178. package/specs/api/PodOverridesAPI.spec.ts +48 -34
  179. package/specs/dashboard-samples/EmptyWorkspace.spec.ts +36 -36
  180. package/specs/dashboard-samples/Quarkus.spec.ts +41 -40
  181. package/specs/dashboard-samples/RecommendedExtensions.spec.ts +202 -183
  182. package/specs/devconsole-intergration/DevConsoleIntegration.spec.ts +85 -75
  183. package/specs/factory/Factory.spec.ts +184 -178
  184. package/specs/factory/NoSetupRepoFactory.spec.ts +233 -219
  185. package/specs/factory/RefusedOAuthFactory.spec.ts +223 -211
  186. package/specs/miscellaneous/PredefinedNamespace.spec.ts +70 -64
  187. package/tests-library/LoginTests.ts +34 -32
  188. package/tests-library/ProjectAndFileTests.ts +21 -18
  189. package/tests-library/WorkspaceHandlingTests.ts +98 -89
  190. package/tsconfig.json +15 -15
  191. package/utils/BrowserTabsUtil.ts +78 -74
  192. package/utils/CheReporter.ts +159 -157
  193. package/utils/DevWorkspaceConfigurationHelper.ts +63 -69
  194. package/utils/DevfilesRegistryHelper.ts +71 -57
  195. package/utils/DriverHelper.ts +728 -700
  196. package/utils/IContextParams.ts +26 -0
  197. package/utils/IKubernetesCommandLineToolsExecutor.ts +42 -0
  198. package/utils/KubernetesCommandLineToolsExecutor.ts +231 -183
  199. package/utils/Logger.ts +102 -125
  200. package/utils/ScreenCatcher.ts +57 -46
  201. package/utils/ShellExecutor.ts +23 -12
  202. package/utils/StringUtil.ts +49 -36
  203. package/utils/request-handlers/CheApiRequestHandler.ts +91 -88
  204. package/utils/request-handlers/headers/CheMultiuserAuthorizationHeaderHandler.ts +32 -21
  205. package/utils/request-handlers/headers/IAuthorizationHeaderHandler.ts +3 -3
  206. package/utils/workspace/ApiUrlResolver.ts +31 -26
  207. package/utils/workspace/ITestWorkspaceUtil.ts +31 -31
  208. package/utils/workspace/TestWorkspaceUtil.ts +152 -145
  209. package/utils/workspace/WorkspaceStatus.ts +5 -5
  210. package/constants/APITestConstants.ts +0 -57
  211. package/constants/BaseTestConstants.ts +0 -68
  212. package/constants/ChromeDriverConstants.ts +0 -46
  213. package/constants/FactoryTestConstants.ts +0 -51
  214. package/constants/MonacoConstants.ts +0 -22
  215. package/constants/OAuthConstants.ts +0 -57
  216. package/constants/PluginsTestConstants.ts +0 -15
  217. package/constants/ReporterConstants.ts +0 -45
  218. package/constants/TimeoutConstants.ts +0 -113
  219. package/dist/constants/APITestConstants.js.map +0 -1
  220. package/dist/constants/BaseTestConstants.js.map +0 -1
  221. package/dist/constants/ChromeDriverConstants.js +0 -44
  222. package/dist/constants/ChromeDriverConstants.js.map +0 -1
  223. package/dist/constants/FactoryTestConstants.js.map +0 -1
  224. package/dist/constants/MonacoConstants.js.map +0 -1
  225. package/dist/constants/OAuthConstants.js.map +0 -1
  226. package/dist/constants/PluginsTestConstants.js.map +0 -1
  227. package/dist/constants/ReporterConstants.js.map +0 -1
  228. package/dist/constants/TimeoutConstants.js.map +0 -1
  229. package/tslint.json +0 -126
@@ -0,0 +1,26 @@
1
+ /** *******************************************************************
2
+ * copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ **********************************************************************/
10
+
11
+ export interface IContextParams {
12
+ devfilePath?: string | undefined;
13
+ devfileUrl?: string | undefined;
14
+ devfileContent?: string | undefined;
15
+ outputFile?: string | undefined;
16
+ editorPath?: string | undefined;
17
+ editorContent?: string | undefined;
18
+ editorEntry?: string | undefined;
19
+ pluginRegistryUrl?: string | undefined;
20
+ projects?: {
21
+ name: string;
22
+ location: string;
23
+ }[];
24
+ injectDefaultComponent?: string | undefined;
25
+ defaultComponentImage?: string | undefined;
26
+ }
@@ -0,0 +1,42 @@
1
+ /** *******************************************************************
2
+ * copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ **********************************************************************/
10
+ import { ShellString } from 'shelljs';
11
+
12
+ export interface IKubernetesCommandLineToolsExecutor {
13
+ loginToOcp(): void;
14
+
15
+ getContainerName(): string;
16
+
17
+ getWorkspacePodName(): string;
18
+
19
+ deleteDevWorkspace(): void;
20
+
21
+ applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString;
22
+
23
+ executeCommand(commandToExecute: string, container: string): ShellString;
24
+
25
+ applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString;
26
+
27
+ applyYamlConfigurationAsFile(pathToFile: string): void;
28
+
29
+ getDevWorkspaceYamlConfiguration(): ShellString;
30
+
31
+ waitDevWorkspace(timeout: number): ShellString;
32
+
33
+ createProject(projectName: string): void;
34
+
35
+ deleteProject(projectName: string): void;
36
+
37
+ getPodAndContainerNames(): void;
38
+
39
+ isUserLoggedIn(user: string): boolean;
40
+
41
+ getServerUrl(): string;
42
+ }
@@ -1,190 +1,238 @@
1
+ /** *******************************************************************
2
+ * copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ **********************************************************************/
1
10
  import { echo, exec, ShellString } from 'shelljs';
2
11
  import { Logger } from './Logger';
3
12
  import { ShellExecutor } from './ShellExecutor';
4
13
  import * as path from 'path';
5
- import { APITestConstants, KubernetesCommandLineTool } from '../constants/APITestConstants';
6
- import { BaseTestConstants } from '../constants/BaseTestConstants';
7
- import { OAuthConstants } from '../constants/OAuthConstants';
8
-
9
- export class KubernetesCommandLineToolsExecutor extends ShellExecutor {
10
- private static container: string;
11
- private static pod: string;
12
- private readonly namespace: string;
13
- private readonly workspaceName: string | undefined;
14
- private readonly KUBERNETES_COMMAND_LINE_TOOL: string =
15
- APITestConstants.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL;
16
-
17
- constructor(_workspaceName?: string, _namespace?: string) {
18
- super();
19
- this.workspaceName = _workspaceName;
20
- this.namespace = this.setNamespace(_namespace);
21
- }
22
-
23
- get getWorkspaceName(): string {
24
- return <string>this.workspaceName;
25
- }
26
-
27
- get getNamespace(): string {
28
- return this.namespace;
29
- }
30
-
31
- // login to Openshift cluster with username and password
32
- loginToOcp(): void {
33
- if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.OC) {
34
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - login to the "OC" client.`);
35
- const url: string = this.getServerUrl();
36
- if (this.isUserLoggedIn()) {
37
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - user already logged`);
38
- } else {
39
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - login ${url}, ${OAuthConstants.TS_SELENIUM_OCP_USERNAME}`);
40
- exec(`oc login --server=${url} -u=${OAuthConstants.TS_SELENIUM_OCP_USERNAME} -p=${OAuthConstants.TS_SELENIUM_OCP_PASSWORD} --insecure-skip-tls-verify`);
41
- }
42
- } else {
43
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - doesn't support login command`);
44
- }
45
- }
46
-
47
- getContainerName(): string {
48
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get container name.`);
49
- const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get ${KubernetesCommandLineToolsExecutor.pod} -o jsonpath='{.spec.containers[*].name}' -n ${this.namespace}`);
50
- echo('\n');
51
- return output.stderr ? output.stderr : output.stdout;
52
- }
53
-
54
- getWorkspacePodName(): string {
55
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get workspace pod name.`);
56
- const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get pod -l controller.devfile.io/devworkspace_name=${this.workspaceName} -n ${this.namespace} -o name`);
57
- return output.stderr ? output.stderr : output.stdout.replace('\n', '');
58
- }
59
-
60
- deleteDevWorkspace(): void {
61
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - delete '${this.workspaceName}' workspace`);
62
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`);
63
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete dw ${this.workspaceName} -n ${this.namespace} || true`);
64
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete dwt ${BaseTestConstants.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`);
65
- }
66
-
67
- applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
68
- if (this.KUBERNETES_COMMAND_LINE_TOOL === KubernetesCommandLineTool.KUBECTL) {
69
- this.createNamespace();
70
- }
71
- this.applyYamlConfigurationAsStringOutput(yamlConfiguration);
72
- return this.waitDevWorkspace();
73
- }
74
-
75
- executeCommand(
76
- commandToExecute: string,
77
- container: string = KubernetesCommandLineToolsExecutor.container): ShellString {
78
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
79
- return ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`);
80
- }
81
-
82
- applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
83
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
84
- return ShellExecutor.execWithLog(`cat <<EOF | ${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f - \n` +
85
- yamlConfiguration +
86
- '\n' +
87
- 'EOF');
88
- }
89
-
90
- applyYamlConfigurationAsFile(pathToFile: string): void {
91
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
92
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} apply -n ${this.namespace} -f "${path.resolve(pathToFile)}"`);
93
- }
94
-
95
- getDevWorkspaceYamlConfiguration(): ShellString {
96
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL}`);
97
- return ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} get dw ${this.workspaceName} -n ${this.namespace} -o yaml`);
98
- }
99
-
100
- waitDevWorkspace(timeout: number = 360): ShellString {
101
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - wait till workspace ready.`);
102
- const output: ShellString = ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} wait -n ${this.namespace} --for=condition=Ready dw ${this.workspaceName} --timeout=${timeout}s`);
103
- this.getPodAndContainerNames();
104
- return output;
105
- }
106
-
107
- createNamespace(): void {
108
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - create namespace "${this.namespace}".`);
109
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} create namespace ${this.namespace}`);
110
- }
111
-
112
- createProject(projectName: string): void {
113
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - create new project "${projectName}".`);
114
- ShellExecutor.execWithLog(
115
- `${this.KUBERNETES_COMMAND_LINE_TOOL} new-project ${projectName} -n ${this.namespace}`
116
- );
117
- }
118
-
119
- deleteProject(projectName: string): void {
120
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - delete "${projectName}".`);
121
- ShellExecutor.execWithLog(`${this.KUBERNETES_COMMAND_LINE_TOOL} delete project ${projectName} -n ${this.namespace}`);
122
- }
123
-
124
- private getPodAndContainerNames(): void {
125
- KubernetesCommandLineToolsExecutor.pod = this.getWorkspacePodName();
126
- KubernetesCommandLineToolsExecutor.container = this.getContainerName();
127
- }
128
-
129
- private isUserLoggedIn(): boolean {
130
- const whoamiCommandOutput: ShellString = ShellExecutor.execWithLog('oc whoami && oc whoami --show-server=true');
131
-
132
- return (
133
- whoamiCommandOutput.stdout.includes(OAuthConstants.TS_SELENIUM_OCP_USERNAME) && whoamiCommandOutput.stdout.includes(this.getServerUrl()));
134
- }
135
-
136
- private setNamespace(_namespace: string | undefined): string {
137
- _namespace =
138
- _namespace !== undefined
139
- ? _namespace
140
- : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('devspaces')
141
- ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-devspaces'
142
- : BaseTestConstants.TS_SELENIUM_BASE_URL.includes('che')
143
- ? OAuthConstants.TS_SELENIUM_OCP_USERNAME + '-che'
144
- : 'default';
145
- return _namespace;
146
- }
147
-
148
- private getServerUrl(): string {
149
- Logger.debug(`${this.KUBERNETES_COMMAND_LINE_TOOL} - get server api url.`);
150
- return (BaseTestConstants.TS_SELENIUM_BASE_URL.replace('devspaces.apps', 'api') + ':6443');
151
- }
14
+ import { API_TEST_CONSTANTS, KubernetesCommandLineTool } from '../constants/API_TEST_CONSTANTS';
15
+ import { BASE_TEST_CONSTANTS } from '../constants/BASE_TEST_CONSTANTS';
16
+ import { OAUTH_CONSTANTS } from '../constants/OAUTH_CONSTANTS';
17
+ import { IKubernetesCommandLineToolsExecutor } from './IKubernetesCommandLineToolsExecutor';
18
+ import { inject, injectable } from 'inversify';
19
+ import { CLASSES } from '../configs/inversify.types';
20
+
21
+ @injectable()
22
+ export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLineToolsExecutor {
23
+ private static container: string;
24
+ private static pod: string;
25
+ private readonly kubernetesCommandLineTool: string;
26
+ protected _namespace: string | undefined;
27
+ protected _workspaceName: string | undefined;
28
+
29
+ constructor(
30
+ @inject(CLASSES.ShellExecutor)
31
+ protected readonly shellExecutor: ShellExecutor
32
+ ) {
33
+ this.kubernetesCommandLineTool = API_TEST_CONSTANTS.TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL;
34
+ }
35
+
36
+ set namespace(value: string | undefined) {
37
+ this._namespace = value;
38
+ }
39
+
40
+ set workspaceName(value: string | undefined) {
41
+ this._workspaceName = value;
42
+ }
43
+
44
+ get workspaceName(): string | undefined {
45
+ return this._workspaceName;
46
+ }
47
+
48
+ get namespace(): string | undefined {
49
+ this._namespace =
50
+ this._namespace !== undefined
51
+ ? this._namespace
52
+ : BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('devspaces')
53
+ ? OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME + '-devspaces'
54
+ : BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.includes('che')
55
+ ? OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME + '-che'
56
+ : 'default';
57
+ return this._namespace;
58
+ }
59
+
60
+ // login to Openshift cluster with username and password
61
+ loginToOcp(user: string = OAUTH_CONSTANTS.TS_SELENIUM_OCP_USERNAME, password: string = OAUTH_CONSTANTS.TS_SELENIUM_OCP_PASSWORD): void {
62
+ if (this.kubernetesCommandLineTool === KubernetesCommandLineTool.OC) {
63
+ Logger.debug(`${this.kubernetesCommandLineTool} - login to the "OC" client.`);
64
+ const url: string = this.getServerUrl();
65
+ if (this.isUserLoggedIn(user)) {
66
+ Logger.debug(`${this.kubernetesCommandLineTool} - user already logged`);
67
+ } else {
68
+ Logger.debug(`${this.kubernetesCommandLineTool} - login ${url}, ${user}`);
69
+ exec(`oc login --server=${url} -u=${user} -p=${password} --insecure-skip-tls-verify`);
70
+ }
71
+ } else {
72
+ Logger.debug(`${this.kubernetesCommandLineTool} - doesn't support login command`);
73
+ }
74
+ }
75
+
76
+ getContainerName(): string {
77
+ Logger.debug(`${this.kubernetesCommandLineTool} - get container name.`);
78
+
79
+ const output: ShellString = this.shellExecutor.executeCommand(
80
+ `${this.kubernetesCommandLineTool} get ${KubernetesCommandLineToolsExecutor.pod} -o jsonpath='{.spec.containers[*].name}' -n ${this.namespace}`
81
+ );
82
+ echo('\n');
83
+ return output.stderr ? output.stderr : output.stdout;
84
+ }
85
+
86
+ getWorkspacePodName(): string {
87
+ Logger.debug(`${this.kubernetesCommandLineTool} - get workspace pod name.`);
88
+
89
+ const output: ShellString = this.shellExecutor.executeCommand(
90
+ `${this.kubernetesCommandLineTool} get pod -l controller.devfile.io/devworkspace_name=${this.workspaceName} -n ${this.namespace} -o name`
91
+ );
92
+ return output.stderr ? output.stderr : output.stdout.replace('\n', '');
93
+ }
94
+
95
+ deleteDevWorkspace(): void {
96
+ Logger.debug(`${this.kubernetesCommandLineTool} - delete '${this.workspaceName}' workspace`);
97
+
98
+ this.shellExecutor.executeCommand(
99
+ `${this.kubernetesCommandLineTool} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`
100
+ );
101
+ this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} delete dw ${this.workspaceName} -n ${this.namespace} || true`);
102
+ this.shellExecutor.executeCommand(
103
+ `${this.kubernetesCommandLineTool} delete dwt ${BASE_TEST_CONSTANTS.TS_SELENIUM_EDITOR}-${this.workspaceName} -n ${this.namespace} || true`
104
+ );
105
+ }
106
+
107
+ applyAndWaitDevWorkspace(yamlConfiguration: string): ShellString {
108
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
109
+
110
+ if (this.kubernetesCommandLineTool === KubernetesCommandLineTool.KUBECTL) {
111
+ this.createNamespace();
112
+ }
113
+ this.applyYamlConfigurationAsStringOutput(yamlConfiguration);
114
+ return this.waitDevWorkspace();
115
+ }
116
+
117
+ executeCommand(commandToExecute: string, container: string = KubernetesCommandLineToolsExecutor.container): ShellString {
118
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
119
+
120
+ return this.shellExecutor.executeCommand(
121
+ `${this.kubernetesCommandLineTool} exec -i ${KubernetesCommandLineToolsExecutor.pod} -n ${this.namespace} -c ${container} -- sh -c '${commandToExecute}'`
122
+ );
123
+ }
124
+
125
+ applyYamlConfigurationAsStringOutput(yamlConfiguration: string): ShellString {
126
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
127
+
128
+ return this.shellExecutor.executeCommand(
129
+ `cat <<EOF | ${this.kubernetesCommandLineTool} apply -n ${this.namespace} -f - \n` + yamlConfiguration + '\n' + 'EOF'
130
+ );
131
+ }
132
+
133
+ applyWithoutNamespace(yamlConfiguration: string): ShellString {
134
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
135
+
136
+ return this.shellExecutor.executeCommand(
137
+ `cat <<EOF | ${this.kubernetesCommandLineTool} apply -f - \n` + yamlConfiguration + '\n' + 'EOF'
138
+ );
139
+ }
140
+
141
+ applyYamlConfigurationAsFile(pathToFile: string): void {
142
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
143
+
144
+ this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} apply -n ${this.namespace} -f "${path.resolve(pathToFile)}"`);
145
+ }
146
+
147
+ getDevWorkspaceYamlConfiguration(): ShellString {
148
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
149
+
150
+ return this.shellExecutor.executeCommand(
151
+ `${this.kubernetesCommandLineTool} get dw ${this.workspaceName} -n ${this.namespace} -o yaml`
152
+ );
153
+ }
154
+
155
+ waitDevWorkspace(timeout: number = 360): ShellString {
156
+ Logger.debug(`${this.kubernetesCommandLineTool} - wait till workspace ready.`);
157
+
158
+ const output: ShellString = this.shellExecutor.executeCommand(
159
+ `${this.kubernetesCommandLineTool} wait -n ${this.namespace} --for=condition=Ready dw ${this.workspaceName} --timeout=${timeout}s`
160
+ );
161
+ this.getPodAndContainerNames();
162
+ return output;
163
+ }
164
+
165
+ createNamespace(): void {
166
+ Logger.debug(`${this.kubernetesCommandLineTool} - create namespace "${this.namespace}".`);
167
+
168
+ this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} create namespace ${this.namespace}`);
169
+ }
170
+
171
+ createProject(projectName: string): void {
172
+ Logger.debug(`${this.kubernetesCommandLineTool} - create new project "${projectName}".`);
173
+
174
+ this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} new-project ${projectName} -n ${this.namespace}`);
175
+ }
176
+
177
+ deleteProject(projectName: string): void {
178
+ Logger.debug(`${this.kubernetesCommandLineTool} - delete "${projectName}".`);
179
+
180
+ this.shellExecutor.executeCommand(`${this.kubernetesCommandLineTool} delete project ${projectName} -n ${this.namespace}`);
181
+ }
182
+
183
+ getPodAndContainerNames(): void {
184
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
185
+
186
+ KubernetesCommandLineToolsExecutor.pod = this.getWorkspacePodName();
187
+ KubernetesCommandLineToolsExecutor.container = this.getContainerName();
188
+ }
189
+
190
+ /**
191
+ * @param userName
192
+ */
193
+ isUserLoggedIn(userName: string): boolean {
194
+ Logger.debug(`${this.kubernetesCommandLineTool}`);
195
+
196
+ const whoamiCommandOutput: ShellString = this.shellExecutor.executeCommand('oc whoami && oc whoami --show-server=true');
197
+
198
+ return whoamiCommandOutput.stdout.includes(userName) && whoamiCommandOutput.stdout.includes(this.getServerUrl());
199
+ }
200
+
201
+ getServerUrl(): string {
202
+ Logger.debug(`${this.kubernetesCommandLineTool} - get server api url.`);
203
+
204
+ return BASE_TEST_CONSTANTS.TS_SELENIUM_BASE_URL.replace('devspaces.apps', 'api') + ':6443';
205
+ }
152
206
  }
153
207
 
154
- export namespace KubernetesCommandLineToolsExecutor {
155
- export class ContainerTerminal extends KubernetesCommandLineToolsExecutor {
156
- constructor(cluster: KubernetesCommandLineToolsExecutor) {
157
- super(cluster.getWorkspaceName, cluster.getNamespace);
158
- }
159
-
160
- ls(path: string = ''): ShellString {
161
- return this.executeCommand('ls ' + path);
162
- }
163
-
164
- pwd(): ShellString {
165
- return this.executeCommand('pwd');
166
- }
167
-
168
- cd(path: string): ShellString {
169
- return this.executeCommand('cd ' + path);
170
- }
171
-
172
- gitClone(repository: string): ShellString {
173
- return this.executeCommand('git clone ' + repository);
174
- }
175
-
176
- removeFolder(path: string): ShellString {
177
- return this.executeCommand('rm -rf ' + path);
178
- }
179
-
180
- getEnvValue(envName: string): string {
181
- envName = envName.replace(/[${}]/g, '');
182
- const output: ShellString = this.executeCommand(`env | grep ${envName}`);
183
- return output.stderr
184
- ? output.stderr
185
- : output.stdout
186
- .substring(output.stdout.lastIndexOf('=') + 1)
187
- .replace('\n', '');
188
- }
189
- }
208
+ @injectable()
209
+ export class ContainerTerminal extends KubernetesCommandLineToolsExecutor {
210
+ constructor(
211
+ @inject(CLASSES.ShellExecutor)
212
+ readonly shellExecutor: ShellExecutor,
213
+ @inject(CLASSES.KubernetesCommandLineToolsExecutor)
214
+ readonly cluster: KubernetesCommandLineToolsExecutor
215
+ ) {
216
+ super(shellExecutor);
217
+ }
218
+
219
+ ls(path: string = ''): ShellString {
220
+ return this.shellExecutor.executeCommand('ls ' + path);
221
+ }
222
+
223
+ pwd(): ShellString {
224
+ return this.shellExecutor.executeCommand('pwd');
225
+ }
226
+
227
+ cd(path: string): ShellString {
228
+ return this.shellExecutor.executeCommand('cd ' + path);
229
+ }
230
+
231
+ gitClone(repository: string): ShellString {
232
+ return this.shellExecutor.executeCommand('git clone ' + repository);
233
+ }
234
+
235
+ removeFolder(path: string): ShellString {
236
+ return this.shellExecutor.executeCommand('rm -rf ' + path);
237
+ }
190
238
  }