Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node-v15 pipeline test failures #8892

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,6 +9,7 @@ import {
BuildConfigModel,
SecretModel,
} from '@console/internal/models';
import * as pipelineOverviewUtils from '@console/pipelines-plugin/src/components/pipelines/pipeline-overview/pipeline-overview-utils';
import * as pipelineUtils from '@console/pipelines-plugin/src/components/import/pipeline/pipeline-template-utils';
import { PipelineModel } from '@console/pipelines-plugin/src/models';
import { Resources } from '../import-types';
Expand Down Expand Up @@ -154,13 +155,11 @@ describe('Import Submit Utils', () => {
});

describe('createPipelineResource tests', () => {
beforeAll(() => {
jest
.spyOn(k8s, 'k8sCreate')
.mockImplementation((model, data, dryRun) => Promise.resolve({ model, data, dryRun }));
beforeEach(() => {
jest.spyOn(k8s, 'k8sCreate').mockImplementation((model, data) => Promise.resolve(data));
});

afterAll(() => {
afterEach(() => {
jest.restoreAllMocks();
});

Expand All @@ -184,10 +183,9 @@ describe('Import Submit Utils', () => {
},
};
});
const createPipelineRunResourceSpy = jest.spyOn(
pipelineUtils,
'createPipelineRunForImportFlow',
);
const createPipelineRunResourceSpy = jest
.spyOn(pipelineUtils, 'createPipelineRunForImportFlow')
.mockImplementation(jest.fn()); // can't handle a no-arg spyOn invoke, stub

await createOrUpdateResources(t, mockData, buildImage.obj, false, false, 'create');
expect(createPipelineResourceSpy).toHaveBeenCalledWith(
Expand All @@ -201,7 +199,6 @@ describe('Import Submit Utils', () => {
mockData.image.tag,
);
expect(createPipelineRunResourceSpy).toHaveBeenCalledTimes(1);
expect(createPipelineRunResourceSpy).not.toThrowError();
done();
});

Expand Down Expand Up @@ -230,19 +227,28 @@ describe('Import Submit Utils', () => {
mockData.docker.dockerfilePath,
mockData.image.tag,
);
const pipelineRunResource = returnValue[1].data;
const pipelineRunResource = returnValue[1];
expect(pipelineRunResource.metadata.name.includes(mockData.name)).toEqual(true);
done();
});

it('should suppress the error if the pipelinerun creation fails with the error', async (done) => {
const mockData = _.cloneDeep(defaultData);
mockData.resources = Resources.Kubernetes;
mockData.pipeline.enabled = true;
const createPipelineResourceSpy = jest.spyOn(pipelineUtils, 'createPipelineForImportFlow');

const createPipelineRunSpy = jest
// Suppress the console log for a cleaner test
jest.spyOn(console, 'log').mockImplementation(jest.fn());

// Force an exception
jest
.spyOn(pipelineUtils, 'createPipelineRunForImportFlow')
.mockImplementation(() => Promise.reject(new Error('PipelineRun error')));
.mockImplementation(() =>
Promise.reject(new Error('PipelineRun errored out and was not caught')),
);

// Make sure the fallback is called
const setPipelineNotStartedSpy = jest.spyOn(pipelineOverviewUtils, 'setPipelineNotStarted');

const returnValue = await createOrUpdateResources(
t,
Expand All @@ -252,11 +258,13 @@ describe('Import Submit Utils', () => {
false,
'create',
);
const models = returnValue.map((r) => r['model.kind']);
expect(createPipelineResourceSpy).not.toThrow();
expect(createPipelineRunSpy).not.toThrow();
expect(returnValue).toBeDefined();
expect(models).toHaveLength(6);
expect(setPipelineNotStartedSpy).toHaveBeenCalled();
expect(returnValue).toHaveLength(6);

// re-enable logs for future tests
// eslint-disable-next-line no-console
(console.log as any).mockRestore();

done();
});

Expand Down
Expand Up @@ -409,6 +409,8 @@ export const managePipelineResources = async (
formData: GitImportFormData,
pipelineData: PipelineKind,
) => {
if (!formData) return;

const { name, git, pipeline, project, docker, image } = formData;
let managedPipeline: PipelineKind;
const pipelineName = pipelineData?.metadata?.name;
Expand Down
Expand Up @@ -110,8 +110,14 @@ describe('getPipelineName', () => {

describe('PipelineAction testing getPipelineRunData', () => {
it('expect null to be returned when no arguments are passed', () => {
// Suppress the error log when we don't have pipeline or pipeline run
jest.spyOn(console, 'error').mockImplementation(jest.fn());

const runData = getPipelineRunData();
expect(runData).toBeNull();

// eslint-disable-next-line no-console
(console.error as any).mockRestore();
});

it('expect pipeline run data to be returned when only Pipeline argument is passed', () => {
Expand Down