Correctly canonicalize lifecycle block when missing hook value (#26285)

This commit is contained in:
Allison Larson
2025-07-16 11:40:16 -07:00
committed by GitHub
parent 0d620607fe
commit 918e1eb123
3 changed files with 32 additions and 3 deletions

View File

@@ -747,13 +747,13 @@ const (
)
type TaskLifecycle struct {
Hook string `mapstructure:"hook" hcl:"hook,optional"`
Hook string `mapstructure:"hook" hcl:"hook"`
Sidecar bool `mapstructure:"sidecar" hcl:"sidecar,optional"`
}
// Determine if lifecycle has user-input values
func (l *TaskLifecycle) Empty() bool {
return l == nil || (l.Hook == "")
return l == nil
}
// Task is a single process in a task group.

View File

@@ -344,10 +344,36 @@ func TestTask_Canonicalize_TaskLifecycle(t *testing.T) {
{
name: "empty",
task: &Task{
Lifecycle: &TaskLifecycle{},
Lifecycle: nil,
},
expected: nil,
},
{
name: "missing hook",
task: &Task{
Lifecycle: &TaskLifecycle{},
},
expected: &TaskLifecycle{},
},
{
name: "with sidecar",
task: &Task{
Lifecycle: &TaskLifecycle{
Sidecar: true,
},
},
expected: &TaskLifecycle{Sidecar: true},
},
{
name: "valid",
task: &Task{
Lifecycle: &TaskLifecycle{
Hook: "prestart",
Sidecar: true,
},
},
expected: &TaskLifecycle{Hook: "prestart", Sidecar: true},
},
}
for _, tc := range testCases {