Skip to content

Commit

Permalink
ui/test: update the test for volume status
Browse files Browse the repository at this point in the history
- should return Ready when Ready condition is True
Refs: #2245
  • Loading branch information
ChengYanJin committed Feb 18, 2020
1 parent c77366b commit 45e9933
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions ui/src/services/NodeVolumesUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
STATUS_TERMINATING,
STATUS_PENDING,
STATUS_FAILED,
STATUS_AVAILABLE,
STATUS_READY,
} from '../constants';
import {
computeVolumeGlobalStatus,
Expand Down Expand Up @@ -278,7 +278,7 @@ it('should return false when volume is available and there is no PV', () => {

it('should return Unkown when called with wrong input', () => {
const volume = {
'status': {'conditions': []}
status: { conditions: [] },
};
const result = computeVolumeGlobalStatus('test', volume);
expect(result).toEqual(STATUS_UNKNOWN);
Expand All @@ -290,57 +290,53 @@ it('should return Unkown when volume has no status', () => {
});

it('should return Unkown when volume has no conditions', () => {
const volumeStatus = {'conditions': []};
const volumeStatus = { conditions: [] };
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_UNKNOWN);
});

it('should return Unkown when volume has no Ready condition', () => {
const volumeStatus = {'conditions': [{'type': 'nope'}]};
const volumeStatus = { conditions: [{ type: 'nope' }] };
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_UNKNOWN);
});

it('should return Available when Ready condition is True', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'True'}
]};
it('should return Ready when Ready condition is True', () => {
const volumeStatus = { conditions: [{ type: 'Ready', status: 'True' }] };
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_AVAILABLE);
expect(result).toEqual(STATUS_READY);
});

it('should return Failed when Ready condition is False', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'False'}
]};
const volumeStatus = { conditions: [{ type: 'Ready', status: 'False' }] };
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_FAILED);
});

it('should return Pending when Ready condition is Unknown/Pending', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'Unknown', 'reason': 'Pending'}
]};
const volumeStatus = {
conditions: [{ type: 'Ready', status: 'Unknown', reason: 'Pending' }],
};
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_PENDING);
});

it('should return Pending when Ready condition is Unknown/Terminating', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'Unknown', 'reason': 'Terminating'}
]};
const volumeStatus = {
conditions: [{ type: 'Ready', status: 'Unknown', reason: 'Terminating' }],
};
const result = computeVolumeGlobalStatus('test', volumeStatus);
expect(result).toEqual(STATUS_TERMINATING);
});

// }}}
// volumeGetError {{{

const NO_ERROR = ['', '']
const NO_ERROR = ['', ''];

it('should return no error when called with wrong input', () => {
const volume = {
'status': {'conditions': []}
status: { conditions: [] },
};
const result = volumeGetError(volume);
expect(result).toEqual(NO_ERROR);
Expand All @@ -352,42 +348,40 @@ it('should return no error when called with no status', () => {
});

it('should return no error when called with no conditions', () => {
const volumeStatus = {'conditions': []};
const volumeStatus = { conditions: [] };
const result = volumeGetError(volumeStatus);
expect(result).toEqual(NO_ERROR);
});

it('should return no error when called with no Ready conditions', () => {
const volumeStatus = {'conditions': [{'type': 'nope'}]};
const volumeStatus = { conditions: [{ type: 'nope' }] };
const result = volumeGetError(volumeStatus);
expect(result).toEqual(NO_ERROR);
});

it('should return no error when called with successful Ready condition', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'True'}
]};
const volumeStatus = { conditions: [{ type: 'Ready', status: 'True' }] };
const result = volumeGetError(volumeStatus);
expect(result).toEqual(NO_ERROR);
});

it('should return no error when called with pending Ready condition', () => {
const volumeStatus = {'conditions': [
{'type': 'Ready', 'status': 'Unknown'}
]};
const volumeStatus = { conditions: [{ type: 'Ready', status: 'Unknown' }] };
const result = volumeGetError(volumeStatus);
expect(result).toEqual(NO_ERROR);
});

it('should return error when called with failed Ready condition', () => {
const volumeStatus = {'conditions': [
{
'type': 'Ready',
'status': 'False',
'reason': 'CreationError',
'message': 'BOOM'
}
]};
const volumeStatus = {
conditions: [
{
type: 'Ready',
status: 'False',
reason: 'CreationError',
message: 'BOOM',
},
],
};
const result = volumeGetError(volumeStatus);
expect(result).toEqual(['CreationError', 'BOOM']);
});
Expand Down

0 comments on commit 45e9933

Please sign in to comment.