From e1c8d58cea479fe2b74c148766e4f59aa1fc65a2 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 23 Dec 2021 16:40:35 -0800 Subject: [PATCH] do not initialize copy's slice if nil in original --- nomad/node_endpoint_test.go | 4 +--- nomad/structs/structs.go | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nomad/node_endpoint_test.go b/nomad/node_endpoint_test.go index 65ac8c03a..1070892b0 100644 --- a/nomad/node_endpoint_test.go +++ b/nomad/node_endpoint_test.go @@ -1531,9 +1531,7 @@ func TestClientEndpoint_GetNode(t *testing.T) { node.StatusUpdatedAt = resp2.Node.StatusUpdatedAt node.SecretID = "" node.Events = resp2.Node.Events - if !reflect.DeepEqual(node, resp2.Node) { - t.Fatalf("bad: %#v \n %#v", node, resp2.Node) - } + require.Equal(t, node, resp2.Node) // assert that the node register event was set correctly if len(resp2.Node.Events) != 1 { diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 77ea61b16..8aaf89514 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -3064,8 +3064,10 @@ type NodeCpuResources struct { func (n NodeCpuResources) Copy() NodeCpuResources { newN := n - newN.ReservableCpuCores = make([]uint16, len(n.ReservableCpuCores)) - copy(newN.ReservableCpuCores, n.ReservableCpuCores) + if n.ReservableCpuCores != nil { + newN.ReservableCpuCores = make([]uint16, len(n.ReservableCpuCores)) + copy(newN.ReservableCpuCores, n.ReservableCpuCores) + } return newN }