Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diff alignment and remove no change DC #2465

Merged
merged 2 commits into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions command/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,17 @@ func formatTaskDiff(task *api.TaskDiff, startPrefix, taskPrefix int, verbose boo
// of spaces to put between the marker and object name output.
func formatObjectDiff(diff *api.ObjectDiff, startPrefix, keyPrefix int) string {
start := strings.Repeat(" ", startPrefix)
marker, _ := getDiffString(diff.Type)
marker, markerLen := getDiffString(diff.Type)
out := fmt.Sprintf("%s%s%s%s {\n", start, marker, strings.Repeat(" ", keyPrefix), diff.Name)

// Determine the length of the longest name and longest diff marker to
// properly align names and values
longestField, longestMarker := getLongestPrefixes(diff.Fields, diff.Objects)
subStartPrefix := startPrefix + 2
subStartPrefix := startPrefix + keyPrefix + 2
out += alignedFieldAndObjects(diff.Fields, diff.Objects, subStartPrefix, longestField, longestMarker)
return fmt.Sprintf("%s\n%s}", out, start)

endprefix := strings.Repeat(" ", startPrefix+markerLen+keyPrefix)
return fmt.Sprintf("%s\n%s}", out, endprefix)
}

// formatFieldDiff produces an annotated diff of a field. startPrefix is the
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (j *Job) Diff(other *Job, contextual bool) (*JobDiff, error) {
diff.Fields = fieldDiffs(oldPrimitiveFlat, newPrimitiveFlat, false)

// Datacenters diff
if setDiff := stringSetDiff(j.Datacenters, other.Datacenters, "Datacenters", contextual); setDiff != nil {
if setDiff := stringSetDiff(j.Datacenters, other.Datacenters, "Datacenters", contextual); setDiff != nil && setDiff.Type != DiffTypeNone {
diff.Objects = append(diff.Objects, setDiff)
}

Expand Down
23 changes: 21 additions & 2 deletions nomad/structs/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func TestJobDiff(t *testing.T) {
},
},
{
// Datacenter contextual
// Datacenter contextual no change
Contextual: true,
Old: &Job{
Datacenters: []string{"foo", "bar"},
Expand All @@ -407,11 +407,30 @@ func TestJobDiff(t *testing.T) {
},
Expected: &JobDiff{
Type: DiffTypeNone,
},
},
{
// Datacenter contextual
Contextual: true,
Old: &Job{
Datacenters: []string{"foo", "bar"},
},
New: &Job{
Datacenters: []string{"foo", "bar", "baz"},
},
Expected: &JobDiff{
Type: DiffTypeEdited,
Objects: []*ObjectDiff{
{
Type: DiffTypeNone,
Type: DiffTypeAdded,
Name: "Datacenters",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
Name: "Datacenters",
Old: "",
New: "baz",
},
{
Type: DiffTypeNone,
Name: "Datacenters",
Expand Down