Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
n313893254 committed Dec 5, 2022
1 parent b39b022 commit 2a74e74
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 56 deletions.
15 changes: 1 addition & 14 deletions cypress/pageobjects/template.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface ValueInterface {
description?: string,
cpu?: string,
memory?: string,
image?: string,
}

export default class TemplatePage extends CruResourcePo {
Expand Down Expand Up @@ -51,20 +52,6 @@ export default class TemplatePage extends CruResourcePo {
this.clickAction(name, 'Add templateVersion')
}

deleteProgramlly(id:string) {
cy.window().then((window: any) => {
const store = window.$nuxt.$store

const resource = store.getters['harvester/byId'](HCI.VM_TEMPLATE, id)

cy.intercept('DELETE', `/v1/harvester/${this.realType}s/${id}*`).as('delete');
resource.remove()
cy.wait('@delete').then(res => {
expect(res.response?.statusCode, `Delete ${this.type}`).to.be.oneOf([200, 204]);
})
})
}

setBasics(cpu?: string, memery?: string, ssh?: {id?: string, createNew?: boolean, value?: string}) {
this.clickTab('Basics');
this.cpu().input(cpu);
Expand Down
31 changes: 19 additions & 12 deletions cypress/pageobjects/virtualmachine.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ interface ValueInterface {
createRunning?: boolean,
usbTablet?: boolean,
efiEnabled?: boolean,
userData?: string,
networkData?: string,
}

interface Volume {
Expand Down Expand Up @@ -364,14 +366,12 @@ export class VmsPage extends CruResourcePo {
return new YamlEditorPo(selector)
}

public checkState(target: string, valid: boolean = true, state: string) {
cy.wait(1000).get(this.searchInput).then(($search) => {
cy.wrap($search).click().type(target);
cy.contains(target).parentsUntil('tbody', 'tr').find('td.col-badge-state-formatter').contains(valid ? state : 'Pending', { timeout: constants.timeout.provisionTimeout }).should('be.visible');
});
}

public selectTemplateAndVersion({name, namespace, id, version}) {
public selectTemplateAndVersion({name, namespace, id, version}: {
name?: string,
namespace?: string,
id?: string,
version?: string,
}) {
cy.contains('Use VM Template').click()
this.template().select({option: id || `${namespace}/${name}`})
this.version().select({
Expand All @@ -384,14 +384,21 @@ export class VmsPage extends CruResourcePo {
this.multipleInstance().input('Multiple Instance')
}

setMultipleInstance(value) {
setMultipleInstance({namePrefix, count}: {
namePrefix?: string,
count?: string,
}) {
this.selectMultipleInstance()
this.namePrefix().input(value.namePrefix)
this.count().input(value.count)
this.namePrefix().input(namePrefix)
this.count().input(count)
}

setNodeScheduling({
radio, nodeName, selector
}: {
radio?: string,
nodeName?: string,
selector?: any,
}) {
this.clickTab('nodeScheduling');

Expand All @@ -400,7 +407,7 @@ export class VmsPage extends CruResourcePo {
const rulesRadio = new RadioButtonPo('.radio-group', ':contains("Run VM on node(s) matching scheduling rules")')

if (radio === 'any') {
anyRadio.input(null)
// anyRadio.input(null)
} else if (radio = 'Run VM on any available node') {
specificRadio.input('Run VM on specific node')

Expand Down
12 changes: 6 additions & 6 deletions cypress/testcases/templates/advanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ describe("template with EFI", () => {

vmPO.goToCreate()

vmPO.selectTemplateAndVersion({id: templateId, version: '2'})
vmPO.selectTemplateAndVersion({id: `${namespace}/${NAME}`, version: '1'})

const VM_NAME = generateName('test-efi')

const imageEnv = Cypress.env('image');

const value = {
const vmValue = {
name: VM_NAME,
cpu: '1',
memory: '1',
Expand All @@ -39,19 +39,19 @@ describe("template with EFI", () => {

cy.intercept('POST', '/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');

vms.create(value);
vmPO.create(vmValue);

cy.wait('@createVM').then(res => {
expect(res.response?.statusCode, 'Check create VM').to.equal(201);
expect(res.response?.body?.spec?.template?.spec?.domain?.features?.smm?.enabled, 'Check smm.enabled').to.equal(false);
expect(res.response?.body?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi?.secureBoot, 'Check efi.secureBoot').to.equal(false);
})

vms.goToConfigDetail(VM_NAME);
vmPO.goToConfigDetail(VM_NAME);

cy.get('.tab#advanced').click()
vms.efiEnabled().expectChecked()
vmPO.efiEnabled().expectChecked()

vms.deleteProgramlly(`${NAMESPACE}/${VM_NAME}`)
vmPO.deleteFromStore(`${namespace}/${VM_NAME}`)
})
})
8 changes: 4 additions & 4 deletions cypress/testcases/templates/template.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,22 @@ describe('Create vm using a template of non-default version', () => {
image: `default/${Cypress._.toLower(imageEnv.name)}`,
}];

vmPO.setNameNsDescription(vmName);
vmPO.setNameNsDescription(vmName, namespace);
vmPO.setVolumes(volume)
vmPO.setAdvancedOption({
efiEnabled: true
})

cy.intercept('POST', '/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');
vmPO.save(namespace);
vmPO.save();
cy.wait('@createVM').then(res => {
expect(res.response?.statusCode).to.equal(201);

expect(res.response?.body?.spec?.template?.spec?.domain?.features?.smm?.enabled, 'Check smm.enabled').to.equal(false);
expect(res.response?.body?.spec?.template?.spec?.domain?.firmware?.bootloader?.efi?.secureBoot, 'Check efi.secureBoot').to.equal(false);

vmPO.deleteProgramlly(res.response?.body?.id)
templates.deleteProgramlly(`${namespace}/${NAME}`)
vmPO.deleteFromStore(res.response?.body?.id)
templates.deleteFromStore(`${namespace}/${NAME}`)
})
});
});
35 changes: 18 additions & 17 deletions cypress/testcases/virtualmachines/advanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe('Create a new VM and add Enable USB tablet option', () => {
expect(res.response?.statusCode).to.equal(200);
const yaml = res.response?.body

const value:any = YAML.load(yaml)
const inputs = value?.spec?.template?.spec?.domain?.devices?.inputs || []
const yamlValue:any = YAML.load(yaml)
const inputs = yamlValue?.spec?.template?.spec?.domain?.devices?.inputs || []
const foundTablet = !!inputs.find((i:any) => i.name === 'tablet')

expect(foundTablet).to.equal(true);
Expand Down Expand Up @@ -161,7 +161,7 @@ sshpwauth: True

vms.setMultipleInstance({
namePrefix,
count: 3,
count: '3',
})

const value = {
Expand Down Expand Up @@ -245,7 +245,7 @@ describe("Create a VM to add user data", () => {
expect(userDataYAML, 'Check user data').to.equal(userData)
})

vms.deleteProgramlly(`${NAMESPACE}/${VM_NAME}`)
vms.deleteFromStore(`${NAMESPACE}/${VM_NAME}`)
})
})

Expand Down Expand Up @@ -298,7 +298,7 @@ network:
expect(networkDataYAML, 'Check network data').to.equal(networkDataYAML)
})

vms.deleteProgramlly(`${NAMESPACE}/${VM_NAME}`)
vms.deleteFromStore(`${NAMESPACE}/${VM_NAME}`)
})
})

Expand All @@ -318,14 +318,14 @@ network:
* 2. Observe the time taken for the system to start the vms.
* 3. Observe the pattern of the vms get allocated on the nodes. Like how many vm on each nodes are created. Is there a pattern?
*/
describe("Create multiple instances of the vm with raw image", () => {
describe("Create multiple instances of the vm with raw image", () => {
it('Create multiple instances of the vm with raw image', () => {
cy.login();

vms.goToCreate();

const namePrefix = generateName('test-multiple-instances')
const NAMESPACE = 'default'
const namespace = 'default'

const imageEnv = Cypress.env('image');
const userData = `cloud-config
Expand All @@ -336,21 +336,22 @@ sshpwauth: True

vms.setMultipleInstance({
namePrefix,
count: 3,
count: '3',
})

const value = {
cpu: '2',
memory: '4',
image: Cypress._.toLower(imageEnv.name),
namespace: NAMESPACE,
userData,
}

cy.intercept('POST', '/v1/harvester/kubevirt.io.virtualmachines/*').as('createVM');
cy.intercept('POST', '/v1/harvester/secrets/*').as('createSecret');

vms.setValue(value);
const volume = [{
buttonText: 'Add Volume',
create: false,
image: `default/${Cypress._.toLower(imageEnv.name)}`,
}];

vms.setNameNsDescription(namePrefix, namespace);
vms.setBasics('1', '1');
vms.setVolumes(volume);

vms.save()

cy.wait('@createVM').then(res => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/testcases/virtualmachines/virtual-machine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ describe("Delete VM with exported image", () => {
cy.wait('@deleteVM').then(res => {
expect(res.response?.statusCode, 'Delete VM').to.be.oneOf([200, 204]);

imagePO.delete(imageName)
imagePO.delete(namespace, imageName)
})
})
});
Expand Down
4 changes: 2 additions & 2 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const generateName = (prefix: string) => {
return `${prefix}-${Date.now()}`
}

export function base64DecodeToBuffer(string) {
export function base64DecodeToBuffer(string: string) {
if (string === null || typeof string === 'undefined') {
return string;
}
Expand All @@ -43,6 +43,6 @@ export function base64DecodeToBuffer(string) {
}
}

export function base64Decode(string) {
export function base64Decode(string: string) {
return !string ? string : base64DecodeToBuffer(string.replace(/[-_]/g, char => char === '-' ? '+' : '/')).toString();
}

0 comments on commit 2a74e74

Please sign in to comment.