Add diff support for ServiceCheck.Header
This commit is contained in:
parent
0634eef12a
commit
9a466bcf5e
|
@ -592,6 +592,23 @@ func serviceCheckDiff(old, new *ServiceCheck, contextual bool) *ObjectDiff {
|
|||
|
||||
// Diff the primitive fields.
|
||||
diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, contextual)
|
||||
|
||||
// Diff Header
|
||||
headerDiff := &ObjectDiff{Type: DiffTypeNone, Name: "Header"}
|
||||
if reflect.DeepEqual(old.Header, new.Header) {
|
||||
return diff
|
||||
} else if len(old.Header) == 0 {
|
||||
headerDiff.Type = DiffTypeAdded
|
||||
} else if len(new.Header) == 0 {
|
||||
headerDiff.Type = DiffTypeDeleted
|
||||
} else {
|
||||
headerDiff.Type = DiffTypeEdited
|
||||
}
|
||||
diff.Objects = append(diff.Objects, headerDiff)
|
||||
|
||||
oldHeaderFlat := flatmap.Flatten(old.Header, nil, false)
|
||||
newHeaderFlat := flatmap.Flatten(new.Header, nil, false)
|
||||
headerDiff.Fields = fieldDiffs(oldHeaderFlat, newHeaderFlat, contextual)
|
||||
return diff
|
||||
}
|
||||
|
||||
|
@ -609,17 +626,17 @@ func serviceCheckDiffs(old, new []*ServiceCheck, contextual bool) []*ObjectDiff
|
|||
}
|
||||
|
||||
var diffs []*ObjectDiff
|
||||
for name, oldService := range oldMap {
|
||||
for name, oldCheck := range oldMap {
|
||||
// Diff the same, deleted and edited
|
||||
if diff := serviceCheckDiff(oldService, newMap[name], contextual); diff != nil {
|
||||
if diff := serviceCheckDiff(oldCheck, newMap[name], contextual); diff != nil {
|
||||
diffs = append(diffs, diff)
|
||||
}
|
||||
}
|
||||
|
||||
for name, newService := range newMap {
|
||||
for name, newCheck := range newMap {
|
||||
// Diff the added
|
||||
if old, ok := oldMap[name]; !ok {
|
||||
if diff := serviceCheckDiff(old, newService, contextual); diff != nil {
|
||||
if diff := serviceCheckDiff(old, newCheck, contextual); diff != nil {
|
||||
diffs = append(diffs, diff)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3410,6 +3410,9 @@ func TestTaskDiff(t *testing.T) {
|
|||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
InitialStatus: "critical",
|
||||
Header: map[string][]string{
|
||||
"Foo": {"bar"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -3430,6 +3433,11 @@ func TestTaskDiff(t *testing.T) {
|
|||
Interval: 1 * time.Second,
|
||||
Timeout: 1 * time.Second,
|
||||
InitialStatus: "passing",
|
||||
Method: "POST",
|
||||
Header: map[string][]string{
|
||||
"Foo": {"bar", "baz"},
|
||||
"Eggs": {"spam"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -3484,6 +3492,12 @@ func TestTaskDiff(t *testing.T) {
|
|||
Old: "1000000000",
|
||||
New: "1000000000",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Method",
|
||||
Old: "",
|
||||
New: "POST",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeNone,
|
||||
Name: "Name",
|
||||
|
@ -3527,6 +3541,32 @@ func TestTaskDiff(t *testing.T) {
|
|||
New: "tcp",
|
||||
},
|
||||
},
|
||||
Objects: []*ObjectDiff{
|
||||
{
|
||||
Type: DiffTypeEdited,
|
||||
Name: "Header",
|
||||
Fields: []*FieldDiff{
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Eggs[0]",
|
||||
Old: "",
|
||||
New: "spam",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeNone,
|
||||
Name: "Foo[0]",
|
||||
Old: "bar",
|
||||
New: "bar",
|
||||
},
|
||||
{
|
||||
Type: DiffTypeAdded,
|
||||
Name: "Foo[1]",
|
||||
Old: "",
|
||||
New: "baz",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue