Skip to content

Commit

Permalink
First draft at better service diffs.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 committed Jul 29, 2021
1 parent 445b115 commit a4355c1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,10 @@ func serviceDiffs(old, new []*Service, contextual bool) []*ObjectDiff {
oldMap := make(map[string]*Service, len(old))
newMap := make(map[string]*Service, len(new))
for _, o := range old {
oldMap[o.Name] = o
oldMap[o.Name+o.PortLabel] = o
}
for _, n := range new {
newMap[n.Name] = n
newMap[n.Name+n.PortLabel] = n
}

var diffs []*ObjectDiff
Expand Down
68 changes: 68 additions & 0 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,74 @@ func TestTaskGroupDiff(t *testing.T) {
},
},
},

{
TestCase: "TaskGroup service added with same name",
Contextual: true,
Old: &TaskGroup{
Services: []*Service{
{
Name: "foo",
PortLabel: "label1",
},
},
},

New: &TaskGroup{
Services: []*Service{
{
Name: "foo",
PortLabel: "label1",
},
{
Name: "foo",
PortLabel: "label2",
},
},
},
Expected: &TaskGroupDiff{
Type: DiffTypeEdited,
Objects: []*ObjectDiff{
{
Type: DiffTypeAdded,
Name: "Service",
Fields: []*FieldDiff{
{
Type: DiffTypeNone,
Name: "AddressMode",
},
{
Type: DiffTypeAdded,
Name: "EnableTagOverride",
New: "false",
},
{
Type: DiffTypeAdded,
Name: "Name",
New: "foo",
},
{
Type: DiffTypeNone,
Name: "Namespace",
},
{
Type: DiffTypeNone,
Name: "OnUpdate",
},
{
Type: DiffTypeAdded,
Name: "PortLabel",
New: "label2",
},
{
Type: DiffTypeNone,
Name: "TaskName",
},
},
},
},
},
},
}

for i, c := range cases {
Expand Down

0 comments on commit a4355c1

Please sign in to comment.