@@ -43,6 +43,12 @@ func TestParseV3WithOneFile(t *testing.T) {
43
43
HostPath : aws .String ("/dev/sda" ),
44
44
},
45
45
}
46
+ wordpressCon .HealthCheck = & ecs.HealthCheck {
47
+ Command : aws .StringSlice ([]string {"CMD-SHELL" , "curl -f http://localhost || exit 1" }),
48
+ Interval : aws .Int64 (int64 (90 )),
49
+ Timeout : aws .Int64 (int64 (10 )),
50
+ Retries : aws .Int64 (int64 (3 )),
51
+ }
46
52
wordpressCon .DNSServers = []string {"2.2.2.2" }
47
53
wordpressCon .DNSSearchDomains = []string {"wrd.search.com" , "wrd.search2.com" }
48
54
wordpressCon .Environment = []* ecs.KeyValuePair {
@@ -110,6 +116,13 @@ func TestParseV3WithOneFile(t *testing.T) {
110
116
IpAddress : aws .String ("10.0.0.0" ),
111
117
},
112
118
}
119
+ mysqlCon .HealthCheck = & ecs.HealthCheck {
120
+ // when test command is specified as a string, compose wraps it in CMD-SHELL
121
+ Command : aws .StringSlice ([]string {"CMD-SHELL" , "curl -f http://example.com || exit 1" }),
122
+ Interval : aws .Int64 (int64 (105 )),
123
+ Timeout : aws .Int64 (int64 (15 )),
124
+ Retries : aws .Int64 (int64 (5 )),
125
+ }
113
126
114
127
// set up file
115
128
composeFileString := `version: '3'
@@ -119,7 +132,7 @@ services:
119
132
- ALL
120
133
cap_drop:
121
134
- NET_ADMIN
122
- command:
135
+ command:
123
136
- echo "hello world"
124
137
image: wordpress
125
138
entrypoint: /wordpress/entry
@@ -162,14 +175,24 @@ services:
162
175
nice:
163
176
soft: 300
164
177
hard: 500
178
+ healthcheck:
179
+ test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
180
+ interval: 1m30s
181
+ timeout: 10s
182
+ retries: 3
165
183
mysql:
166
184
image: mysql
167
185
labels:
168
186
- "com.example.mysql=mysqllabel"
169
187
- "com.example.mysql2=anothermysql label"
170
188
user: mysqluser
171
189
extra_hosts:
172
- - "mysqlexhost:10.0.0.0"`
190
+ - "mysqlexhost:10.0.0.0"
191
+ healthcheck:
192
+ test: curl -f http://example.com || exit 1
193
+ interval: 1m45s
194
+ timeout: 15s
195
+ retries: 5`
173
196
174
197
tmpfile , err := ioutil .TempFile ("" , "test" )
175
198
assert .NoError (t , err , "Unexpected error in creating test file" )
@@ -608,6 +631,53 @@ services:
608
631
assert .ElementsMatch (t , expectedEnv , web .Environment , "Expected Environment to match" )
609
632
}
610
633
634
+ func TestParseV3HealthCheckDisabled (t * testing.T ) {
635
+ // set up expected ContainerConfig values
636
+ wordpressCon := adapter.ContainerConfig {}
637
+ wordpressCon .Name = "wordpress"
638
+ wordpressCon .Command = []string {"echo \" hello world\" " }
639
+ wordpressCon .Image = "wordpress"
640
+
641
+ // set up file
642
+ composeFileString := `version: '3'
643
+ services:
644
+ wordpress:
645
+ command:
646
+ - echo "hello world"
647
+ image: wordpress
648
+ healthcheck:
649
+ test: ["CMD-SHELL", "curl -f http://localhost || exit 1"]
650
+ interval: 1m30s
651
+ timeout: 10s
652
+ retries: 3
653
+ disable: true`
654
+
655
+ tmpfile , err := ioutil .TempFile ("" , "test" )
656
+ assert .NoError (t , err , "Unexpected error in creating test file" )
657
+
658
+ defer os .Remove (tmpfile .Name ())
659
+
660
+ _ , err = tmpfile .Write ([]byte (composeFileString ))
661
+ assert .NoError (t , err , "Unexpected error writing file" )
662
+
663
+ err = tmpfile .Close ()
664
+ assert .NoError (t , err , "Unexpected error closing file" )
665
+
666
+ // add files to projects
667
+ project := setupTestProject (t )
668
+ project .ecsContext .ComposeFiles = append (project .ecsContext .ComposeFiles , tmpfile .Name ())
669
+
670
+ // assert # and content of container configs matches expected
671
+ actualConfigs , err := project .parseV3 ()
672
+ assert .NoError (t , err , "Unexpected error parsing file" )
673
+
674
+ assert .Equal (t , 1 , len (* actualConfigs ))
675
+
676
+ wp , err := getContainerConfigByName (wordpressCon .Name , actualConfigs )
677
+ assert .NoError (t , err , "Unexpected error retrieving wordpress config" )
678
+ verifyContainerConfig (t , wordpressCon , * wp )
679
+ }
680
+
611
681
// TODO: add check for fields not used by V3, use to also check V1V2 ContainerConfigs?
612
682
func verifyContainerConfig (t * testing.T , expected , actual adapter.ContainerConfig ) {
613
683
assert .ElementsMatch (t , expected .CapAdd , actual .CapAdd , "Expected CapAdd to match" )
@@ -634,4 +704,13 @@ func verifyContainerConfig(t *testing.T, expected, actual adapter.ContainerConfi
634
704
assert .ElementsMatch (t , expected .Ulimits , actual .Ulimits , "Expected Ulimits to match" )
635
705
assert .Equal (t , expected .User , actual .User , "Expected User to match" )
636
706
assert .Equal (t , expected .WorkingDirectory , actual .WorkingDirectory , "Expected WorkingDirectory to match" )
707
+ if expected .HealthCheck != nil && actual .HealthCheck != nil {
708
+ assert .ElementsMatch (t , aws .StringValueSlice (expected .HealthCheck .Command ), aws .StringValueSlice (actual .HealthCheck .Command ), "Expected healthcheck command to match" )
709
+ assert .Equal (t , expected .HealthCheck .Interval , actual .HealthCheck .Interval , "Expected healthcheck interval to match" )
710
+ assert .Equal (t , expected .HealthCheck .Retries , actual .HealthCheck .Retries , "Expected healthcheck retries to match" )
711
+ assert .Equal (t , expected .HealthCheck .StartPeriod , actual .HealthCheck .StartPeriod , "Expected healthcheck start_period to match" )
712
+ assert .Equal (t , expected .HealthCheck .Timeout , actual .HealthCheck .Timeout , "Expected healthcheck timeout to match" )
713
+ } else {
714
+ assert .Nil (t , actual .HealthCheck , "Expected healthcheck to be nil in output ContainerConfig" )
715
+ }
637
716
}
0 commit comments