@@ -255,3 +255,40 @@ func Test_SignatureMethod(t *testing.T) {
255255 res = SignatureMethod (priKey , "source" , "ACS3-RSA-SHA256" )
256256 utils .AssertEqual (t , "a00b88ae04f651a8ab645e724949ff435bbb2cf9a37aa54323024477f8031f4e13dc948484c5c5a81ba53a55eb0571dffccc1e953c93269d6da23ed319e0f1ef699bcc9823a646574628ae1b70ed569b5a07d139dda28996b5b9231f5ba96141f0893deec2fbf54a0fa2c203b8ae74dd26f457ac29c873745a5b88273d2b3d12" , tea .StringValue (HexEncode (res )))
257257}
258+
259+ func Test_GetThrottlingTimeLeft (t * testing.T ) {
260+ headers := map [string ]* string {
261+ "X-RateLimit-User-API" : nil ,
262+ "X-RateLimit-User" : nil ,
263+ }
264+ timeLeft := GetThrottlingTimeLeft (headers )
265+ utils .AssertNil (t , timeLeft )
266+
267+ headers = map [string ]* string {
268+ "X-RateLimit-User-API" : nil ,
269+ "X-RateLimit-User" : tea .String ("Limit:1,Remain:0,TimeLeft:2000,Reset:1234" ),
270+ }
271+ timeLeft = GetThrottlingTimeLeft (headers )
272+ utils .AssertEqual (t , int64 (2000 ), tea .Int64Value (timeLeft ))
273+
274+ headers = map [string ]* string {
275+ "X-RateLimit-User-API" : tea .String ("Limit:1,Remain:0,TimeLeft:2000,Reset:1234" ),
276+ "X-RateLimit-User" : nil ,
277+ }
278+ timeLeft = GetThrottlingTimeLeft (headers )
279+ utils .AssertEqual (t , int64 (2000 ), tea .Int64Value (timeLeft ))
280+
281+ headers = map [string ]* string {
282+ "X-RateLimit-User-API" : tea .String ("Limit:1,Remain:0,TimeLeft:2000,Reset:1234" ),
283+ "X-RateLimit-User" : tea .String ("Limit:1,Remain:0,TimeLeft:0,Reset:1234" ),
284+ }
285+ timeLeft = GetThrottlingTimeLeft (headers )
286+ utils .AssertEqual (t , int64 (2000 ), tea .Int64Value (timeLeft ))
287+
288+ headers = map [string ]* string {
289+ "X-RateLimit-User-API" : tea .String ("Limit:1,Remain:0,TimeLeft:0,Reset:1234" ),
290+ "X-RateLimit-User" : tea .String ("Limit:1,Remain:0,TimeLeft:0,Reset:1234" ),
291+ }
292+ timeLeft = GetThrottlingTimeLeft (headers )
293+ utils .AssertEqual (t , int64 (0 ), tea .Int64Value (timeLeft ))
294+ }
0 commit comments