Skip to content

Commit

Permalink
* [e2e] implement hosts env utils
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Jun 13, 2024
1 parent 6e47deb commit 512c1bd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions cypress/models/host.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Node {
name: string;
customName: string;
}
6 changes: 1 addition & 5 deletions cypress/pageobjects/hosts.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const constants = new Constants();
import CruResourcePo from '@/utils/components/cru-resource.po';
import { HCI } from '@/constants/types'
import LabeledInputPo from '@/utils/components/labeled-input.po';
import { Node } from '@/models/host'

interface ValueInterface {
namespace?: string,
Expand All @@ -12,11 +13,6 @@ interface ValueInterface {
consoleUrl?: string,
}

export interface Node {
name: string;
customName: string;
}

export class HostsPage extends CruResourcePo {
private hostList = '.host-list';
private actionsDropdown = '.role-multi-action';
Expand Down
4 changes: 2 additions & 2 deletions cypress/testcases/virtualmachines/node-scheduling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VmsPage } from "@/pageobjects/virtualmachine.po";

import { generateName } from '@/utils/utils';
import { generateName, host as hostUtil } from '@/utils/utils';
import { Constants } from "@/constants/constants";

const vmPO = new VmsPage();
Expand All @@ -27,7 +27,7 @@ describe('Stop VM Negative', () => {
vmPO.setBasics('1', '1');
vmPO.setVolumes(volume);

const hostList = Cypress.env('host');
const hostList = hostUtil.list();
const host = hostList[0];

vmPO.setNodeScheduling({
Expand Down
6 changes: 4 additions & 2 deletions cypress/testcases/virtualmachines/scheduling.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { VmsPage } from "@/pageobjects/virtualmachine.po";
import { HostsPage, Node } from "@/pageobjects/hosts.po";
import { HostsPage } from "@/pageobjects/hosts.po";
import { host as hostsUtil } from '@/utils/utils';
import { Node } from '@/models/host'

const vms = new VmsPage();
const hosts = new HostsPage();
Expand All @@ -13,7 +15,7 @@ describe('VM scheduling on Specific node', () => {
});

it('Schedule VM on the Node which is Enable Maintenance Mode', () => {
const hostList = Cypress.env('host');
const hostList = hostsUtil.list();

const hostNames: string[] = hostList.map((node: Node) => node.customName || node.name);

Expand Down
12 changes: 11 additions & 1 deletion cypress/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import AdmZip from 'adm-zip';
import { Node } from '@/models/host'
/**
* This will validate the zip file by checking the contents. Assumes that this is in
* the downloads folder
Expand Down Expand Up @@ -47,7 +48,16 @@ export function base64Decode(string: string) {
return !string ? string : base64DecodeToBuffer(string.replace(/[-_]/g, char => char === '-' ? '+' : '/')).toString();
}

export const nodes = {
export const host = {
list(): Node[] {
const hosts = Cypress.env('host');

if (!hosts || hosts.length < 1) {
throw new Error("No hosts defined in cypress env");
}

return hosts;
},
filterWitnessNode: (hosts: {name: string, witnessNode: boolean}[]) => {
const ret = hosts.filter((host) => !host.witnessNode);

Expand Down

0 comments on commit 512c1bd

Please sign in to comment.