-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes Terraform table/list page crashing (#3705)
* More defensively parse timestamps
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
ui/src/components/Terraform/__tests__/TerraformListTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { TerraformObject } from '../../../api/terraform/types.pb'; | ||
import { getLastApplied } from '../TerraformListTable'; | ||
|
||
describe('getLastApplied', () => { | ||
const obj: TerraformObject = { | ||
conditions: [ | ||
{ | ||
type: 'Apply', | ||
status: 'True', | ||
timestamp: '2021-08-11T14:23:39Z', | ||
}, | ||
], | ||
}; | ||
|
||
it('should return the timestamp', () => { | ||
expect(getLastApplied(obj)).toBe('2021-08-11T14:23:39.000Z'); | ||
}); | ||
|
||
it('should return "-" if no timestamp', () => { | ||
const obj2: TerraformObject = { | ||
conditions: [ | ||
{ | ||
type: 'Apply', | ||
status: 'True', | ||
}, | ||
], | ||
}; | ||
expect(getLastApplied(obj2)).toBe('-'); | ||
}); | ||
|
||
it('should return "-" if no conditions', () => { | ||
const obj3: TerraformObject = {}; | ||
expect(getLastApplied(obj3)).toBe('-'); | ||
}); | ||
|
||
it('should return "-" if no conditions with type Apply', () => { | ||
const obj4: TerraformObject = { | ||
conditions: [ | ||
{ | ||
type: 'Apply1', | ||
status: 'True', | ||
timestamp: '2021-08-11T14:23:39Z', | ||
}, | ||
], | ||
}; | ||
expect(getLastApplied(obj4)).toBe('-'); | ||
}); | ||
|
||
it('should return "-" if the timestamp is not valid', () => { | ||
const obj5: TerraformObject = { | ||
conditions: [ | ||
{ | ||
type: 'Apply', | ||
status: 'True', | ||
timestamp: 'foo', | ||
}, | ||
], | ||
}; | ||
|
||
expect(getLastApplied(obj5)).toBe('-'); | ||
}); | ||
}); |