Skip to content

Commit f2cfc62

Browse files
author
Andrew Farries
committed
Add extra assertions
1 parent b88d9bb commit f2cfc62

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export class WorkspaceClusterDBSpec {
4242
maxScore: 100,
4343
govern: true,
4444
};
45+
const wsc1a: DBWorkspaceCluster = {
46+
name: "eu71",
47+
applicationCluster: "us02",
48+
url: "some-url",
49+
state: "cordoned",
50+
score: 0,
51+
maxScore: 0,
52+
govern: false,
53+
};
4554
const wsc2: DBWorkspaceCluster = {
4655
name: "us71",
4756
applicationCluster: "eu02",
@@ -53,22 +62,26 @@ export class WorkspaceClusterDBSpec {
5362
};
5463

5564
await this.db.save(wsc1);
65+
await this.db.save(wsc1a);
5666
await this.db.save(wsc2);
5767

5868
// Can find the eu71 cluster as seen by the eu02 application cluster.
5969
const result = await this.db.findByName("eu71", "eu02");
6070
expect(result).not.to.be.undefined;
6171
expect((result as WorkspaceCluster).name).to.equal("eu71");
72+
expect((result as WorkspaceCluster).applicationCluster).to.equal("eu02");
6273

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).
74+
// Can find the eu71 cluster as seen by the us02 application cluster.
6575
const result2 = await this.db.findByName("eu71", "us02");
66-
expect(result2).to.be.undefined;
76+
expect(result2).not.to.be.undefined;
77+
expect((result2 as WorkspaceCluster).name).to.equal("eu71");
78+
expect((result2 as WorkspaceCluster).applicationCluster).to.equal("us02");
6779

6880
// Can find the us71 cluster as seen by the eu02 application cluster.
6981
const result3 = await this.db.findByName("us71", "eu02");
7082
expect(result3).not.to.be.undefined;
7183
expect((result3 as WorkspaceCluster).name).to.equal("us71");
84+
expect((result3 as WorkspaceCluster).applicationCluster).to.equal("eu02");
7285
}
7386

7487
@test public async deleteByName() {
@@ -81,6 +94,15 @@ export class WorkspaceClusterDBSpec {
8194
maxScore: 100,
8295
govern: true,
8396
};
97+
const wsc1a: DBWorkspaceCluster = {
98+
name: "eu71",
99+
applicationCluster: "us02",
100+
url: "some-url",
101+
state: "cordoned",
102+
score: 0,
103+
maxScore: 0,
104+
govern: false,
105+
};
84106
const wsc2: DBWorkspaceCluster = {
85107
name: "us71",
86108
applicationCluster: "eu02",
@@ -92,11 +114,13 @@ export class WorkspaceClusterDBSpec {
92114
};
93115

94116
await this.db.save(wsc1);
117+
await this.db.save(wsc1a);
95118
await this.db.save(wsc2);
96119

97120
// Can delete the eu71 cluster as seen by the eu02 application cluster.
98121
await this.db.deleteByName("eu71", "eu02");
99122
expect(await this.db.findByName("eu71", "eu02")).to.be.undefined;
123+
expect(await this.db.findByName("eu71", "us02")).not.to.be.undefined;
100124
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined;
101125
}
102126

@@ -110,6 +134,15 @@ export class WorkspaceClusterDBSpec {
110134
maxScore: 100,
111135
govern: true,
112136
};
137+
const wsc1a: DBWorkspaceCluster = {
138+
name: "eu71",
139+
applicationCluster: "us02",
140+
url: "some-url",
141+
state: "cordoned",
142+
score: 0,
143+
maxScore: 0,
144+
govern: false,
145+
};
113146
const wsc2: DBWorkspaceCluster = {
114147
name: "us71",
115148
applicationCluster: "eu02",
@@ -121,11 +154,13 @@ export class WorkspaceClusterDBSpec {
121154
};
122155

123156
await this.db.save(wsc1);
157+
await this.db.save(wsc1a);
124158
await this.db.save(wsc2);
125159

126160
const wscs = await this.db.findFiltered({ name: "eu71", applicationCluster: "eu02" });
127161
expect(wscs.length).to.equal(1);
128162
expect(wscs[0].name).to.equal("eu71");
163+
expect(wscs[0].applicationCluster).to.equal("eu02");
129164
}
130165

131166
@test public async testFindFilteredByApplicationCluster() {
@@ -138,6 +173,15 @@ export class WorkspaceClusterDBSpec {
138173
maxScore: 100,
139174
govern: true,
140175
};
176+
const wsc1a: DBWorkspaceCluster = {
177+
name: "eu71",
178+
applicationCluster: "us02",
179+
url: "some-url",
180+
state: "cordoned",
181+
score: 0,
182+
maxScore: 0,
183+
govern: false,
184+
};
141185
const wsc2: DBWorkspaceCluster = {
142186
name: "us71",
143187
applicationCluster: "us02",
@@ -149,11 +193,20 @@ export class WorkspaceClusterDBSpec {
149193
};
150194

151195
await this.db.save(wsc1);
196+
await this.db.save(wsc1a);
152197
await this.db.save(wsc2);
153198

154199
const wscs = await this.db.findFiltered({ applicationCluster: "eu02" });
155200
expect(wscs.length).to.equal(1);
156201
expect(wscs[0].name).to.equal("eu71");
202+
203+
const wscs2 = await this.db.findFiltered({ applicationCluster: "us02" });
204+
expect(wscs2.length).to.equal(2);
205+
wscs2.sort((x, y) => x.name.localeCompare(y.name));
206+
expect(wscs2[0].name).to.equal("eu71");
207+
expect(wscs2[0].applicationCluster).to.equal("us02");
208+
expect(wscs2[1].name).to.equal("us71");
209+
expect(wscs2[1].applicationCluster).to.equal("us02");
157210
}
158211
}
159212

0 commit comments

Comments
 (0)