open-nomad/api/resources_test.go
Seth Hoenig 3943dd1e16 ci: use serial testing for api in CI
This is a followup to running tests in serial in CI.
Since the API package cannot import anything outside of api/,
copy the ci.Parallel function into api/internal/testutil, and
have api tests use that.
2022-03-17 08:35:01 -05:00

58 lines
1.1 KiB
Go

package api
import (
"reflect"
"testing"
"github.com/hashicorp/nomad/api/internal/testutil"
"github.com/kr/pretty"
)
func TestResources_Canonicalize(t *testing.T) {
testutil.Parallel(t)
testCases := []struct {
name string
input *Resources
expected *Resources
}{
{
name: "empty",
input: &Resources{},
expected: DefaultResources(),
},
{
name: "cores",
input: &Resources{
Cores: intToPtr(2),
MemoryMB: intToPtr(1024),
},
expected: &Resources{
CPU: intToPtr(0),
Cores: intToPtr(2),
MemoryMB: intToPtr(1024),
},
},
{
name: "cpu",
input: &Resources{
CPU: intToPtr(500),
MemoryMB: intToPtr(1024),
},
expected: &Resources{
CPU: intToPtr(500),
Cores: intToPtr(0),
MemoryMB: intToPtr(1024),
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.input.Canonicalize()
if !reflect.DeepEqual(tc.input, tc.expected) {
t.Fatalf("Name: %v, Diffs:\n%v", tc.name, pretty.Diff(tc.expected, tc.input))
}
})
}
}