Skip to content

Commit

Permalink
test: compare gpu resources
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelvr committed Dec 2, 2024
1 parent 0faa536 commit 4aabc96
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions pkg/analyze/node_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func Test_compareNodeResourceConditionalToActual(t *testing.T) {
nodeData := []corev1.Node{
corev1.Node{
{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Node",
Expand All @@ -28,16 +28,18 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) {
"ephemeral-storage": resource.MustParse("20959212Ki"),
"memory": resource.MustParse("3999Ki"),
"pods": resource.MustParse("15"),
gpuResourceName: resource.MustParse("4"),
},
Allocatable: corev1.ResourceList{
"cpu": resource.MustParse("1.5"),
"ephemeral-storage": resource.MustParse("19316009748"),
"memory": resource.MustParse("16Ki"),
"pods": resource.MustParse("14"),
gpuResourceName: resource.MustParse("4"),
},
},
},
corev1.Node{
{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Node",
Expand Down Expand Up @@ -366,6 +368,70 @@ func Test_compareNodeResourceConditionalToActual(t *testing.T) {
expected: false,
isError: true,
},
{
name: "sum(gpuCapacity) > 1 (true)",
conditional: "sum(gpuCapacity) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuCapacity) >= 8 (false)",
conditional: "sum(gpuCapacity) >= 8",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "min(gpuCapacity) > 1 (false)",
conditional: "min(gpuCapacity) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "min(gpuAllocatable) > 1 (false)",
conditional: "min(gpuAllocatable) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
{
name: "max(gpuCapacity) == 4 (true)",
conditional: "max(gpuCapacity) == 4",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "max(gpuAllocatable) == 4 (true)",
conditional: "max(gpuAllocatable) == 4",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuAllocatable) > 1 (true)",
conditional: "sum(gpuAllocatable) > 1",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: true,
isError: false,
},
{
name: "sum(gpuAllocatable) >= 8 (false)",
conditional: "sum(gpuAllocatable) >= 8",
matchingNodes: nodeData,
totalNodeCount: len(nodeData),
expected: false,
isError: false,
},
}

for _, test := range tests {
Expand Down

0 comments on commit 4aabc96

Please sign in to comment.