do not initialize copy's slice if nil in original

This commit is contained in:
Michael Schurter
2021-12-23 16:40:35 -08:00
parent 0fdf624eda
commit e1c8d58cea
2 changed files with 5 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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
}