-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathworkspace-cluster-db.spec.db.ts
160 lines (140 loc) · 4.97 KB
/
workspace-cluster-db.spec.db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/
import * as chai from "chai";
import { suite, test, timeout } from "mocha-typescript";
import { testContainer } from "./test-container";
import { TypeORM } from "./typeorm/typeorm";
import { WorkspaceCluster, WorkspaceClusterDB } from "@gitpod/gitpod-protocol/lib/workspace-cluster";
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster";
const expect = chai.expect;
@suite
@timeout(5000)
export class WorkspaceClusterDBSpec {
typeORM = testContainer.get<TypeORM>(TypeORM);
db = testContainer.get<WorkspaceClusterDB>(WorkspaceClusterDB);
async before() {
await this.clear();
}
async after() {
await this.clear();
}
protected async clear() {
const connection = await this.typeORM.getConnection();
const manager = connection.manager;
await manager.clear(DBWorkspaceCluster);
}
@test public async findByName() {
const wsc1: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
await this.db.save(wsc1);
await this.db.save(wsc2);
// Can find the eu71 cluster as seen by the eu02 application cluster.
const result = await this.db.findByName("eu71", "eu02");
expect(result).not.to.be.undefined;
expect((result as WorkspaceCluster).name).to.equal("eu71");
// Can't find the eu71 cluster as seen by the us02 application cluster.
// (no record in the db for that (ws-cluster, app-cluster) combination).
const result2 = await this.db.findByName("eu71", "us02");
expect(result2).to.be.undefined;
// Can find the us71 cluster as seen by the eu02 application cluster.
const result3 = await this.db.findByName("us71", "eu02");
expect(result3).not.to.be.undefined;
expect((result3 as WorkspaceCluster).name).to.equal("us71");
}
@test public async deleteByName() {
const wsc1: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
await this.db.save(wsc1);
await this.db.save(wsc2);
// Can delete the eu71 cluster as seen by the eu02 application cluster.
await this.db.deleteByName("eu71", "eu02");
expect(await this.db.findByName("eu71", "eu02")).to.be.undefined;
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined;
}
@test public async testFindFilteredByName() {
const wsc1: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
await this.db.save(wsc1);
await this.db.save(wsc2);
const wscs = await this.db.findFiltered({ name: "eu71", applicationCluster: "eu02" });
expect(wscs.length).to.equal(1);
expect(wscs[0].name).to.equal("eu71");
}
@test public async testFindFilteredByApplicationCluster() {
const wsc1: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "us02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
};
await this.db.save(wsc1);
await this.db.save(wsc2);
const wscs = await this.db.findFiltered({ applicationCluster: "eu02" });
expect(wscs.length).to.equal(1);
expect(wscs[0].name).to.equal("eu71");
}
}
module.exports = WorkspaceClusterDBSpec;