@@ -15,6 +15,10 @@ const (
15
15
localizedMsgTmpl = "LocalizedMessage%d message"
16
16
helpLinkDescriptionTmpl = "Help%dLink%d Description"
17
17
helpLinkUrlTmpl = "https://help%d.com/link%d"
18
+ quotaExceededMsg = "Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1."
19
+ quotaExceededCode = "QUOTA_EXCEEDED"
20
+ quotaMetricName = "compute.googleapis.com/disks_total_storage"
21
+ quotaLimitName = "DISKS-TOTAL-GB-per-project-region"
18
22
)
19
23
20
24
var locales = []string {"en-US" , "es-US" , "es-ES" , "es-MX" , "de-DE" }
@@ -53,6 +57,27 @@ func buildOperationError(numLocalizedMsg int, numHelpWithLinks []int) compute.Op
53
57
54
58
}
55
59
60
+ func buildOperationErrorQuotaExceeded (withDetails bool , withDimensions bool ) compute.OperationError {
61
+ opError := & compute.OperationErrorErrors {Message : quotaExceededMsg , Code : quotaExceededCode }
62
+ opErrorErrors := []* compute.OperationErrorErrors {opError }
63
+ if withDetails {
64
+ quotaInfo := & compute.QuotaExceededInfo {
65
+ MetricName : quotaMetricName ,
66
+ LimitName : quotaLimitName ,
67
+ Limit : 1100 ,
68
+ }
69
+ if withDimensions {
70
+ quotaInfo .Dimensions = map [string ]string {"region" : "us-central1" }
71
+ }
72
+ opError .ErrorDetails = append (opError .ErrorDetails ,
73
+ & compute.OperationErrorErrorsErrorDetails {
74
+ QuotaInfo : quotaInfo ,
75
+ })
76
+ }
77
+
78
+ return compute.OperationError {Errors : opErrorErrors }
79
+ }
80
+
56
81
func omitAlways (numLocalizedMsg int , numHelpWithLinks []int ) []string {
57
82
var omits []string
58
83
@@ -180,6 +205,43 @@ func TestComputeOperationError_Error(t *testing.T) {
180
205
},
181
206
expectOmits : append (omitAlways (2 , []int {1 }), []string {}... ),
182
207
},
208
+ {
209
+ name : "QuotaMessageOnly" ,
210
+ input : buildOperationErrorQuotaExceeded (false , false ),
211
+ expectContains : []string {
212
+ "Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1." ,
213
+ },
214
+ expectOmits : append (omitAlways (0 , []int {}), []string {
215
+ "metric name = compute.googleapis.com/disks_total_storage" ,
216
+ }... ),
217
+ },
218
+ {
219
+ name : "QuotaMessageWithDetailsNoDimensions" ,
220
+ input : buildOperationErrorQuotaExceeded (true , false ),
221
+ expectContains : []string {
222
+ "Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1." ,
223
+ "metric name = compute.googleapis.com/disks_total_storage" ,
224
+ "limit name = DISKS-TOTAL-GB-per-project-region" ,
225
+ },
226
+ expectOmits : append (omitAlways (0 , []int {}), []string {
227
+ "dimensions = map[region:us-central1]" ,
228
+ }... ),
229
+ },
230
+ {
231
+ name : "QuotaMessageWithDetailsWithDimensions" ,
232
+ input : buildOperationErrorQuotaExceeded (true , true ),
233
+ expectContains : []string {
234
+ "Quota DISKS_TOTAL_GB exceeded. Limit: 1100.0 in region us-central1." ,
235
+ "metric name = compute.googleapis.com/disks_total_storage" ,
236
+ "limit name = DISKS-TOTAL-GB-per-project-region" ,
237
+ "dimensions = map[region:us-central1]" ,
238
+ },
239
+ expectOmits : append (omitAlways (0 , []int {}), []string {
240
+ "LocalizedMessage1" ,
241
+ "Help1Link1 Description" ,
242
+ "https://help1.com/link1" ,
243
+ }... ),
244
+ },
183
245
}
184
246
185
247
for _ , tc := range testCases {
0 commit comments