2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-03-20 02:08:27 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-17 13:34:57 +00:00
|
|
|
"github.com/hashicorp/nomad/api/internal/testutil"
|
2023-01-01 18:57:26 +00:00
|
|
|
"github.com/shoenig/test/must"
|
2021-03-20 02:08:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestResources_Canonicalize(t *testing.T) {
|
2022-03-17 13:34:57 +00:00
|
|
|
testutil.Parallel(t)
|
2021-03-20 02:08:27 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
input *Resources
|
|
|
|
expected *Resources
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "empty",
|
|
|
|
input: &Resources{},
|
|
|
|
expected: DefaultResources(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cores",
|
|
|
|
input: &Resources{
|
2022-08-17 16:26:34 +00:00
|
|
|
Cores: pointerOf(2),
|
|
|
|
MemoryMB: pointerOf(1024),
|
2021-03-20 02:08:27 +00:00
|
|
|
},
|
|
|
|
expected: &Resources{
|
2022-08-17 16:26:34 +00:00
|
|
|
CPU: pointerOf(0),
|
|
|
|
Cores: pointerOf(2),
|
|
|
|
MemoryMB: pointerOf(1024),
|
2021-03-20 02:08:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "cpu",
|
|
|
|
input: &Resources{
|
2022-08-17 16:26:34 +00:00
|
|
|
CPU: pointerOf(500),
|
|
|
|
MemoryMB: pointerOf(1024),
|
2021-03-20 02:08:27 +00:00
|
|
|
},
|
|
|
|
expected: &Resources{
|
2022-08-17 16:26:34 +00:00
|
|
|
CPU: pointerOf(500),
|
|
|
|
Cores: pointerOf(0),
|
|
|
|
MemoryMB: pointerOf(1024),
|
2021-03-20 02:08:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
tc.input.Canonicalize()
|
2023-01-01 18:57:26 +00:00
|
|
|
must.Eq(t, tc.expected, tc.input)
|
2021-03-20 02:08:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|