mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 19:05:42 +03:00
Ensure templates have different destinations
This commit is contained in:
@@ -2129,11 +2129,19 @@ func (t *Task) Validate(ephemeralDisk *EphemeralDisk) error {
|
||||
}
|
||||
}
|
||||
|
||||
destinations := make(map[string]int, len(t.Templates))
|
||||
for idx, tmpl := range t.Templates {
|
||||
if err := tmpl.Validate(); err != nil {
|
||||
outer := fmt.Errorf("Template %d validation failed: %s", idx+1, err)
|
||||
mErr.Errors = append(mErr.Errors, outer)
|
||||
}
|
||||
|
||||
if other, ok := destinations[tmpl.DestPath]; ok {
|
||||
outer := fmt.Errorf("Template %d has same destination as %d", idx+1, other)
|
||||
mErr.Errors = append(mErr.Errors, outer)
|
||||
} else {
|
||||
destinations[tmpl.DestPath] = idx + 1
|
||||
}
|
||||
}
|
||||
|
||||
return mErr.ErrorOrNil()
|
||||
|
||||
@@ -526,6 +526,19 @@ func TestTask_Validate_Template(t *testing.T) {
|
||||
if !strings.Contains(err.Error(), "Template 1 validation failed") {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Have two templates that share the same destination
|
||||
good := &Template{
|
||||
SourcePath: "foo",
|
||||
DestPath: "local/foo",
|
||||
ChangeMode: "noop",
|
||||
}
|
||||
|
||||
task.Templates = []*Template{good, good}
|
||||
err = task.Validate(ephemeralDisk)
|
||||
if !strings.Contains(err.Error(), "same destination as") {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTemplate_Validate(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user