3
3
* Licensed under the MIT License. See LICENSE file in the project root for license information.
4
4
*-----------------------------------------------------------------------------------------------*/
5
5
import { fail } from 'assert' ;
6
- import { expect } from 'chai' ;
7
6
import * as fs from 'fs/promises' ;
8
7
import { suite , suiteSetup } from 'mocha' ;
9
8
import * as path from 'path' ;
@@ -16,128 +15,132 @@ import { OdoPreference } from '../../src/odo/odoPreference';
16
15
import { Odo } from '../../src/odo/odoWrapper' ;
17
16
import { LoginUtil } from '../../src/util/loginUtil' ;
18
17
19
- suite ( './alizer/alizerWrapper.ts' , function ( ) {
20
- const isOpenShift : boolean = Boolean ( parseInt ( process . env . IS_OPENSHIFT , 10 ) ) || false ;
21
- const clusterUrl = process . env . CLUSTER_URL || 'https://api.crc.testing:6443' ;
22
- const username = process . env . CLUSTER_USER || 'developer' ;
23
- const password = process . env . CLUSTER_PASSWORD || 'developer' ;
18
+ void import ( 'chai' ) . then ( ( chai ) => {
19
+ const expect = chai . expect ;
24
20
25
- suiteSetup ( async function ( ) {
26
- await OdoPreference . Instance . getRegistries ( ) ; // This creates the ODO preferences, if needed
27
- if ( isOpenShift ) {
21
+ suite ( './alizer/alizerWrapper.ts' , function ( ) {
22
+ const isOpenShift : boolean = Boolean ( parseInt ( process . env . IS_OPENSHIFT , 10 ) ) || false ;
23
+ const clusterUrl = process . env . CLUSTER_URL || 'https://api.crc.testing:6443' ;
24
+ const username = process . env . CLUSTER_USER || 'developer' ;
25
+ const password = process . env . CLUSTER_PASSWORD || 'developer' ;
26
+
27
+ suiteSetup ( async function ( ) {
28
+ await OdoPreference . Instance . getRegistries ( ) ; // This creates the ODO preferences, if needed
29
+ if ( isOpenShift ) {
30
+ try {
31
+ await LoginUtil . Instance . logout ( ) ;
32
+ } catch {
33
+ // do nothing
34
+ }
35
+ await Oc . Instance . loginWithUsernamePassword ( clusterUrl , username , password ) ;
36
+ }
37
+ } ) ;
38
+
39
+ suiteTeardown ( async function ( ) {
40
+ // ensure projects are cleaned up
28
41
try {
29
- await LoginUtil . Instance . logout ( ) ;
42
+ await Oc . Instance . deleteProject ( 'my-test-project-1' ) ;
43
+ } catch {
44
+ // do nothing
45
+ }
46
+ try {
47
+ await Oc . Instance . deleteProject ( 'my-test-project-2' ) ;
30
48
} catch {
31
49
// do nothing
32
50
}
33
- await Oc . Instance . loginWithUsernamePassword ( clusterUrl , username , password ) ;
34
- }
35
- } ) ;
36
-
37
- suiteTeardown ( async function ( ) {
38
- // ensure projects are cleaned up
39
- try {
40
- await Oc . Instance . deleteProject ( 'my-test-project-1' ) ;
41
- } catch {
42
- // do nothing
43
- }
44
- try {
45
- await Oc . Instance . deleteProject ( 'my-test-project-2' ) ;
46
- } catch {
47
- // do nothing
48
- }
49
-
50
- if ( isOpenShift ) {
51
- await LoginUtil . Instance . logout ( ) ;
52
- }
53
- } ) ;
54
51
55
- suite ( 'analyse folder' , function ( ) {
56
- const project1 = 'my-test-project-1' ;
52
+ if ( isOpenShift ) {
53
+ await LoginUtil . Instance . logout ( ) ;
54
+ }
55
+ } ) ;
57
56
58
- let tmpFolder1 : Uri ;
59
- let tmpFolder2 : Uri ;
57
+ suite ( 'analyse folder' , function ( ) {
58
+ const project1 = 'my-test-project-1' ;
59
+
60
+ let tmpFolder1 : Uri ;
61
+ let tmpFolder2 : Uri ;
62
+
63
+ suiteSetup ( async function ( ) {
64
+ await Oc . Instance . createProject ( project1 ) ;
65
+ tmpFolder1 = Uri . parse ( await promisify ( tmp . dir ) ( ) ) ;
66
+ tmpFolder2 = Uri . parse ( await promisify ( tmp . dir ) ( ) ) ;
67
+ await Odo . Instance . createComponentFromFolder (
68
+ 'nodejs' ,
69
+ 'latest' ,
70
+ undefined ,
71
+ 'component1' ,
72
+ tmpFolder1 ,
73
+ 'nodejs-starter' ,
74
+ ) ;
75
+ await Odo . Instance . createComponentFromFolder (
76
+ 'go' ,
77
+ 'latest' ,
78
+ undefined ,
79
+ 'component2' ,
80
+ tmpFolder2 ,
81
+ 'go-starter' ,
82
+ ) ;
83
+ } ) ;
60
84
61
- suiteSetup ( async function ( ) {
62
- await Oc . Instance . createProject ( project1 ) ;
63
- tmpFolder1 = Uri . parse ( await promisify ( tmp . dir ) ( ) ) ;
64
- tmpFolder2 = Uri . parse ( await promisify ( tmp . dir ) ( ) ) ;
65
- await Odo . Instance . createComponentFromFolder (
66
- 'nodejs' ,
67
- 'latest' ,
68
- undefined ,
69
- 'component1' ,
70
- tmpFolder1 ,
71
- 'nodejs-starter' ,
72
- ) ;
73
- await Odo . Instance . createComponentFromFolder (
74
- 'go' ,
75
- 'latest' ,
76
- undefined ,
77
- 'component2' ,
78
- tmpFolder2 ,
79
- 'go-starter' ,
80
- ) ;
81
- } ) ;
85
+ suiteTeardown ( async function ( ) {
86
+ if ( isOpenShift ) {
87
+ await Oc . Instance . loginWithUsernamePassword ( clusterUrl , username , password ) ;
88
+ }
89
+ const newWorkspaceFolders = workspace . workspaceFolders . filter ( ( workspaceFolder ) => {
90
+ const fsPath = workspaceFolder . uri . fsPath ;
91
+ return ( fsPath !== tmpFolder1 . fsPath && fsPath !== tmpFolder2 . fsPath ) ;
92
+ } ) ;
93
+ workspace . updateWorkspaceFolders ( 0 , workspace . workspaceFolders . length , ...newWorkspaceFolders ) ;
94
+ await fs . rm ( tmpFolder1 . fsPath , { force : true , recursive : true } ) ;
95
+ await fs . rm ( tmpFolder2 . fsPath , { force : true , recursive : true } ) ;
96
+ await Oc . Instance . deleteProject ( project1 ) ;
97
+ } ) ;
82
98
83
- suiteTeardown ( async function ( ) {
84
- if ( isOpenShift ) {
85
- await Oc . Instance . loginWithUsernamePassword ( clusterUrl , username , password ) ;
86
- }
87
- const newWorkspaceFolders = workspace . workspaceFolders . filter ( ( workspaceFolder ) => {
88
- const fsPath = workspaceFolder . uri . fsPath ;
89
- return ( fsPath !== tmpFolder1 . fsPath && fsPath !== tmpFolder2 . fsPath ) ;
99
+ test ( 'analyze()' , async function ( ) {
100
+ const analysis1 = await Alizer . Instance . alizerDevfile ( tmpFolder1 ) ;
101
+ expect ( analysis1 . Name ) . to . exist ;
102
+ expect ( analysis1 . Name ) . to . equal ( 'nodejs' ) ;
103
+ const analysis2 = await Alizer . Instance . alizerDevfile ( tmpFolder2 ) ;
104
+ expect ( analysis2 . Name ) . to . exist ;
105
+ expect ( analysis2 . Name ) . to . equal ( 'go' ) ;
90
106
} ) ;
91
- workspace . updateWorkspaceFolders ( 0 , workspace . workspaceFolders . length , ...newWorkspaceFolders ) ;
92
- await fs . rm ( tmpFolder1 . fsPath , { force : true , recursive : true } ) ;
93
- await fs . rm ( tmpFolder2 . fsPath , { force : true , recursive : true } ) ;
94
- await Oc . Instance . deleteProject ( project1 ) ;
95
107
} ) ;
96
108
97
- test ( 'analyze()' , async function ( ) {
98
- const analysis1 = await Alizer . Instance . alizerDevfile ( tmpFolder1 ) ;
99
- expect ( analysis1 . Name ) . to . exist ;
100
- expect ( analysis1 . Name ) . to . equal ( 'nodejs' ) ;
101
- const analysis2 = await Alizer . Instance . alizerDevfile ( tmpFolder2 ) ;
102
- expect ( analysis2 . Name ) . to . exist ;
103
- expect ( analysis2 . Name ) . to . equal ( 'go' ) ;
104
- } ) ;
105
- } ) ;
109
+ suite ( 'create component' , function ( ) {
106
110
107
- suite ( 'create component' , function ( ) {
111
+ const COMPONENT_TYPE = 'dotnet50' ;
112
+ const COMPONENT_VERSION = 'latest' ;
108
113
109
- const COMPONENT_TYPE = 'dotnet50' ;
110
- const COMPONENT_VERSION = 'latest' ;
114
+ let tmpFolder : string ;
111
115
112
- let tmpFolder : string ;
116
+ suiteSetup ( async function ( ) {
117
+ tmpFolder = await promisify ( tmp . dir ) ( ) ;
118
+ } ) ;
113
119
114
- suiteSetup ( async function ( ) {
115
- tmpFolder = await promisify ( tmp . dir ) ( ) ;
116
- } ) ;
120
+ suiteTeardown ( async function ( ) {
121
+ await fs . rm ( tmpFolder , { recursive : true , force : true } ) ;
122
+ } ) ;
117
123
118
- suiteTeardown ( async function ( ) {
119
- await fs . rm ( tmpFolder , { recursive : true , force : true } ) ;
120
- } ) ;
124
+ test ( 'createComponentFromTemplateProject()' , async function ( ) {
125
+ await Odo . Instance . createComponentFromTemplateProject (
126
+ tmpFolder , 'my-component' , 8080 ,
127
+ COMPONENT_TYPE , COMPONENT_VERSION ,
128
+ OdoPreference . DEFAULT_DEVFILE_REGISTRY_NAME , 'dotnet50-example' ) ;
129
+ try {
130
+ await fs . access ( path . join ( tmpFolder , 'devfile.yaml' ) ) ;
131
+ } catch {
132
+ fail ( 'Expected devfile to be created' ) ;
133
+ }
134
+ } ) ;
121
135
122
- test ( 'createComponentFromTemplateProject()' , async function ( ) {
123
- await Odo . Instance . createComponentFromTemplateProject (
124
- tmpFolder , 'my-component' , 8080 ,
125
- COMPONENT_TYPE , COMPONENT_VERSION ,
126
- OdoPreference . DEFAULT_DEVFILE_REGISTRY_NAME , 'dotnet50-example' ) ;
127
- try {
128
- await fs . access ( path . join ( tmpFolder , 'devfile.yaml' ) ) ;
129
- } catch {
130
- fail ( 'Expected devfile to be created' ) ;
131
- }
132
- } ) ;
136
+ test ( 'analyze()' , async function ( ) {
137
+ const analysis = await Alizer . Instance . alizerDevfile ( Uri . file ( tmpFolder ) ) ;
138
+ expect ( analysis ) . to . exist ;
139
+ expect ( analysis . Name ) . to . equal ( COMPONENT_TYPE ) ;
140
+ } ) ;
133
141
134
- test ( 'analyze()' , async function ( ) {
135
- const analysis = await Alizer . Instance . alizerDevfile ( Uri . file ( tmpFolder ) ) ;
136
- expect ( analysis ) . to . exist ;
137
- expect ( analysis . Name ) . to . equal ( COMPONENT_TYPE ) ;
138
142
} ) ;
139
143
144
+ test ( 'deleteComponentConfiguration' ) ;
140
145
} ) ;
141
-
142
- test ( 'deleteComponentConfiguration' ) ;
143
- } ) ;
146
+ } ) ;
0 commit comments