diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 90b33b198..0131c491a 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -617,6 +617,62 @@ func TestJob_RequiredSignals(t *testing.T) { } } +// test new Equal comparisons for components of Jobs +func TestJob_PartEqual(t *testing.T) { + ns := &Networks{} + if !ns.Equals(&Networks{}) { + t.Fatal("network set wise not equal") + } + + ns = &Networks{ + &NetworkResource{Device: "eth0"}, + } + if !ns.Equals(&Networks{ + &NetworkResource{Device: "eth0"}, + }) { + t.Fatal("network set wise not equal") + } + + ns = &Networks{ + &NetworkResource{Device: "eth0"}, + &NetworkResource{Device: "eth1"}, + &NetworkResource{Device: "eth2"}, + } + if !ns.Equals(&Networks{ + &NetworkResource{Device: "eth2"}, + &NetworkResource{Device: "eth0"}, + &NetworkResource{Device: "eth1"}, + }) { + t.Fatal("network set wise not equal") + } + + cs := &Constraints{ + &Constraint{"left0", "right0", "=", ""}, + &Constraint{"left1", "right1", "=", ""}, + &Constraint{"left2", "right2", "=", ""}, + } + if !cs.Equals(&Constraints{ + &Constraint{"left0", "right0", "=", ""}, + &Constraint{"left2", "right2", "=", ""}, + &Constraint{"left1", "right1", "=", ""}, + }) { + t.Fatal("constraint set wise not equal") + } + + as := &Affinities{ + &Affinity{"left0", "right0", "=", 0, ""}, + &Affinity{"left1", "right1", "=", 0, ""}, + &Affinity{"left2", "right2", "=", 0, ""}, + } + if !as.Equals(&Affinities{ + &Affinity{"left0", "right0", "=", 0, ""}, + &Affinity{"left2", "right2", "=", 0, ""}, + &Affinity{"left1", "right1", "=", 0, ""}, + }) { + t.Fatal("affinity set wise not equal") + } +} + func TestTaskGroup_Validate(t *testing.T) { j := testJob() tg := &TaskGroup{