@@ -7,6 +7,7 @@ import * as cdk from '@aws-cdk/core';
7
7
import * as cxapi from '@aws-cdk/cx-api' ;
8
8
import * as ecs from '../lib' ;
9
9
import { AppProtocol } from '../lib' ;
10
+ import { Duration } from '@aws-cdk/core' ;
10
11
11
12
describe ( 'container definition' , ( ) => {
12
13
describe ( 'When creating a Task Definition' , ( ) => {
@@ -1691,6 +1692,161 @@ describe('container definition', () => {
1691
1692
} ) . toThrow ( / A t l e a s t o n e a r g u m e n t m u s t b e s u p p l i e d f o r h e a l t h c h e c k c o m m a n d ./ ) ;
1692
1693
} ) ;
1693
1694
1695
+ test ( 'throws when setting Health Check with invalid interval because of too short' , ( ) => {
1696
+ // GIVEN
1697
+ const stack = new cdk . Stack ( ) ;
1698
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'TaskDef' ) ;
1699
+
1700
+ // WHEN
1701
+ taskDefinition . addContainer ( 'cont' , {
1702
+ image : ecs . ContainerImage . fromRegistry ( 'test' ) ,
1703
+ memoryLimitMiB : 1024 ,
1704
+ healthCheck : {
1705
+ command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1706
+ interval : Duration . seconds ( 4 ) ,
1707
+ timeout : Duration . seconds ( 30 ) ,
1708
+ } ,
1709
+ } ) ;
1710
+
1711
+ // THEN
1712
+ expect ( ( ) => {
1713
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1714
+ ContainerDefinitions : [
1715
+ {
1716
+ HealthCheck : {
1717
+ Command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1718
+ Interval : 4 ,
1719
+ } ,
1720
+ } ,
1721
+ ] ,
1722
+ } ) ;
1723
+ } ) . toThrow ( / I n t e r v a l m u s t b e b e t w e e n 5 s e c o n d s a n d 3 0 0 s e c o n d s ./ ) ;
1724
+ } ) ;
1725
+
1726
+ test ( 'throws when setting Health Check with invalid interval because of too long' , ( ) => {
1727
+ // GIVEN
1728
+ const stack = new cdk . Stack ( ) ;
1729
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'TaskDef' ) ;
1730
+
1731
+ // WHEN
1732
+ taskDefinition . addContainer ( 'cont' , {
1733
+ image : ecs . ContainerImage . fromRegistry ( 'test' ) ,
1734
+ memoryLimitMiB : 1024 ,
1735
+ healthCheck : {
1736
+ command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1737
+ interval : Duration . seconds ( 301 ) ,
1738
+ timeout : Duration . seconds ( 30 ) ,
1739
+ } ,
1740
+ } ) ;
1741
+
1742
+ // THEN
1743
+ expect ( ( ) => {
1744
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1745
+ ContainerDefinitions : [
1746
+ {
1747
+ HealthCheck : {
1748
+ Command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1749
+ Interval : 4 ,
1750
+ } ,
1751
+ } ,
1752
+ ] ,
1753
+ } ) ;
1754
+ } ) . toThrow ( / I n t e r v a l m u s t b e b e t w e e n 5 s e c o n d s a n d 3 0 0 s e c o n d s ./ ) ;
1755
+ } ) ;
1756
+
1757
+ test ( 'throws when setting Health Check with invalid timeout because of too short' , ( ) => {
1758
+ // GIVEN
1759
+ const stack = new cdk . Stack ( ) ;
1760
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'TaskDef' ) ;
1761
+
1762
+ // WHEN
1763
+ taskDefinition . addContainer ( 'cont' , {
1764
+ image : ecs . ContainerImage . fromRegistry ( 'test' ) ,
1765
+ memoryLimitMiB : 1024 ,
1766
+ healthCheck : {
1767
+ command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1768
+ interval : Duration . seconds ( 40 ) ,
1769
+ timeout : Duration . seconds ( 1 ) ,
1770
+ } ,
1771
+ } ) ;
1772
+
1773
+ // THEN
1774
+ expect ( ( ) => {
1775
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1776
+ ContainerDefinitions : [
1777
+ {
1778
+ HealthCheck : {
1779
+ Command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1780
+ Interval : 4 ,
1781
+ } ,
1782
+ } ,
1783
+ ] ,
1784
+ } ) ;
1785
+ } ) . toThrow ( / T i m e o u t m u s t b e b e t w e e n 2 s e c o n d s a n d 1 2 0 s e c o n d s ./ ) ;
1786
+ } ) ;
1787
+
1788
+ test ( 'throws when setting Health Check with invalid timeout because of too long' , ( ) => {
1789
+ // GIVEN
1790
+ const stack = new cdk . Stack ( ) ;
1791
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'TaskDef' ) ;
1792
+
1793
+ // WHEN
1794
+ taskDefinition . addContainer ( 'cont' , {
1795
+ image : ecs . ContainerImage . fromRegistry ( 'test' ) ,
1796
+ memoryLimitMiB : 1024 ,
1797
+ healthCheck : {
1798
+ command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1799
+ interval : Duration . seconds ( 150 ) ,
1800
+ timeout : Duration . seconds ( 130 ) ,
1801
+ } ,
1802
+ } ) ;
1803
+
1804
+ // THEN
1805
+ expect ( ( ) => {
1806
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1807
+ ContainerDefinitions : [
1808
+ {
1809
+ HealthCheck : {
1810
+ Command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1811
+ Interval : 4 ,
1812
+ } ,
1813
+ } ,
1814
+ ] ,
1815
+ } ) ;
1816
+ } ) . toThrow ( / T i m e o u t m u s t b e b e t w e e n 2 s e c o n d s a n d 1 2 0 s e c o n d s ./ ) ;
1817
+ } ) ;
1818
+
1819
+ test ( 'throws when setting Health Check with invalid interval and timeout because timeout is longer than interval' , ( ) => {
1820
+ // GIVEN
1821
+ const stack = new cdk . Stack ( ) ;
1822
+ const taskDefinition = new ecs . Ec2TaskDefinition ( stack , 'TaskDef' ) ;
1823
+
1824
+ // WHEN
1825
+ taskDefinition . addContainer ( 'cont' , {
1826
+ image : ecs . ContainerImage . fromRegistry ( 'test' ) ,
1827
+ memoryLimitMiB : 1024 ,
1828
+ healthCheck : {
1829
+ command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1830
+ interval : Duration . seconds ( 10 ) ,
1831
+ timeout : Duration . seconds ( 30 ) ,
1832
+ } ,
1833
+ } ) ;
1834
+
1835
+ // THEN
1836
+ expect ( ( ) => {
1837
+ Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::ECS::TaskDefinition' , {
1838
+ ContainerDefinitions : [
1839
+ {
1840
+ HealthCheck : {
1841
+ Command : [ 'CMD-SHELL' , 'curl localhost:8000' ] ,
1842
+ Interval : 4 ,
1843
+ } ,
1844
+ } ,
1845
+ ] ,
1846
+ } ) ;
1847
+ } ) . toThrow ( / H e a l t h c h e c k i n t e r v a l s h o u l d b e l o n g e r t h a n t i m e o u t ./ ) ;
1848
+ } ) ;
1849
+
1694
1850
test ( 'can specify Health Check values in shell form' , ( ) => {
1695
1851
// GIVEN
1696
1852
const stack = new cdk . Stack ( ) ;
0 commit comments