Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/util/parse-workspace-id.spec.ts
2500 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import * as chai from "chai";
8
import { suite, test } from "@testdeck/mocha";
9
import {
10
isWorkspaceId,
11
matchesInstanceIdOrLegacyWorkspaceIdExactly,
12
matchesNewWorkspaceIdExactly,
13
parseWorkspaceIdFromHostname,
14
} from "./parse-workspace-id";
15
const expect = chai.expect;
16
17
@suite
18
export class ParseWorkspaceIdTest {
19
@test public parseWorkspaceIdFromHostname_fromWorkspaceLocation() {
20
const actual = parseWorkspaceIdFromHostname("moccasin-ferret-155799b3.ws-eu01.gitpod.io");
21
expect(actual).to.equal("moccasin-ferret-155799b3");
22
}
23
24
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocation() {
25
const actual = parseWorkspaceIdFromHostname("3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
26
expect(actual).to.equal("moccasin-ferret-155799b3");
27
}
28
29
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
30
const actual = parseWorkspaceIdFromHostname("webview-3000-moccasin-ferret-155799b3.ws-eu01.gitpod.io");
31
expect(actual).to.equal("moccasin-ferret-155799b3");
32
}
33
34
@test public parseWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
35
const actual = parseWorkspaceIdFromHostname(
36
"webview-3000-moccasin-ferret-155799b3.ws-eu01.some.subdomain.somehost.com",
37
);
38
expect(actual).to.equal("moccasin-ferret-155799b3");
39
}
40
41
// legacy mode
42
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspaceLocation() {
43
const actual = parseWorkspaceIdFromHostname("b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
44
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
45
}
46
47
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocation() {
48
const actual = parseWorkspaceIdFromHostname("3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io");
49
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
50
}
51
52
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefix() {
53
const actual = parseWorkspaceIdFromHostname(
54
"webview-3000-b7e0eaf8-ec73-44ec-81ea-04859263b656.ws-eu01.gitpod.io",
55
);
56
expect(actual).to.equal("b7e0eaf8-ec73-44ec-81ea-04859263b656");
57
}
58
59
@test public parseLegacyWorkspaceIdFromHostname_fromWorkspacePortLocationWithWebviewPrefixCustomHost() {
60
const actual = parseWorkspaceIdFromHostname(
61
"webview-3000-ca81a50f-09d7-465c-acd9-264a747d5351.ws-eu01.some.subdomain.somehost.com",
62
);
63
expect(actual).to.equal("ca81a50f-09d7-465c-acd9-264a747d5351");
64
}
65
66
// match - instance ID
67
@test public matchesInstanceIdOrLegacyWorkspaceIdExactly_positive() {
68
const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81ea-04859263b656");
69
expect(actual).to.be.true;
70
}
71
@test public matchesInstanceIdOrLegacyWorkspaceIdExactly_negative() {
72
const actual = matchesInstanceIdOrLegacyWorkspaceIdExactly("b7e0eaf8-ec73-44ec-81a-04859263b656");
73
expect(actual).to.be.false;
74
}
75
76
// match - new workspace ID
77
@test public matchesWorkspaceIdExactly_new_positive() {
78
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-155799b3");
79
expect(actual).to.be.true;
80
}
81
@test public matchesWorkspaceIdExactly_new_negative() {
82
const actual = matchesNewWorkspaceIdExactly("moccasin-ferret-15599b3");
83
expect(actual).to.be.false;
84
}
85
86
@test public isWorkspaceId_positive_new() {
87
const actual = isWorkspaceId("moccasin-ferret-155799b3");
88
expect(actual).to.be.true;
89
}
90
@test public isWorkspaceId_positive_legacy() {
91
const actual = isWorkspaceId("b7e0eaf8-ec73-44ec-81ea-04859263b656");
92
expect(actual).to.be.true;
93
}
94
@test public isWorkspaceId_negative_empty() {
95
const actual = isWorkspaceId(undefined);
96
expect(actual).to.be.false;
97
}
98
}
99
module.exports = new ParseWorkspaceIdTest();
100
101