Skip to content

Commit

Permalink
make request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil143 committed Mar 31, 2020
1 parent b530c37 commit 8e623fb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.odc-logs {
// color: var(--pf-global--BackgroundColor--100);
margin: 0;
padding: var(--pf-global--spacer--sm) var(--pf-global--spacer--md);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Logs: React.FC<LogsProps> = ({ resource, resourceStatus, container, onComp

React.useEffect(() => {
let ws: WSFactory;
let ignore: boolean = false;
if (!fetching) {
const urlOpts = {
ns: resNamespace,
Expand All @@ -59,8 +60,10 @@ const Logs: React.FC<LogsProps> = ({ resource, resourceStatus, container, onComp
if (resourceStatus === LOG_SOURCE_TERMINATED) {
coFetchText(watchURL)
.then((res) => {
appendMessage(res);
onComplete(name);
if (!ignore) {
appendMessage(res);
onComplete(name);
}
})
.catch(() => {});
} else {
Expand All @@ -77,9 +80,10 @@ const Logs: React.FC<LogsProps> = ({ resource, resourceStatus, container, onComp
onComplete(name);
});
}
setFetching(true);
if (!ignore) setFetching(true);
}
return () => {
ignore = true;
ws && ws.destroy();
};
}, [appendMessage, fetching, kind, name, onComplete, resName, resNamespace, resourceStatus]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const LogsWrapperComponent: React.FC<LogsWrapperComponentProps> = ({ obj,
return <MultiStreamLogs taskName={taskName} resource={ref.current} />;
};

export type MultiStreamLogsProps = {
type MultiStreamLogsProps = {
resource: PodKind;
taskName: string;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { cloneDeep } from 'lodash';
import { LogControls } from '@console/internal/components/utils';
import { MultiStreamLogsProps, MultiStreamLogs } from '../MultiStreamLogs';
import { MultiStreamLogs } from '../MultiStreamLogs';
import Logs from '../Logs';
import { podData } from './logs-test-data';

describe('MultiStreamLogs', () => {
let props: MultiStreamLogsProps;
let props: React.ComponentProps<typeof MultiStreamLogs>;

beforeEach(() => {
props = {
taskName: 'step-oc',
resource: podData,
resource: cloneDeep(podData),
};
});

it('should exist', () => {
const wrapper = shallow(<MultiStreamLogs {...props} />);
expect(wrapper.isEmptyRender()).toBe(false);
});

it('should not render logs when containers is not present', () => {
props.resource.spec.containers = [];
const wrapper = shallow(<MultiStreamLogs {...props} />);
Expand All @@ -36,4 +32,10 @@ describe('MultiStreamLogs', () => {
const wrapper = shallow(<MultiStreamLogs {...props} />);
expect(wrapper.find(LogControls).exists()).toBe(true);
});

it('should render number of logs equal to number of containers', () => {
const containersLength = props.resource.spec.containers.length;
const wrapper = shallow(<MultiStreamLogs {...props} />);
expect(wrapper.find(Logs)).toHaveLength(containersLength);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const getRenderContainers = (
sortedContainerStatus[containerIndex] = cs;
});

const firstrunningCont = sortedContainerStatus.findIndex(
const firstRunningCont = sortedContainerStatus.findIndex(
(container) => containerToLogSourceStatus(container) !== LOG_SOURCE_TERMINATED,
);
return {
containers: containers.slice(
0,
firstrunningCont === -1 ? containers.length : firstrunningCont + 1,
firstRunningCont === -1 ? containers.length : firstRunningCont + 1,
),
stillFetching: firstrunningCont !== -1,
stillFetching: firstRunningCont !== -1,
};
};

0 comments on commit 8e623fb

Please sign in to comment.