-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move Garden Cloud utils to own module (#5435)
* chore: move Garden Cloud utils to own module * chore: better type-safety * test: add missing tests for `getCloudDistributionName` * refactor: type for Cloud log section name * test: add missing tests for `getCloudLogSectionName` * chore: renamed new files to follow the naming convention
- Loading branch information
1 parent
783cc66
commit a7c7816
Showing
14 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Garden Technologies, Inc. <info@garden.io> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
import { DEFAULT_GARDEN_CLOUD_DOMAIN } from "../constants.js" | ||
|
||
export type CloudDistroName = "Cloud Dashboard" | "Garden Enterprise" | "Garden Cloud" | ||
|
||
/** | ||
* Returns "Garden Cloud" if domain matches https://<some-subdomain>.app.garden, | ||
* otherwise "Garden Enterprise". | ||
* | ||
* TODO: Return the distribution type from the API and store on the CloudApi class. | ||
*/ | ||
export function getCloudDistributionName(domain: string): CloudDistroName { | ||
if (domain === DEFAULT_GARDEN_CLOUD_DOMAIN) { | ||
return "Cloud Dashboard" | ||
} | ||
|
||
// TODO: consider using URL object instead. | ||
if (!domain.match(/^https:\/\/.+\.app\.garden$/i)) { | ||
return "Garden Enterprise" | ||
} | ||
|
||
return "Garden Cloud" | ||
} | ||
|
||
export type CloudLogSectionName = "cloud-dashboard" | "garden-cloud" | "garden-enterprise" | ||
|
||
export function getCloudLogSectionName(distroName: CloudDistroName): CloudLogSectionName { | ||
if (distroName === "Cloud Dashboard") { | ||
return "cloud-dashboard" | ||
} else if (distroName === "Garden Cloud") { | ||
return "garden-cloud" | ||
} else if (distroName === "Garden Enterprise") { | ||
return "garden-enterprise" | ||
} else { | ||
return distroName satisfies never | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Garden Technologies, Inc. <info@garden.io> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { describe } from "mocha" | ||
import { getCloudDistributionName, getCloudLogSectionName } from "../../../../src/util/cloud.js" | ||
import { DEFAULT_GARDEN_CLOUD_DOMAIN } from "../../../../src/constants.js" | ||
import { expect } from "chai" | ||
|
||
describe("garden-cloud", () => { | ||
describe("getCloudDistributionName", () => { | ||
context(`when domain name is ${DEFAULT_GARDEN_CLOUD_DOMAIN}`, () => { | ||
it(`returns "Cloud Dashboard" for ${DEFAULT_GARDEN_CLOUD_DOMAIN}`, () => { | ||
expect(getCloudDistributionName(DEFAULT_GARDEN_CLOUD_DOMAIN)).to.eql("Cloud Dashboard") | ||
}) | ||
}) | ||
|
||
context("when top-level domain is .garden", () => { | ||
context("when 2nd level domain is .app", () => { | ||
it(`returns "Garden Cloud" for https urls`, () => { | ||
expect(getCloudDistributionName("https://backend.app.garden")).to.eql("Garden Cloud") | ||
}) | ||
}) | ||
|
||
context("when 2nd level domain is not .app", () => { | ||
it(`returns "Garden Enterprise" for https urls`, () => { | ||
expect(getCloudDistributionName("https://backend.demo.garden")).to.eql("Garden Enterprise") | ||
}) | ||
}) | ||
}) | ||
|
||
context("when domain is something else", () => { | ||
it(`returns "Garden Enterprise" for https urls`, () => { | ||
expect(getCloudDistributionName("https://app.garden-proxy.net")).to.eql("Garden Enterprise") | ||
}) | ||
}) | ||
}) | ||
|
||
describe("getCloudLogSectionName", () => { | ||
it(`returns "cloud-dashboard" for "Cloud Dashboard"`, () => { | ||
expect(getCloudLogSectionName("Cloud Dashboard")).to.eql("cloud-dashboard") | ||
}) | ||
|
||
it(`returns "garden-cloud" for "Garden Cloud"`, () => { | ||
expect(getCloudLogSectionName("Garden Cloud")).to.eql("garden-cloud") | ||
}) | ||
|
||
it(`returns "garden-enterprise" for "Garden Enterprise"`, () => { | ||
expect(getCloudLogSectionName("Garden Enterprise")).to.eql("garden-enterprise") | ||
}) | ||
}) | ||
}) |