Skip to content

Commit

Permalink
Fix diff alignment and remove no change DC
Browse files Browse the repository at this point in the history
Old Output:
```
+/- Job: "example"
    Datacenters {
  Datacenters: "dc1"
}
+/- Task Group: "cache" (1 create/destroy update)
  +/- RestartPolicy {
    +/- Attempts: "10" => "9"
        Delay:    "25000000000"
        Interval: "300000000000"
        Mode:     "delay"
  }
  +/- EphemeralDisk {
        Migrate: "false"
    +/- SizeMB:  "300" => "301"
        Sticky:  "false"
  }
  +/- Task: "redis" (forces create/destroy update)
    +   Meta[key]: "value"
    +/- Config {
          image:           "redis:3.2"
      +/- port_map[0][db]: "6379" => "6380"
    }
    +/- Resources {
          CPU:      "500"
          DiskMB:   "0"
          IOPS:     "0"
      +/- MemoryMB: "256" => "257"
    }
    +/- Service {
          Name:      "global-redis-check"
          PortLabel: "db"
      +/- Check {
            Command:       ""
            InitialStatus: ""
            Interval:      "10000000000"
            Name:          "alive"
            Path:          ""
            PortLabel:     ""
            Protocol:      ""
        +/- Timeout:       "2000000000" => "3000000000"
            Type:          "tcp"
      }
    }
```

New Output:
```
+/- Job: "example"
+/- Task Group: "cache" (1 create/destroy update)
  +/- RestartPolicy {
    +/- Attempts: "10" => "9"
        Delay:    "25000000000"
        Interval: "300000000000"
        Mode:     "delay"
      }
  +/- EphemeralDisk {
        Migrate: "false"
    +/- SizeMB:  "300" => "301"
        Sticky:  "false"
      }
  +/- Task: "redis" (forces create/destroy update)
    +   Meta[key]: "value"
    +/- Config {
          image:           "redis:3.2"
      +/- port_map[0][db]: "6379" => "6380"
        }
    +/- Resources {
          CPU:      "500"
          DiskMB:   "0"
          IOPS:     "0"
      +/- MemoryMB: "256" => "257"
        }
    +/- Service {
          Name:      "global-redis-check"
          PortLabel: "db"
      +/- Check {
            Command:       ""
            InitialStatus: ""
            Interval:      "10000000000"
            Name:          "alive"
            Path:          ""
            PortLabel:     ""
            Protocol:      ""
        +/- Timeout:       "2000000000" => "3000000000"
            Type:          "tcp"
          }
        }
```
  • Loading branch information
dadgar committed Mar 21, 2017
1 parent 456da65 commit c4435ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
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", false); setDiff != nil {
if setDiff := stringSetDiff(j.Datacenters, other.Datacenters, "Datacenters", contextual); setDiff != nil && setDiff.Type != DiffTypeNone {
diff.Objects = append(diff.Objects, setDiff)
}

Expand Down
41 changes: 40 additions & 1 deletion 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 @@ -409,6 +409,45 @@ func TestJobDiff(t *testing.T) {
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: DiffTypeAdded,
Name: "Datacenters",
Fields: []*FieldDiff{
{
Type: DiffTypeAdded,
Name: "Datacenters",
Old: "",
New: "baz",
},
{
Type: DiffTypeNone,
Name: "Datacenters",
Old: "bar",
New: "bar",
},
{
Type: DiffTypeNone,
Name: "Datacenters",
Old: "foo",
New: "foo",
},
},
},
},
},
},
{
// Update strategy edited
Old: &Job{
Expand Down

0 comments on commit c4435ee

Please sign in to comment.