Skip to content

Commit

Permalink
Merge pull request #5074 from rhrazdil/refactor-console-shared
Browse files Browse the repository at this point in the history
Remove method searchYAML from console-shared
  • Loading branch information
openshift-merge-robot committed Apr 16, 2020
2 parents aca088f + 5cb3ae0 commit 293e553
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
13 changes: 0 additions & 13 deletions frontend/packages/console-shared/src/test-utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,6 @@ export const waitForStringNotInElement = (elem: any, needle: string) => {
};
};

/**
* Search YAML manifest for a given string. Return true if found.
* @param {string} needle String to search in YAML.
* @param {string} name Name of the resource.
* @param {string} namespace Namespace of the resource.
* @param {string} kind Kind of the resource.
* @returns {boolean} True if found, false otherwise.
*/
export function searchYAML(needle: string, name: string, namespace: string, kind: string): boolean {
const result = execSync(`kubectl get -o yaml -n ${namespace} ${kind} ${name}`).toString();
return result.search(needle) >= 0;
}

type CardInfo = {
text: string;
index: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isLoaded, resourceTitle } from '@console/internal-integration-tests/vie
import { activeTab } from '../../views/detailView.view';
import * as VmsListView from '../../views/vms.list.view';
import { TAB } from '../utils/consts';
import { getResourceObject } from '../utils/utils';

export class DetailView {
readonly name: string;
Expand All @@ -19,6 +20,10 @@ export class DetailView {
this.kind = instance.kind;
}

getResource() {
return getResourceObject(this.name, this.namespace, this.kind);
}

static async getResourceTitle() {
return resourceTitle.getText();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import {
removeLeakedResources,
waitForCount,
searchYAML,
withResource,
createResources,
deleteResources,
Expand All @@ -22,6 +21,7 @@ import {
} from '@console/shared/src/test-utils/utils';
import * as cloneDialogView from '../views/dialogs/cloneVirtualMachineDialog.view';
import { getVolumes, getDataVolumeTemplates } from '../../src/selectors/vm/selectors';
import { getLabels } from '../../src/selectors/selectors';
import { getResourceObject, getRandStr, createProject } from './utils/utils';
import {
CLONE_VM_TIMEOUT_SECS,
Expand Down Expand Up @@ -225,8 +225,8 @@ describe('Test clone VM.', () => {

it('Cloned VM has vm.kubevirt.io/name label.', () => {
expect(
searchYAML(`vm.kubevirt.io/name: ${vm.name}`, clonedVM.name, clonedVM.namespace, 'vm'),
).toBeTruthy();
_.has(getLabels(getResourceObject(vm.name, vm.namespace, 'vmi')), 'vm.kubevirt.io/name'),
).toBe(true);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
deleteResources,
createResource,
deleteResource,
searchYAML,
withResource,
} from '@console/shared/src/test-utils/utils';
import { createNICButton } from '../views/kubevirtDetailView.view';
Expand Down Expand Up @@ -82,7 +81,12 @@ describe('Add/remove disks and NICs on respective VM pages', () => {
await vm.addNIC(multusNetworkInterface);
expect(await vm.getAttachedNICs()).toContain(multusNetworkInterface);
await vm.action(VM_ACTION.Start);
expect(searchYAML(multusNetworkInterface.network, vm.name, vm.namespace, 'vmi')).toBe(true);
expect(
_.find(
getInterfaces(getResourceObject(vm.name, vm.namespace, 'vmi')),
(o) => o.name === multusNetworkInterface.name,
),
).toBeDefined();
await vm.action(VM_ACTION.Stop);
await vm.removeNIC(multusNetworkInterface.name);
expect(await vm.getAttachedNICs()).not.toContain(multusNetworkInterface);
Expand All @@ -100,9 +104,9 @@ describe('Add/remove disks and NICs on respective VM pages', () => {
}

// Verify the NIC is added in VM Manifest
const resource = getResourceObject(vm.name, vm.namespace, vm.kind);
const nic = _.find(getInterfaces(resource), (o) => o.name === multusNetworkInterface.name);
expect(nic).not.toBe(undefined);
expect(
_.find(getInterfaces(vm.getResource()), (o) => o.name === multusNetworkInterface.name),
).toBeDefined();

// Try to add the NIC again
await click(createNICButton, 1000);
Expand Down

0 comments on commit 293e553

Please sign in to comment.