Skip to content

Commit

Permalink
don't allow tasks without commands
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed May 4, 2023
1 parent ede231d commit 6f50143
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/config/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,12 @@ func (p *PlayBook) checkConfig() error {

// check what all commands have a single type set
for _, t := range p.Tasks {
if len(t.Commands) == 0 {
return fmt.Errorf("task %q has no commands", t.Name)
}
for _, c := range t.Commands {
if err := c.validate(); err != nil {
return fmt.Errorf("task %s rejected, invalid command %q: %w", t.Name, c.Name, err)
return fmt.Errorf("task %q rejected, invalid command %q: %w", t.Name, c.Name, err)
}
}
}
Expand Down
16 changes: 14 additions & 2 deletions app/config/playbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,24 @@ func TestPlayBook_checkConfig(t *testing.T) {
{
Name: "task1",
Commands: []Cmd{
{Script: "example_script", Delete: DeleteInternal{Location: "location"}},
{Name: "c1", Script: "example_script", Delete: DeleteInternal{Location: "location"}},
},
},
},
},
expectedErr: `task task1 rejected, invalid command "": only one of [script, delete] is allowed`,
expectedErr: `task "task1" rejected, invalid command "c1": only one of [script, delete] is allowed`,
},
{
name: "no commands",
playbook: PlayBook{
Tasks: []Task{
{
Name: "task1",
Commands: []Cmd{},
},
},
},
expectedErr: `task "task1" has no commands`,
},
}

Expand Down

0 comments on commit 6f50143

Please sign in to comment.