Skip to content

Commit

Permalink
use T.Equal method instead of reflect.DeepEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Feb 2, 2023
1 parent f481021 commit 710daa9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions nomad/structs/workload_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
32 changes: 32 additions & 0 deletions nomad/structs/workload_id_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 710daa9

Please sign in to comment.