Skip to content

Commit

Permalink
fix(integration): handle missing rev in git params
Browse files Browse the repository at this point in the history
  • Loading branch information
rottencandy committed Jan 3, 2024
1 parent 3ff9a4c commit d27dd67
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ describe('Create Utils', () => {
expect(getURLForParam(k8sResource.spec.resolverRef.params, ResolverRefParams.PATH)).toBe(
'https://github.com/redhat-appstudio/integration-examples/tree/main/pipelines/integration_pipeline_pass.yaml',
);
expect(
getURLForParam(
MockIntegrationTestsWithGit[3].spec.resolverRef.params,
ResolverRefParams.PATH,
),
).toBe('https://github.com/example/repo/tree/master/.tekton/pipeline.yaml');
});

it('Should set EC kind annotation', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const getURLForParam = (params: ResolverParam[], paramName: string): stri
}
if (paramName === ResolverRefParams.PATH && resolverParam) {
const branch = params.find((param) => param.name === ResolverRefParams.REVISION);
return `${checkedURL}/tree/${branch.value}/${resolverParam.value}`;
return `${checkedURL}/tree/${branch.value || 'master'}/${resolverParam.value}`;
}
if (paramName === ResolverRefParams.REVISION && resolverParam) {
return `${checkedURL}/tree/${resolverParam.value}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ export const MockIntegrationTestsWithGit: IntegrationTestScenarioKind[] = [
],
},
},
{
apiVersion: 'appstudio.redhat.com/v1alpha1',
kind: 'IntegrationTestScenario',
metadata: {
annotations: {
'app.kubernetes.io/display-name': 'Test 3',
},
name: 'test-app-test-4',
namespace: 'test-namespace',
uid: 'ed722704-74bc-4152-b27b-bee29cc7bfd3',
},
spec: {
application: 'test-app',
resolverRef: {
resolver: ResolverType.GIT,
params: [
{ name: 'url', value: 'https://github.com/example/repo' },
{ name: 'revision', value: '' },
{ name: 'pathInRepo', value: '.tekton/pipeline.yaml' },
],
},
},
},
];

export const MockIntegrationTestsWithParams: IntegrationTestScenarioKind[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ const IntegrationTestOverviewTab: React.FC<
integrationTest.spec.resolverRef.params,
param.name,
);
if (!param.value) {
return null;
}
return (
<DescriptionListGroup key={param.name}>
<DescriptionListTerm>{getLabelForParam(param.name)}</DescriptionListTerm>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { fireEvent, render, screen, configure } from '@testing-library/react';
import '@testing-library/jest-dom';
import { useModalLauncher } from '../../../modal/ModalProvider';
import {
MockIntegrationTestsWithBundles,
Expand Down Expand Up @@ -60,6 +61,11 @@ describe('IntegrationTestOverviewTab', () => {
); // path link
});

it('should not render param if value is not given', () => {
render(<IntegrationTestOverviewTab integrationTest={MockIntegrationTestsWithGit[3]} />);
expect(screen.queryByText('revision')).not.toBeInTheDocument();
});

it('should use the git url from the spec param', () => {
render(<IntegrationTestOverviewTab integrationTest={MockIntegrationTestsWithGit[0]} />);
expect(screen.getAllByRole('link')[0].getAttribute('href')).toBe('https://test-url');
Expand Down

0 comments on commit d27dd67

Please sign in to comment.