diff --git a/components/gitpod-db/src/workspace-cluster-db.spec.db.ts b/components/gitpod-db/src/workspace-cluster-db.spec.db.ts index 33c9bc6196c950..9388d49c90e725 100644 --- a/components/gitpod-db/src/workspace-cluster-db.spec.db.ts +++ b/components/gitpod-db/src/workspace-cluster-db.spec.db.ts @@ -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; @@ -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", @@ -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() { @@ -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", @@ -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; } @@ -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", @@ -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() { @@ -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", @@ -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); } }