@@ -1015,168 +1015,3 @@ func TestInvalidFormatMessageOnChannel(t *testing.T) {
1015
1015
// verify no request was made from the two ill-formed message
1016
1016
conn .EXPECT ().WriteMessage (gomock .Any (), gomock .Any ()).Times (0 )
1017
1017
}
1018
- func TestCopyTaskMetrics (t * testing.T ) {
1019
- testCases := []struct {
1020
- name string
1021
- metrics []types.TaskMetric
1022
- expected int
1023
- }{
1024
- {
1025
- name : "empty metrics" ,
1026
- metrics : []types.TaskMetric {},
1027
- expected : 0 ,
1028
- },
1029
- {
1030
- name : "single task metric" ,
1031
- metrics : []types.TaskMetric {
1032
- {
1033
- TaskArn : aws .String ("task-arn-1" ),
1034
- },
1035
- },
1036
- expected : 1 ,
1037
- },
1038
- {
1039
- name : "multiple task metrics" ,
1040
- metrics : []types.TaskMetric {
1041
- {
1042
- TaskArn : aws .String ("task-arn-1" ),
1043
- },
1044
- {
1045
- TaskArn : aws .String ("task-arn-2" ),
1046
- },
1047
- {
1048
- TaskArn : aws .String ("task-arn-3" ),
1049
- },
1050
- },
1051
- expected : 3 ,
1052
- },
1053
- }
1054
-
1055
- for _ , tc := range testCases {
1056
- t .Run (tc .name , func (t * testing.T ) {
1057
- // Create a copy of the metrics
1058
- copiedMetrics := copyTaskMetrics (tc .metrics )
1059
-
1060
- // Verify the length is correct
1061
- assert .Equal (t , tc .expected , len (copiedMetrics ), "Expected copied metrics to have length %d, got %d" , tc .expected , len (copiedMetrics ))
1062
-
1063
- // For non-empty slices, verify contents are the same
1064
- if tc .expected > 0 {
1065
- for i , metric := range tc .metrics {
1066
- assert .Equal (t , * metric .TaskArn , * copiedMetrics [i ].TaskArn , "TaskArn mismatch at index %d" , i )
1067
- }
1068
-
1069
- // Verify that changing the copy doesn't affect the original
1070
- if tc .expected > 0 {
1071
- // Modify the copy
1072
- newArn := "modified-arn"
1073
- copiedMetrics [0 ].TaskArn = & newArn
1074
-
1075
- // Verify original is unchanged
1076
- assert .NotEqual (t , * copiedMetrics [0 ].TaskArn , * tc .metrics [0 ].TaskArn ,
1077
- "Expected changes to copied metrics not to affect original" )
1078
- }
1079
- }
1080
-
1081
- // Verify that the returned slice is a new slice
1082
- if tc .expected > 0 {
1083
- // Get the original pointers
1084
- originalPtr := fmt .Sprintf ("%p" , & tc .metrics )
1085
- copiedPtr := fmt .Sprintf ("%p" , & copiedMetrics )
1086
-
1087
- // They should be different
1088
- assert .NotEqual (t , originalPtr , copiedPtr , "Expected copied slice to have different memory address" )
1089
- }
1090
- })
1091
- }
1092
- }
1093
-
1094
- func TestCopyTaskMetricsWithComplexData (t * testing.T ) {
1095
- // Create task metrics with container metrics
1096
- originalMetrics := []types.TaskMetric {
1097
- {
1098
- TaskArn : aws .String ("task-1" ),
1099
- ContainerMetrics : []types.ContainerMetric {
1100
- {
1101
- ContainerName : aws .String ("container-1" ),
1102
- CpuStatsSet : & types.CWStatsSet {
1103
- Max : 1.0 ,
1104
- Min : 0.1 ,
1105
- SampleCount : 10 ,
1106
- Sum : 5.5 ,
1107
- },
1108
- },
1109
- },
1110
- },
1111
- }
1112
-
1113
- // Copy metrics
1114
- copiedMetrics := copyTaskMetrics (originalMetrics )
1115
-
1116
- // Test that the container metrics were copied correctly
1117
- assert .Equal (t , * originalMetrics [0 ].ContainerMetrics [0 ].ContainerName ,
1118
- * copiedMetrics [0 ].ContainerMetrics [0 ].ContainerName )
1119
- assert .Equal (t , originalMetrics [0 ].ContainerMetrics [0 ].CpuStatsSet .Max ,
1120
- copiedMetrics [0 ].ContainerMetrics [0 ].CpuStatsSet .Max )
1121
-
1122
- // Modify the copied metrics
1123
- newName := "modified-container"
1124
- copiedMetrics [0 ].ContainerMetrics [0 ].ContainerName = & newName
1125
- copiedMetrics [0 ].ContainerMetrics [0 ].CpuStatsSet .Max = 2.0
1126
-
1127
- // Verify the original wasn't changed (this checks if it's a deep copy)
1128
- assert .Equal (t , "container-1" , * originalMetrics [0 ].ContainerMetrics [0 ].ContainerName )
1129
- assert .Equal (t , 1.0 , originalMetrics [0 ].ContainerMetrics [0 ].CpuStatsSet .Max )
1130
- }
1131
-
1132
- func TestCopyTaskMetricsWithServiceConnectMetrics (t * testing.T ) {
1133
- // Create task metrics with Service Connect metrics
1134
- dimensionKey := "ClusterName"
1135
- dimensionValue := "TestCluster"
1136
- metricName := "HTTPCode_Target_2XX_Count"
1137
-
1138
- originalMetrics := []types.TaskMetric {
1139
- {
1140
- TaskArn : aws .String ("task-1" ),
1141
- ServiceConnectMetricsWrapper : []types.GeneralMetricsWrapper {
1142
- {
1143
- MetricType : types .MetricType ("2" ),
1144
- Dimensions : []types.Dimension {
1145
- {
1146
- Key : & dimensionKey ,
1147
- Value : & dimensionValue ,
1148
- },
1149
- },
1150
- GeneralMetrics : []types.GeneralMetric {
1151
- {
1152
- MetricName : & metricName ,
1153
- MetricValues : []float64 {3.0 },
1154
- MetricCounts : []int64 {1 },
1155
- },
1156
- },
1157
- },
1158
- },
1159
- },
1160
- }
1161
-
1162
- // Copy metrics
1163
- copiedMetrics := copyTaskMetrics (originalMetrics )
1164
-
1165
- // Test that service connect metrics were copied correctly
1166
- assert .Equal (t , originalMetrics [0 ].ServiceConnectMetricsWrapper [0 ].MetricType ,
1167
- copiedMetrics [0 ].ServiceConnectMetricsWrapper [0 ].MetricType )
1168
- assert .Equal (t , * originalMetrics [0 ].ServiceConnectMetricsWrapper [0 ].Dimensions [0 ].Key ,
1169
- * copiedMetrics [0 ].ServiceConnectMetricsWrapper [0 ].Dimensions [0 ].Key )
1170
- assert .Equal (t , * originalMetrics [0 ].ServiceConnectMetricsWrapper [0 ].GeneralMetrics [0 ].MetricName ,
1171
- * copiedMetrics [0 ].ServiceConnectMetricsWrapper [0 ].GeneralMetrics [0 ].MetricName )
1172
-
1173
- // Modify copied metrics
1174
- newDimensionValue := "ModifiedCluster"
1175
- copiedMetrics [0 ].ServiceConnectMetricsWrapper [0 ].Dimensions [0 ].Value = & newDimensionValue
1176
- newMetricValue := 5.0
1177
- copiedMetrics [0 ].ServiceConnectMetricsWrapper [0 ].GeneralMetrics [0 ].MetricValues [0 ] = newMetricValue
1178
-
1179
- // Original shouldn't change
1180
- assert .Equal (t , "TestCluster" , * originalMetrics [0 ].ServiceConnectMetricsWrapper [0 ].Dimensions [0 ].Value )
1181
- assert .Equal (t , 3.0 , originalMetrics [0 ].ServiceConnectMetricsWrapper [0 ].GeneralMetrics [0 ].MetricValues [0 ])
1182
- }
0 commit comments