Skip to content

Commit 19c0a6d

Browse files
Andrew Farriesroboquat
authored andcommitted
Add extra assertions
1 parent ee8354a commit 19c0a6d

File tree

1 file changed

+94
-7
lines changed

1 file changed

+94
-7
lines changed

components/gitpod-db/src/workspace-cluster-db.spec.db.ts

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import * as chai from "chai";
88
import { suite, test, timeout } from "mocha-typescript";
99
import { testContainer } from "./test-container";
1010
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";
1216
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster";
1317
const expect = chai.expect;
1418

@@ -42,6 +46,15 @@ export class WorkspaceClusterDBSpec {
4246
maxScore: 100,
4347
govern: true,
4448
};
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+
};
4558
const wsc2: DBWorkspaceCluster = {
4659
name: "us71",
4760
applicationCluster: "eu02",
@@ -53,22 +66,26 @@ export class WorkspaceClusterDBSpec {
5366
};
5467

5568
await this.db.save(wsc1);
69+
await this.db.save(wsc1a);
5670
await this.db.save(wsc2);
5771

5872
// Can find the eu71 cluster as seen by the eu02 application cluster.
5973
const result = await this.db.findByName("eu71", "eu02");
6074
expect(result).not.to.be.undefined;
6175
expect((result as WorkspaceCluster).name).to.equal("eu71");
76+
expect((result as WorkspaceCluster).applicationCluster).to.equal("eu02");
6277

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.
6579
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");
6783

6884
// Can find the us71 cluster as seen by the eu02 application cluster.
6985
const result3 = await this.db.findByName("us71", "eu02");
7086
expect(result3).not.to.be.undefined;
7187
expect((result3 as WorkspaceCluster).name).to.equal("us71");
88+
expect((result3 as WorkspaceCluster).applicationCluster).to.equal("eu02");
7289
}
7390

7491
@test public async deleteByName() {
@@ -81,6 +98,15 @@ export class WorkspaceClusterDBSpec {
8198
maxScore: 100,
8299
govern: true,
83100
};
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+
};
84110
const wsc2: DBWorkspaceCluster = {
85111
name: "us71",
86112
applicationCluster: "eu02",
@@ -92,11 +118,13 @@ export class WorkspaceClusterDBSpec {
92118
};
93119

94120
await this.db.save(wsc1);
121+
await this.db.save(wsc1a);
95122
await this.db.save(wsc2);
96123

97124
// Can delete the eu71 cluster as seen by the eu02 application cluster.
98125
await this.db.deleteByName("eu71", "eu02");
99126
expect(await this.db.findByName("eu71", "eu02")).to.be.undefined;
127+
expect(await this.db.findByName("eu71", "us02")).not.to.be.undefined;
100128
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined;
101129
}
102130

@@ -110,6 +138,15 @@ export class WorkspaceClusterDBSpec {
110138
maxScore: 100,
111139
govern: true,
112140
};
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+
};
113150
const wsc2: DBWorkspaceCluster = {
114151
name: "us71",
115152
applicationCluster: "eu02",
@@ -121,11 +158,13 @@ export class WorkspaceClusterDBSpec {
121158
};
122159

123160
await this.db.save(wsc1);
161+
await this.db.save(wsc1a);
124162
await this.db.save(wsc2);
125163

126164
const wscs = await this.db.findFiltered({ name: "eu71", applicationCluster: "eu02" });
127165
expect(wscs.length).to.equal(1);
128166
expect(wscs[0].name).to.equal("eu71");
167+
expect(wscs[0].applicationCluster).to.equal("eu02");
129168
}
130169

131170
@test public async testFindFilteredByApplicationCluster() {
@@ -138,6 +177,15 @@ export class WorkspaceClusterDBSpec {
138177
maxScore: 100,
139178
govern: true,
140179
};
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+
};
141189
const wsc2: DBWorkspaceCluster = {
142190
name: "us71",
143191
applicationCluster: "us02",
@@ -149,11 +197,50 @@ export class WorkspaceClusterDBSpec {
149197
};
150198

151199
await this.db.save(wsc1);
200+
await this.db.save(wsc1a);
152201
await this.db.save(wsc2);
153202

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);
157244
}
158245
}
159246

0 commit comments

Comments
 (0)