Skip to content

Commit

Permalink
feat: demo cluster api
Browse files Browse the repository at this point in the history
  • Loading branch information
panuhorsmalahti committed Jun 27, 2024
1 parent a709642 commit 31a5dd2
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
TOKEN_HOST: ${{ secrets.TOKEN_HOST }}
strategy:
matrix:
node-version: [16]
node-version: [18]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
max-parallel: 1
fail-fast: false
matrix:
node-version: [16, 18]
node-version: [18]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
Expand Down
23 changes: 23 additions & 0 deletions integration-test/DemoClusterService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { config } from "./configuration";
import { testPlatformFactory } from "./utils";
import type { TestPlatform } from "./utils";

jest.setTimeout(10000);

describe("DemoClusterService", () => {
const [userBob] = config.users;
let bobPlatform: TestPlatform;

beforeAll(async () => {
bobPlatform = await testPlatformFactory(userBob.username, userBob.password);
});

describe("getConfig", () => {
it("returns kubeconfig file", async () => {
const config = await bobPlatform.client.demoCluster.getConfig();

expect(config.startsWith("apiVersion: v1")).toBeTruthy();
expect(typeof config).toBe("string");
});
});
});
4 changes: 4 additions & 0 deletions integration-test/TeamService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("TeamService", () => {
name: existingSpace.name,
queryString: "join=teams",
});

teams = joinedSpace.teams as any as Team[];
});

Expand All @@ -48,6 +49,7 @@ describe("TeamService", () => {

it("throws CantRemoveLastTeamUser if removing last user from Owner team", async () => {
const ownerTeam = teams.find((team) => team.kind === "Owner");

expect(ownerTeam).toBeTruthy();

return expect(
Expand All @@ -60,6 +62,7 @@ describe("TeamService", () => {

it("throws UserNameNotFoundException if removing user not in Team", async () => {
const ownerTeam = teams.find((team) => team.kind === "Owner");

expect(ownerTeam).toBeTruthy();

return expect(
Expand All @@ -72,6 +75,7 @@ describe("TeamService", () => {

it("throws ForbiddenException if removing user from another user", async () => {
const ownerTeam = teams.find((team) => team.kind === "Owner");

expect(ownerTeam).toBeTruthy();

return expect(
Expand Down
11 changes: 8 additions & 3 deletions integration-test/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ export const config = {
subscriptionId: getEnvironmentalVariable("STAGING_SUBSCRIPTION_ID_2"),
},
],
keyCloakAddress: getEnvironmentalVariable("KEYCLOAK_ADDRESS"),
keyCloakAddress:
getEnvironmentalVariable("KEYCLOAK_ADDRESS") ||
"https://keycloak.lc-staging1.staging-k8slens.cloud",
keycloakClientId: "lens-extension",
keycloakRealm: getEnvironmentalVariable("KEYCLOAK_REALM"),
apiEndpointAddress: getEnvironmentalVariable("API_ENDPOINT_ADDRESS"),
tokenHost: getEnvironmentalVariable("TOKEN_HOST"),
apiEndpointAddress:
getEnvironmentalVariable("API_ENDPOINT_ADDRESS") ||
"https://api.lc-staging1.staging-k8slens.cloud",
tokenHost:
getEnvironmentalVariable("TOKEN_HOST") || "https://frontend.lc-staging1.staging-k8slens.cloud",
};
7 changes: 4 additions & 3 deletions integration-test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { config } from "./configuration";

export class TestPlatform {
public fakeToken?: string;

public readonly client: LensPlatformClient;

constructor(private readonly accessToken: string) {
Expand All @@ -26,14 +27,14 @@ export const testPlatformFactory = async (username: string, password: string) =>
secret: "<client-secret>",
},
auth: {
tokenHost: config.tokenHost,
tokenHost: config.keyCloakAddress,
tokenPath: "/auth/realms/lensCloud/protocol/openid-connect/token",
},
});

const tokenParams = {
username: username,
password: password,
username,
password,
scope: "openid",
};

Expand Down
2 changes: 1 addition & 1 deletion jest.integration-test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const swcConfig = JSON.parse(fs.readFileSync(`${__dirname}/.test.swcrc`, "utf-8"
module.exports = {
globalSetup: `${__dirname}/integration-test/setup.ts`,
moduleFileExtensions: ["js", "json", "ts"],
testPathIgnorePatterns: ["dist"],
testPathIgnorePatterns: ["src", "dist"],
testRegex: ".*\\.test\\.ts$",
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest", swcConfig],
Expand Down
23 changes: 23 additions & 0 deletions src/DemoClusterService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Base } from "./Base";
import { throwExpected } from "./exceptions";

type ConfigResponse = string;

/**
*
* The class for consuming all `DemoCluster` resources.
*
*/
class DemoClusterService extends Base {
async getConfig(): Promise<ConfigResponse> {
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
const url = `${apiEndpointAddress}/demo-cluster/config`;
const response = await throwExpected(async () => fetch.get(url), {
unauthenticated: true,
} as any);

return response as unknown as ConfigResponse;
}
}

export { DemoClusterService };
4 changes: 4 additions & 0 deletions src/LensPlatformClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UserRolesService } from "./UserRolesService";
import http from "http";
import https from "https";
import { LensDesktopKubeService } from "./LensDesktopKubeService";
import { DemoClusterService } from "./DemoClusterService";
import { SSOService } from "./SSOService";

// Axios defaults to xhr adapter if XMLHttpRequest is available.
Expand Down Expand Up @@ -161,6 +162,8 @@ class LensPlatformClient {

lensDesktopKube: LensDesktopKubeService;

demoCluster: DemoClusterService;

space: SpaceService;

roles: UserRolesService;
Expand Down Expand Up @@ -213,6 +216,7 @@ class LensPlatformClient {

this.user = new UserService(this);
this.lensDesktopKube = new LensDesktopKubeService(this);
this.demoCluster = new DemoClusterService(this);
this.space = new SpaceService(this);
this.roles = new UserRolesService(this);
this.team = new TeamService(this);
Expand Down

0 comments on commit 31a5dd2

Please sign in to comment.