Merge pull request #88 from sgotti/fix_check_task_and_parent_common_deps
config: fix check on task and parents with common deps
This commit is contained in:
commit
8a05513db6
|
@ -769,12 +769,11 @@ func checkConfig(config *Config) error {
|
|||
for _, task := range run.Tasks {
|
||||
parents := getTaskParents(run, task)
|
||||
for _, parent := range parents {
|
||||
allParents := getAllTaskParents(run, task)
|
||||
allParentParents := getAllTaskParents(run, parent)
|
||||
for _, p := range allParents {
|
||||
for _, p := range parents {
|
||||
for _, pp := range allParentParents {
|
||||
if p.Name == pp.Name {
|
||||
return errors.Errorf("task %s and its dependency %s have both a dependency on task %s", task.Name, parent.Name, p.Name)
|
||||
return errors.Errorf("task %q and its dependency %q have both a dependency on task %q", task.Name, parent.Name, p.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,6 +133,71 @@ func TestParseConfig(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test task parent same dep a -> b -> c, a -> c",
|
||||
in: `
|
||||
runs:
|
||||
- name: run01
|
||||
tasks:
|
||||
- name: task01
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
- name: task02
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
depends:
|
||||
- task01
|
||||
- name: task03
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
depends:
|
||||
- task02
|
||||
- task01
|
||||
`,
|
||||
err: errors.Errorf("task %q and its dependency %q have both a dependency on task %q", "task03", "task02", "task01"),
|
||||
},
|
||||
{
|
||||
name: "test task parent same dep a -> b -> c -> d, a -> d",
|
||||
in: `
|
||||
runs:
|
||||
- name: run01
|
||||
tasks:
|
||||
- name: task01
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
- name: task02
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
depends:
|
||||
- task01
|
||||
- name: task03
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
depends:
|
||||
- task02
|
||||
- name: task04
|
||||
runtime:
|
||||
type: pod
|
||||
containers:
|
||||
- image: busybox
|
||||
depends:
|
||||
- task03
|
||||
- task01
|
||||
`,
|
||||
err: errors.Errorf("task %q and its dependency %q have both a dependency on task %q", "task04", "task03", "task01"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
@ -316,12 +316,11 @@ func CheckRunConfigTasks(rcts map[string]*rstypes.RunConfigTask) error {
|
|||
for _, t := range rcts {
|
||||
parents := GetParents(rcts, t)
|
||||
for _, parent := range parents {
|
||||
allParents := GetAllParents(rcts, t)
|
||||
allParentParents := GetAllParents(rcts, parent)
|
||||
for _, p := range allParents {
|
||||
for _, p := range parents {
|
||||
for _, pp := range allParentParents {
|
||||
if p.ID == pp.ID {
|
||||
return errors.Errorf("task %s and its parent %s have both a dependency on task %s", t.Name, parent.Name, p.Name)
|
||||
return errors.Errorf("task %q and its parent %q have both a dependency on task %q", t.Name, parent.Name, p.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -590,6 +590,63 @@ func TestCheckRunConfig(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "test task parent same dep a -> b -> c, a -> c",
|
||||
in: []task{
|
||||
{
|
||||
ID: "1",
|
||||
Level: -1,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Level: -1,
|
||||
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
||||
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "3",
|
||||
Level: -1,
|
||||
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
||||
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
||||
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
err: errors.Errorf("task %q and its parent %q have both a dependency on task %q", "task3", "task2", "task1"),
|
||||
},
|
||||
{
|
||||
name: "test task parent same dep a -> b -> c -> d, a -> d",
|
||||
in: []task{
|
||||
{
|
||||
ID: "1",
|
||||
Level: -1,
|
||||
},
|
||||
{
|
||||
ID: "2",
|
||||
Level: -1,
|
||||
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
||||
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "3",
|
||||
Level: -1,
|
||||
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
||||
"2": &rstypes.RunConfigTaskDepend{TaskID: "2"},
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "4",
|
||||
Level: -1,
|
||||
Depends: map[string]*rstypes.RunConfigTaskDepend{
|
||||
"3": &rstypes.RunConfigTaskDepend{TaskID: "3"},
|
||||
"1": &rstypes.RunConfigTaskDepend{TaskID: "1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
err: errors.Errorf("task %q and its parent %q have both a dependency on task %q", "task4", "task3", "task1"),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue