@@ -8,7 +8,11 @@ import * as chai from "chai";
8
8
import { suite , test , timeout } from "mocha-typescript" ;
9
9
import { testContainer } from "./test-container" ;
10
10
import { TypeORM } from "./typeorm/typeorm" ;
11
- import { WorkspaceCluster , WorkspaceClusterDB } from "@gitpod/gitpod-protocol/lib/workspace-cluster" ;
11
+ import {
12
+ WorkspaceCluster ,
13
+ WorkspaceClusterDB ,
14
+ WorkspaceClusterWoTLS ,
15
+ } from "@gitpod/gitpod-protocol/lib/workspace-cluster" ;
12
16
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster" ;
13
17
const expect = chai . expect ;
14
18
@@ -42,6 +46,15 @@ export class WorkspaceClusterDBSpec {
42
46
maxScore : 100 ,
43
47
govern : true ,
44
48
} ;
49
+ const wsc1a : DBWorkspaceCluster = {
50
+ name : "eu71" ,
51
+ applicationCluster : "us02" ,
52
+ url : "some-url" ,
53
+ state : "cordoned" ,
54
+ score : 0 ,
55
+ maxScore : 0 ,
56
+ govern : false ,
57
+ } ;
45
58
const wsc2 : DBWorkspaceCluster = {
46
59
name : "us71" ,
47
60
applicationCluster : "eu02" ,
@@ -53,22 +66,26 @@ export class WorkspaceClusterDBSpec {
53
66
} ;
54
67
55
68
await this . db . save ( wsc1 ) ;
69
+ await this . db . save ( wsc1a ) ;
56
70
await this . db . save ( wsc2 ) ;
57
71
58
72
// Can find the eu71 cluster as seen by the eu02 application cluster.
59
73
const result = await this . db . findByName ( "eu71" , "eu02" ) ;
60
74
expect ( result ) . not . to . be . undefined ;
61
75
expect ( ( result as WorkspaceCluster ) . name ) . to . equal ( "eu71" ) ;
76
+ expect ( ( result as WorkspaceCluster ) . applicationCluster ) . to . equal ( "eu02" ) ;
62
77
63
- // Can't find the eu71 cluster as seen by the us02 application cluster.
64
- // (no record in the db for that (ws-cluster, app-cluster) combination).
78
+ // Can find the eu71 cluster as seen by the us02 application cluster.
65
79
const result2 = await this . db . findByName ( "eu71" , "us02" ) ;
66
- expect ( result2 ) . to . be . undefined ;
80
+ expect ( result2 ) . not . to . be . undefined ;
81
+ expect ( ( result2 as WorkspaceCluster ) . name ) . to . equal ( "eu71" ) ;
82
+ expect ( ( result2 as WorkspaceCluster ) . applicationCluster ) . to . equal ( "us02" ) ;
67
83
68
84
// Can find the us71 cluster as seen by the eu02 application cluster.
69
85
const result3 = await this . db . findByName ( "us71" , "eu02" ) ;
70
86
expect ( result3 ) . not . to . be . undefined ;
71
87
expect ( ( result3 as WorkspaceCluster ) . name ) . to . equal ( "us71" ) ;
88
+ expect ( ( result3 as WorkspaceCluster ) . applicationCluster ) . to . equal ( "eu02" ) ;
72
89
}
73
90
74
91
@test public async deleteByName ( ) {
@@ -81,6 +98,15 @@ export class WorkspaceClusterDBSpec {
81
98
maxScore : 100 ,
82
99
govern : true ,
83
100
} ;
101
+ const wsc1a : DBWorkspaceCluster = {
102
+ name : "eu71" ,
103
+ applicationCluster : "us02" ,
104
+ url : "some-url" ,
105
+ state : "cordoned" ,
106
+ score : 0 ,
107
+ maxScore : 0 ,
108
+ govern : false ,
109
+ } ;
84
110
const wsc2 : DBWorkspaceCluster = {
85
111
name : "us71" ,
86
112
applicationCluster : "eu02" ,
@@ -92,11 +118,13 @@ export class WorkspaceClusterDBSpec {
92
118
} ;
93
119
94
120
await this . db . save ( wsc1 ) ;
121
+ await this . db . save ( wsc1a ) ;
95
122
await this . db . save ( wsc2 ) ;
96
123
97
124
// Can delete the eu71 cluster as seen by the eu02 application cluster.
98
125
await this . db . deleteByName ( "eu71" , "eu02" ) ;
99
126
expect ( await this . db . findByName ( "eu71" , "eu02" ) ) . to . be . undefined ;
127
+ expect ( await this . db . findByName ( "eu71" , "us02" ) ) . not . to . be . undefined ;
100
128
expect ( await this . db . findByName ( "us71" , "eu02" ) ) . not . to . be . undefined ;
101
129
}
102
130
@@ -110,6 +138,15 @@ export class WorkspaceClusterDBSpec {
110
138
maxScore : 100 ,
111
139
govern : true ,
112
140
} ;
141
+ const wsc1a : DBWorkspaceCluster = {
142
+ name : "eu71" ,
143
+ applicationCluster : "us02" ,
144
+ url : "some-url" ,
145
+ state : "cordoned" ,
146
+ score : 0 ,
147
+ maxScore : 0 ,
148
+ govern : false ,
149
+ } ;
113
150
const wsc2 : DBWorkspaceCluster = {
114
151
name : "us71" ,
115
152
applicationCluster : "eu02" ,
@@ -121,11 +158,13 @@ export class WorkspaceClusterDBSpec {
121
158
} ;
122
159
123
160
await this . db . save ( wsc1 ) ;
161
+ await this . db . save ( wsc1a ) ;
124
162
await this . db . save ( wsc2 ) ;
125
163
126
164
const wscs = await this . db . findFiltered ( { name : "eu71" , applicationCluster : "eu02" } ) ;
127
165
expect ( wscs . length ) . to . equal ( 1 ) ;
128
166
expect ( wscs [ 0 ] . name ) . to . equal ( "eu71" ) ;
167
+ expect ( wscs [ 0 ] . applicationCluster ) . to . equal ( "eu02" ) ;
129
168
}
130
169
131
170
@test public async testFindFilteredByApplicationCluster ( ) {
@@ -138,6 +177,15 @@ export class WorkspaceClusterDBSpec {
138
177
maxScore : 100 ,
139
178
govern : true ,
140
179
} ;
180
+ const wsc1a : DBWorkspaceCluster = {
181
+ name : "eu71" ,
182
+ applicationCluster : "us02" ,
183
+ url : "some-url" ,
184
+ state : "cordoned" ,
185
+ score : 0 ,
186
+ maxScore : 0 ,
187
+ govern : false ,
188
+ } ;
141
189
const wsc2 : DBWorkspaceCluster = {
142
190
name : "us71" ,
143
191
applicationCluster : "us02" ,
@@ -149,11 +197,50 @@ export class WorkspaceClusterDBSpec {
149
197
} ;
150
198
151
199
await this . db . save ( wsc1 ) ;
200
+ await this . db . save ( wsc1a ) ;
152
201
await this . db . save ( wsc2 ) ;
153
202
154
- const wscs = await this . db . findFiltered ( { applicationCluster : "eu02" } ) ;
155
- expect ( wscs . length ) . to . equal ( 1 ) ;
156
- expect ( wscs [ 0 ] . name ) . to . equal ( "eu71" ) ;
203
+ const expectedClusters : WorkspaceClusterWoTLS [ ] = [
204
+ {
205
+ name : "eu71" ,
206
+ applicationCluster : "eu02" ,
207
+ url : "some-url" ,
208
+ state : "available" ,
209
+ score : 100 ,
210
+ maxScore : 100 ,
211
+ govern : true ,
212
+ admissionConstraints : [ ] ,
213
+ } ,
214
+ ] ;
215
+ const actualClusters = await this . db . findFiltered ( { applicationCluster : "eu02" } ) ;
216
+ expect ( actualClusters . length ) . to . equal ( 1 ) ;
217
+ expect ( actualClusters ) . to . deep . include . members ( expectedClusters ) ;
218
+
219
+ const expectedClusters2 : WorkspaceClusterWoTLS [ ] = [
220
+ {
221
+ name : "eu71" ,
222
+ applicationCluster : "us02" ,
223
+ url : "some-url" ,
224
+ state : "cordoned" ,
225
+ score : 0 ,
226
+ maxScore : 0 ,
227
+ govern : false ,
228
+ admissionConstraints : [ ] ,
229
+ } ,
230
+ {
231
+ name : "us71" ,
232
+ applicationCluster : "us02" ,
233
+ url : "some-url" ,
234
+ state : "available" ,
235
+ score : 100 ,
236
+ maxScore : 100 ,
237
+ govern : true ,
238
+ admissionConstraints : [ ] ,
239
+ } ,
240
+ ] ;
241
+ const wscs2 = await this . db . findFiltered ( { applicationCluster : "us02" } ) ;
242
+ expect ( wscs2 . length ) . to . equal ( 2 ) ;
243
+ expect ( wscs2 ) . to . deep . include . members ( expectedClusters2 ) ;
157
244
}
158
245
}
159
246
0 commit comments