Skip to content

[db] Add extra assertions to workspace cluster db tests #14323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 94 additions & 7 deletions components/gitpod-db/src/workspace-cluster-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ 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 {
WorkspaceCluster,
WorkspaceClusterDB,
WorkspaceClusterWoTLS,
} from "@gitpod/gitpod-protocol/lib/workspace-cluster";
import { DBWorkspaceCluster } from "./typeorm/entity/db-workspace-cluster";
const expect = chai.expect;

Expand Down Expand Up @@ -42,6 +46,15 @@ export class WorkspaceClusterDBSpec {
maxScore: 100,
govern: true,
};
const wsc1a: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
Expand All @@ -53,22 +66,26 @@ export class WorkspaceClusterDBSpec {
};

await this.db.save(wsc1);
await this.db.save(wsc1a);
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");
expect((result as WorkspaceCluster).applicationCluster).to.equal("eu02");

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

// 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");
expect((result3 as WorkspaceCluster).applicationCluster).to.equal("eu02");
}

@test public async deleteByName() {
Expand All @@ -81,6 +98,15 @@ export class WorkspaceClusterDBSpec {
maxScore: 100,
govern: true,
};
const wsc1a: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
Expand All @@ -92,11 +118,13 @@ export class WorkspaceClusterDBSpec {
};

await this.db.save(wsc1);
await this.db.save(wsc1a);
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("eu71", "us02")).not.to.be.undefined;
expect(await this.db.findByName("us71", "eu02")).not.to.be.undefined;
}

Expand All @@ -110,6 +138,15 @@ export class WorkspaceClusterDBSpec {
maxScore: 100,
govern: true,
};
const wsc1a: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "eu02",
Expand All @@ -121,11 +158,13 @@ export class WorkspaceClusterDBSpec {
};

await this.db.save(wsc1);
await this.db.save(wsc1a);
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");
expect(wscs[0].applicationCluster).to.equal("eu02");
}

@test public async testFindFilteredByApplicationCluster() {
Expand All @@ -138,6 +177,15 @@ export class WorkspaceClusterDBSpec {
maxScore: 100,
govern: true,
};
const wsc1a: DBWorkspaceCluster = {
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
};
const wsc2: DBWorkspaceCluster = {
name: "us71",
applicationCluster: "us02",
Expand All @@ -149,11 +197,50 @@ export class WorkspaceClusterDBSpec {
};

await this.db.save(wsc1);
await this.db.save(wsc1a);
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");
const expectedClusters: WorkspaceClusterWoTLS[] = [
{
name: "eu71",
applicationCluster: "eu02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
admissionConstraints: [],
},
];
const actualClusters = await this.db.findFiltered({ applicationCluster: "eu02" });
expect(actualClusters.length).to.equal(1);
expect(actualClusters).to.deep.include.members(expectedClusters);

const expectedClusters2: WorkspaceClusterWoTLS[] = [
{
name: "eu71",
applicationCluster: "us02",
url: "some-url",
state: "cordoned",
score: 0,
maxScore: 0,
govern: false,
admissionConstraints: [],
},
{
name: "us71",
applicationCluster: "us02",
url: "some-url",
state: "available",
score: 100,
maxScore: 100,
govern: true,
admissionConstraints: [],
},
];
const wscs2 = await this.db.findFiltered({ applicationCluster: "us02" });
expect(wscs2.length).to.equal(2);
expect(wscs2).to.deep.include.members(expectedClusters2);
}
}

Expand Down