Skip to content

Commit

Permalink
Merge pull request #30 from konflux-jp-repos/KFLUIXUI-187
Browse files Browse the repository at this point in the history
fix(pipeline): null check on status of taskrun
  • Loading branch information
sahil143 authored Dec 13, 2024
2 parents eabc80b + 0dd7d0f commit 09c1462
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ describe('useEnterpriseContractResultFromLogs', () => {
expect(result.current[0][0].warnings).toEqual(undefined);
});

it('should call tknResults when taskRun is empty array', () => {
mockUseTaskRuns.mockReturnValueOnce([[], true, undefined]);
mockGetTaskRunLogs.mockReturnValue(`asdfcdfadsf
[report-json] { "components": [] }
`);
const { result } = renderHook(() => useEnterpriseContractResultFromLogs('dummy-abcd'));
const [, loaded] = result.current;
expect(mockCommmonFetchJSON).toHaveBeenCalled();
expect(loaded).toBe(true);
expect(mockCommmonFetchJSON).toHaveBeenLastCalledWith(
'/api/v1/namespaces/test-ns/pods/pod-acdf/log?container=step-report-json&follow=true',
);
});

it('should filter out all 404 image url components from EC results', async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useEnterpriseContractResultFromLogs('dummy-abcd'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useEnterpriseContractResultFromLogs = (
const [ecJson, setEcJson] = React.useState<EnterpriseContractResult>();
const [ecLoaded, setEcLoaded] = React.useState<boolean>(false);
const ecResultOpts = React.useMemo(() => {
const podName = loaded && !error ? taskRun[0].status.podName : null;
const podName = loaded && !error ? taskRun?.[0]?.status?.podName : null;
return podName
? {
ns: namespace,
Expand All @@ -38,6 +38,9 @@ export const useEnterpriseContractResultFromLogs = (

React.useEffect(() => {
let unmount = false;
if (loaded && !ecResultOpts) {
setFetchTknLogs(true);
}
if (ecResultOpts) {
commonFetchJSON(getK8sResourceURL(PodModel, undefined, ecResultOpts))
.then((res: EnterpriseContractResult) => {
Expand All @@ -59,7 +62,7 @@ export const useEnterpriseContractResultFromLogs = (
return () => {
unmount = true;
};
}, [ecResultOpts]);
}, [ecResultOpts, loaded]);

React.useEffect(() => {
let unmount = false;
Expand Down

0 comments on commit 09c1462

Please sign in to comment.