From 710daa97b185e32d10f639c484f5bde80f99ddcb Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 2 Feb 2023 09:17:33 -0800 Subject: [PATCH] use T.Equal method instead of reflect.DeepEqual --- nomad/structs/workload_id.go | 16 ++++++++++++++++ nomad/structs/workload_id_test.go | 32 +++++++++++++++++++++++++++++++ scheduler/util.go | 2 +- 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 nomad/structs/workload_id_test.go diff --git a/nomad/structs/workload_id.go b/nomad/structs/workload_id.go index 17a41c3230b..a5bb332f875 100644 --- a/nomad/structs/workload_id.go +++ b/nomad/structs/workload_id.go @@ -21,3 +21,19 @@ func (wi *WorkloadIdentity) Copy() *WorkloadIdentity { File: wi.File, } } + +func (wi *WorkloadIdentity) Equal(other *WorkloadIdentity) bool { + if wi == nil || other == nil { + return wi == other + } + + if wi.Env != other.Env { + return false + } + + if wi.File != other.File { + return false + } + + return true +} diff --git a/nomad/structs/workload_id_test.go b/nomad/structs/workload_id_test.go new file mode 100644 index 00000000000..937f02ccfa0 --- /dev/null +++ b/nomad/structs/workload_id_test.go @@ -0,0 +1,32 @@ +package structs + +import ( + "testing" + + "github.com/hashicorp/nomad/ci" + "github.com/shoenig/test/must" +) + +func TestWorkloadIdentity_Equal(t *testing.T) { + ci.Parallel(t) + + var orig *WorkloadIdentity + + newWI := orig.Copy() + must.Equal(t, orig, newWI) + + orig = &WorkloadIdentity{} + must.NotEqual(t, orig, newWI) + + newWI = &WorkloadIdentity{} + must.Equal(t, orig, newWI) + + orig.Env = true + must.NotEqual(t, orig, newWI) + + newWI.Env = true + must.Equal(t, orig, newWI) + + newWI.File = true + must.NotEqual(t, orig, newWI) +} diff --git a/scheduler/util.go b/scheduler/util.go index a9328507386..c02e05840b3 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -600,7 +600,7 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) bool { } // Inspect Identity being exposed - if !reflect.DeepEqual(at.Identity, bt.Identity) { + if !at.Identity.Equal(bt.Identity) { return true } }