@@ -18,27 +18,20 @@ type parseCPUMemoryMetadataTestData struct {
18
18
}
19
19
20
20
var validCPUMemoryMetadata = map [string ]string {
21
- "type" : "Utilization" ,
22
21
"value" : "50" ,
23
22
}
24
23
var validContainerCPUMemoryMetadata = map [string ]string {
25
- "type" : "Utilization" ,
26
24
"value" : "50" ,
27
25
"containerName" : "foo" ,
28
26
}
29
27
30
28
var testCPUMemoryMetadata = []parseCPUMemoryMetadataTestData {
31
29
{"" , map [string ]string {}, true },
32
- {"" , validCPUMemoryMetadata , false },
33
- {"" , validContainerCPUMemoryMetadata , false },
34
- {"" , map [string ]string {"type" : "Utilization" , "value" : "50" }, false },
35
30
{v2 .UtilizationMetricType , map [string ]string {"value" : "50" }, false },
36
- {"" , map [string ]string {"type" : "AverageValue" , "value" : "50" }, false },
37
31
{v2 .AverageValueMetricType , map [string ]string {"value" : "50" }, false },
38
- {"" , map [string ]string {"type" : "Value" , "value" : "50" }, true },
39
32
{v2 .ValueMetricType , map [string ]string {"value" : "50" }, true },
40
- {"" , map [string ]string {"type " : "AverageValue " }, true },
41
- {"" , map [string ]string {"type" : "xxx" , "value" : "50" }, true },
33
+ {"" , map [string ]string {"value " : "" }, true },
34
+ {"" , map [string ]string {}, true },
42
35
}
43
36
44
37
func TestCPUMemoryParseMetadata (t * testing.T ) {
@@ -58,34 +51,23 @@ func TestCPUMemoryParseMetadata(t *testing.T) {
58
51
}
59
52
60
53
func TestGetMetricSpecForScaling (t * testing.T ) {
61
- // Using trigger.metadata.type field for type
62
54
config := & scalersconfig.ScalerConfig {
63
55
TriggerMetadata : validCPUMemoryMetadata ,
56
+ MetricType : v2 .UtilizationMetricType ,
64
57
}
65
58
scaler , _ := NewCPUMemoryScaler (v1 .ResourceCPU , config )
66
59
metricSpec := scaler .GetMetricSpecForScaling (context .Background ())
67
60
68
61
assert .Equal (t , metricSpec [0 ].Type , v2 .ResourceMetricSourceType )
69
62
assert .Equal (t , metricSpec [0 ].Resource .Name , v1 .ResourceCPU )
70
63
assert .Equal (t , metricSpec [0 ].Resource .Target .Type , v2 .UtilizationMetricType )
71
-
72
- // Using trigger.metricType field for type
73
- config = & scalersconfig.ScalerConfig {
74
- TriggerMetadata : map [string ]string {"value" : "50" },
75
- MetricType : v2 .UtilizationMetricType ,
76
- }
77
- scaler , _ = NewCPUMemoryScaler (v1 .ResourceCPU , config )
78
- metricSpec = scaler .GetMetricSpecForScaling (context .Background ())
79
-
80
- assert .Equal (t , metricSpec [0 ].Type , v2 .ResourceMetricSourceType )
81
- assert .Equal (t , metricSpec [0 ].Resource .Name , v1 .ResourceCPU )
82
- assert .Equal (t , metricSpec [0 ].Resource .Target .Type , v2 .UtilizationMetricType )
83
64
}
84
65
66
+
85
67
func TestGetContainerMetricSpecForScaling (t * testing.T ) {
86
- // Using trigger.metadata.type field for type
87
68
config := & scalersconfig.ScalerConfig {
88
69
TriggerMetadata : validContainerCPUMemoryMetadata ,
70
+ MetricType : v2 .UtilizationMetricType ,
89
71
}
90
72
scaler , _ := NewCPUMemoryScaler (v1 .ResourceCPU , config )
91
73
metricSpec := scaler .GetMetricSpecForScaling (context .Background ())
@@ -94,17 +76,4 @@ func TestGetContainerMetricSpecForScaling(t *testing.T) {
94
76
assert .Equal (t , metricSpec [0 ].ContainerResource .Name , v1 .ResourceCPU )
95
77
assert .Equal (t , metricSpec [0 ].ContainerResource .Target .Type , v2 .UtilizationMetricType )
96
78
assert .Equal (t , metricSpec [0 ].ContainerResource .Container , validContainerCPUMemoryMetadata ["containerName" ])
97
-
98
- // Using trigger.metricType field for type
99
- config = & scalersconfig.ScalerConfig {
100
- TriggerMetadata : map [string ]string {"value" : "50" , "containerName" : "bar" },
101
- MetricType : v2 .UtilizationMetricType ,
102
- }
103
- scaler , _ = NewCPUMemoryScaler (v1 .ResourceCPU , config )
104
- metricSpec = scaler .GetMetricSpecForScaling (context .Background ())
105
-
106
- assert .Equal (t , metricSpec [0 ].Type , v2 .ContainerResourceMetricSourceType )
107
- assert .Equal (t , metricSpec [0 ].ContainerResource .Name , v1 .ResourceCPU )
108
- assert .Equal (t , metricSpec [0 ].ContainerResource .Target .Type , v2 .UtilizationMetricType )
109
- assert .Equal (t , metricSpec [0 ].ContainerResource .Container , "bar" )
110
79
}
0 commit comments