mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
add another test
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
486083ddba
commit
8856d8f812
@ -448,11 +448,25 @@ describe("pre 3.6.0-beta.1 config with an existing cluster", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("getClusterIdFromHost", () => {
|
describe("getClusterIdFromHost", () => {
|
||||||
|
const clusterFakeId = "fe540901-0bd6-4f6c-b472-bce1559d7c4a";
|
||||||
|
|
||||||
it("should return undefined for non cluster frame hosts", () => {
|
it("should return undefined for non cluster frame hosts", () => {
|
||||||
expect(getClusterIdFromHost("localhost:45345")).toBeUndefined();
|
expect(getClusterIdFromHost("localhost:45345")).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return undefined for non cluster frame hosts", () => {
|
it("should return ClusterId for cluster frame hosts", () => {
|
||||||
expect(getClusterIdFromHost("fe540901-0bd6-4f6c-b472-bce1559d7c4a.localhost:59110")).toBe("fe540901-0bd6-4f6c-b472-bce1559d7c4a");
|
expect(getClusterIdFromHost(`${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return ClusterId for cluster frame hosts with additional subdomains", () => {
|
||||||
|
expect(getClusterIdFromHost(`abc.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.vwx.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
|
expect(getClusterIdFromHost(`abc.def.ghi.jkl.mno.pqr.stu.vwx.yz.${clusterFakeId}.localhost:59110`)).toBe(clusterFakeId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -357,12 +357,11 @@ export const clusterStore = ClusterStore.getInstance<ClusterStore>();
|
|||||||
export function getClusterIdFromHost(host: string): ClusterId | undefined {
|
export function getClusterIdFromHost(host: string): ClusterId | undefined {
|
||||||
// e.g host == "%clusterId.localhost:45345"
|
// e.g host == "%clusterId.localhost:45345"
|
||||||
const subDomains = host.split(":")[0].split(".");
|
const subDomains = host.split(":")[0].split(".");
|
||||||
|
const lastTwoParts = subDomains.slice(-2);
|
||||||
|
|
||||||
if (subDomains.length >= 2) {
|
lastTwoParts.pop(); // remove last entry (namely "localhost")
|
||||||
return subDomains[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
return lastTwoParts[0]; // ClusterId or undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getClusterFrameUrl(clusterId: ClusterId) {
|
export function getClusterFrameUrl(clusterId: ClusterId) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user