|
|
@@ -3,6 +3,8 @@ package costmodel
|
|
|
import (
|
|
|
"reflect"
|
|
|
"testing"
|
|
|
+
|
|
|
+ "github.com/davecgh/go-spew/spew"
|
|
|
)
|
|
|
|
|
|
func TestMergeTypeMaps(t *testing.T) {
|
|
|
@@ -122,3 +124,79 @@ func TestMergeTypeMaps(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestBuildNodeMap(t *testing.T) {
|
|
|
+ cases := []struct {
|
|
|
+ name string
|
|
|
+ cpuCostMap map[NodeIdentifier]float64
|
|
|
+ ramCostMap map[NodeIdentifier]float64
|
|
|
+ gpuCostMap map[NodeIdentifier]float64
|
|
|
+ cpuCoresMap map[nodeIdentifierNoProviderID]float64
|
|
|
+ ramBytesMap map[nodeIdentifierNoProviderID]float64
|
|
|
+ ramUserPctMap map[nodeIdentifierNoProviderID]float64
|
|
|
+ ramSystemPctMap map[nodeIdentifierNoProviderID]float64
|
|
|
+ cpuBreakdownMap map[nodeIdentifierNoProviderID]*ClusterCostsBreakdown
|
|
|
+ activeDataMap map[NodeIdentifier]activeData
|
|
|
+ preemptibleMap map[NodeIdentifier]bool
|
|
|
+ clusterAndNameToType map[nodeIdentifierNoProviderID]string
|
|
|
+ expected map[NodeIdentifier]*Node
|
|
|
+ }{
|
|
|
+ {
|
|
|
+ name: "empty",
|
|
|
+ expected: map[NodeIdentifier]*Node{},
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "just cpu cost",
|
|
|
+ cpuCostMap: map[NodeIdentifier]float64{
|
|
|
+ NodeIdentifier{
|
|
|
+ Cluster: "cluster1",
|
|
|
+ Name: "node1",
|
|
|
+ ProviderID: "prov_node1",
|
|
|
+ }: 0.048,
|
|
|
+ },
|
|
|
+ clusterAndNameToType: map[nodeIdentifierNoProviderID]string{
|
|
|
+ nodeIdentifierNoProviderID{
|
|
|
+ Cluster: "cluster1",
|
|
|
+ Name: "node1",
|
|
|
+ }: "type1",
|
|
|
+ },
|
|
|
+ expected: map[NodeIdentifier]*Node{
|
|
|
+ NodeIdentifier{
|
|
|
+ Cluster: "cluster1",
|
|
|
+ Name: "node1",
|
|
|
+ ProviderID: "prov_node1",
|
|
|
+ }: &Node{
|
|
|
+ Cluster: "cluster1",
|
|
|
+ Name: "node1",
|
|
|
+ ProviderID: "prov_node1",
|
|
|
+ NodeType: "type1",
|
|
|
+ CPUCost: 0.048,
|
|
|
+ CPUBreakdown: &ClusterCostsBreakdown{},
|
|
|
+ RAMBreakdown: &ClusterCostsBreakdown{},
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, testCase := range cases {
|
|
|
+
|
|
|
+ result := buildNodeMap(
|
|
|
+ testCase.cpuCostMap, testCase.ramCostMap, testCase.gpuCostMap,
|
|
|
+ testCase.cpuCoresMap, testCase.ramBytesMap, testCase.ramUserPctMap,
|
|
|
+ testCase.ramSystemPctMap,
|
|
|
+ testCase.cpuBreakdownMap,
|
|
|
+ testCase.activeDataMap,
|
|
|
+ testCase.preemptibleMap,
|
|
|
+ testCase.clusterAndNameToType,
|
|
|
+ )
|
|
|
+
|
|
|
+ if !reflect.DeepEqual(result, testCase.expected) {
|
|
|
+ t.Errorf("buildNodeMap case %s failed. Got %+v but expected %+v", testCase.name, result, testCase.expected)
|
|
|
+
|
|
|
+ // Use spew because we have to follow pointers to figure out
|
|
|
+ // what isn't matching up
|
|
|
+ t.Logf("Got: %s", spew.Sdump(result))
|
|
|
+ t.Logf("Expected: %s", spew.Sdump(testCase.expected))
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|