-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: get the execution API based methods to check capabilities and re…
…port server version info on error (#145)
- Loading branch information
Showing
7 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Client } from "../../client"; | ||
import { processConfiguration } from "../../clientConfiguration.test"; | ||
import { checkForCapability } from "./capability"; | ||
|
||
describe("Check capabilities", () => { | ||
let client: Client; | ||
|
||
beforeAll(async () => { | ||
client = await Client.create(processConfiguration()); | ||
console.log(`Client connected to API endpoint successfully.`); | ||
}); | ||
|
||
test("Returns no error for something we know exists", async () => { | ||
const result = await checkForCapability(client, "GetAllSpacesRequest", "2018.1"); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
test("Returns false for something we know does not exist", async () => { | ||
const result = await checkForCapability(client, "SomeMadeUpRequest", "2023.1"); | ||
expect(result).toBe( | ||
"The Octopus instance does not support SomeMadeUpRequest, it needs to be at least version 2023.1 to get access to the feature you are trying to use." | ||
); | ||
}); | ||
}); |
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,23 @@ | ||
import { Client } from "../../client"; | ||
import { apiLocation } from "../../apiLocation"; | ||
import { OctopusError } from "../../octopusError"; | ||
|
||
interface CapabilitiesResponse { | ||
Capabilities: string[]; | ||
} | ||
|
||
export async function checkForCapability(client: Client, capabilityName: string, minimumVersionThisWouldAppearIn: string): Promise<string | null> { | ||
try { | ||
const response = await client.get<CapabilitiesResponse>(`${apiLocation}/capabilities`); | ||
return response.Capabilities.filter((c) => c === capabilityName).length === 1 | ||
? null | ||
: `The Octopus instance does not support ${capabilityName}, it needs to be at least version ${minimumVersionThisWouldAppearIn} to get access to the feature you are trying to use.`; | ||
} catch (e) { | ||
if (e instanceof OctopusError) { | ||
if (e.StatusCode && e.StatusCode != 200) { | ||
return `The Octopus instance does not support the Capabilities API, you will need to upgrade it at least 2022.3 to get access to the feature you are trying to use.`; | ||
} | ||
} | ||
return `Unknown error occurred trying to determine if the Octopus instance supports ${capabilityName}.`; | ||
} | ||
} |
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 @@ | ||
export * from "./capability"; |
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