@@ -196,7 +196,7 @@ func TestAddLifecyclePreStopHook(t *testing.T) {
196196 answer bool
197197 }{
198198 {
199- scenario : "Test passing a complete lifecyle config" ,
199+ scenario : "Test passing a complete lifecyle config - Exec Command " ,
200200 lifecycleObj : v1alpha1.Container {
201201 Lifecycle : v1.Lifecycle {
202202 PreStop : & v1.LifecycleHandler {
@@ -230,6 +230,32 @@ func TestAddLifecyclePreStopHook(t *testing.T) {
230230 },
231231 answer : false ,
232232 },
233+ {
234+ scenario : "Test passing a complete lifecyle config - Sleep" ,
235+ lifecycleObj : v1alpha1.Container {
236+ Lifecycle : v1.Lifecycle {
237+ PreStop : & v1.LifecycleHandler {
238+ Sleep : & v1.SleepAction {
239+ Seconds : 10 ,
240+ },
241+ },
242+ },
243+ },
244+ answer : true ,
245+ },
246+ {
247+ scenario : "Test passing an incorrect lifecyle config - Sleep" ,
248+ lifecycleObj : v1alpha1.Container {
249+ Lifecycle : v1.Lifecycle {
250+ PreStop : & v1.LifecycleHandler {
251+ Sleep : & v1.SleepAction {
252+ Seconds : - 10 ,
253+ },
254+ },
255+ },
256+ },
257+ answer : false ,
258+ },
233259 }
234260
235261 // Run tests
@@ -241,7 +267,16 @@ func TestAddLifecyclePreStopHook(t *testing.T) {
241267 ans := addLifecycleHook (vaultContainer , tt .lifecycleObj )
242268
243269 //log.Printf("%+v", ans)
244- isValid := ans .Lifecycle != nil && ans .Lifecycle .PreStop != nil && ans .Lifecycle .PreStop .Exec != nil && len (ans .Lifecycle .PreStop .Exec .Command ) > 0
270+
271+ // Is our function returning a container object with valid Lifecycle config?
272+ isValid := bool (false )
273+ if ans .Lifecycle != nil && ans .Lifecycle .PreStop != nil {
274+ if ans .Lifecycle .PreStop .Exec != nil && len (ans .Lifecycle .PreStop .Exec .Command ) > 0 { // Check preStop Exec format
275+ isValid = true
276+ } else if ans .Lifecycle .PreStop .Sleep != nil && ans .Lifecycle .PreStop .Sleep .Seconds > 0 { // Check preStop Sleep format
277+ isValid = true
278+ }
279+ }
245280
246281 if isValid != tt .answer {
247282 t .Errorf ("got %v, want %v" , isValid , tt .answer )
0 commit comments