mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
Include affinities in job and task diff, and more test cases
This commit is contained in:
@@ -105,6 +105,17 @@ func (j *Job) Diff(other *Job, contextual bool) (*JobDiff, error) {
|
||||
diff.Objects = append(diff.Objects, conDiff...)
|
||||
}
|
||||
|
||||
// Affinities diff
|
||||
affinitiesDiff := primitiveObjectSetDiff(
|
||||
interfaceSlice(j.Affinities),
|
||||
interfaceSlice(other.Affinities),
|
||||
[]string{"str"},
|
||||
"Affinity",
|
||||
contextual)
|
||||
if affinitiesDiff != nil {
|
||||
diff.Objects = append(diff.Objects, affinitiesDiff...)
|
||||
}
|
||||
|
||||
// Task groups diff
|
||||
tgs, err := taskGroupDiffs(j.TaskGroups, other.TaskGroups, contextual)
|
||||
if err != nil {
|
||||
@@ -398,6 +409,17 @@ func (t *Task) Diff(other *Task, contextual bool) (*TaskDiff, error) {
|
||||
diff.Objects = append(diff.Objects, conDiff...)
|
||||
}
|
||||
|
||||
// Affinities diff
|
||||
affinitiesDiff := primitiveObjectSetDiff(
|
||||
interfaceSlice(t.Affinities),
|
||||
interfaceSlice(other.Affinities),
|
||||
[]string{"str"},
|
||||
"Affinity",
|
||||
contextual)
|
||||
if affinitiesDiff != nil {
|
||||
diff.Objects = append(diff.Objects, affinitiesDiff...)
|
||||
}
|
||||
|
||||
// Config diff
|
||||
if cDiff := configDiff(t.Config, other.Config, contextual); cDiff != nil {
|
||||
diff.Objects = append(diff.Objects, cDiff)
|
||||
|
||||
@@ -753,6 +753,110 @@ func TestJobDiff(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// Affinities edited
|
||||
Old: &Job{
|
||||
Affinities: []*Affinity{
|
||||
{
|
||||
LTarget: "foo",
|
||||
RTarget: "foo",
|
||||
Operand: "foo",
|
||||
Weight: 20,
|
||||
str: "foo",
|
||||
},
|
||||
{
|
||||
LTarget: "bar",
|
||||
RTarget: "bar",
|
||||
Operand: "bar",
|
||||
Weight: 20,
|
||||
str: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
New: &Job{
|
||||
Affinities: []*Affinity{
|
||||
{
|
||||
LTarget: "foo",
|
||||
RTarget: "foo",
|
||||
Operand: "foo",
|
||||
Weight: 20,
|
||||
str: "foo",
|
||||
},
|
||||
{
|
||||
LTarget: "baz",
|
||||
RTarget: "baz",
|
||||
Operand: "baz",
|
||||
Weight: 20,
|
||||
str: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
Expected: &JobDiff{
|
||||
Type: DiffTypeEdited,
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Affinity",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "LTarget",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Operand",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "RTarget",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Weight",
|
||||
Old: "",
|
||||
New: "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Affinity",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "LTarget",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Operand",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "RTarget",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Weight",
|
||||
Old: "20",
|
||||
New: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// Task groups edited
|
||||
Old: &Job{
|
||||
@@ -2714,6 +2818,110 @@ func TestTaskDiff(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Affinities edited",
|
||||
Old: &Task{
|
||||
Affinities: []*Affinity{
|
||||
{
|
||||
LTarget: "foo",
|
||||
RTarget: "foo",
|
||||
Operand: "foo",
|
||||
Weight: 20,
|
||||
str: "foo",
|
||||
},
|
||||
{
|
||||
LTarget: "bar",
|
||||
RTarget: "bar",
|
||||
Operand: "bar",
|
||||
Weight: 20,
|
||||
str: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
New: &Task{
|
||||
Affinities: []*Affinity{
|
||||
{
|
||||
LTarget: "foo",
|
||||
RTarget: "foo",
|
||||
Operand: "foo",
|
||||
Weight: 20,
|
||||
str: "foo",
|
||||
},
|
||||
{
|
||||
LTarget: "baz",
|
||||
RTarget: "baz",
|
||||
Operand: "baz",
|
||||
Weight: 20,
|
||||
str: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
Expected: &TaskDiff{
|
||||
Type: DiffTypeEdited,
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Affinity",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "LTarget",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Operand",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "RTarget",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Weight",
|
||||
Old: "",
|
||||
New: "20",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Affinity",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "LTarget",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Operand",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "RTarget",
|
||||
Old: "bar",
|
||||
New: "",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeDeleted,
|
||||
Name: "Weight",
|
||||
Old: "20",
|
||||
New: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "LogConfig added",
|
||||
Old: &Task{},
|
||||
|
||||
Reference in New Issue
Block a user