github.com/polarismesh/polaris@v1.17.8/test/integrate/ratelimit_config_test.go (about) 1 //go:build integration 2 // +build integration 3 4 /** 5 * Tencent is pleased to support the open source community by making Polaris available. 6 * 7 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 8 * 9 * Licensed under the BSD 3-Clause License (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * https://opensource.org/licenses/BSD-3-Clause 14 * 15 * Unless required by applicable law or agreed to in writing, software distributed 16 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations under the License. 19 */ 20 21 package test 22 23 import ( 24 "testing" 25 26 "github.com/polarismesh/polaris/test/integrate/http" 27 "github.com/polarismesh/polaris/test/integrate/resource" 28 ) 29 30 /** 31 * @brief 测试增删改查限流规则 32 */ 33 34 /** 35 * @brief 测试增删改查限流规则 36 */ 37 func TestRateLimit(t *testing.T) { 38 t.Log("test rate limit interface") 39 40 client := http.NewClient(httpserverAddress, httpserverVersion) 41 42 namespaces := resource.CreateNamespaces() 43 services := resource.CreateServices(namespaces[0]) 44 45 // 创建命名空间 46 ret, err := client.CreateNamespaces(namespaces) 47 if err != nil { 48 t.Fatalf("create namespaces fail, err is %s", err.Error()) 49 } 50 for index, item := range ret.GetResponses() { 51 namespaces[index].Token = item.GetNamespace().GetToken() 52 } 53 t.Log("create namespaces success") 54 55 // 创建服务 56 ret, err = client.CreateServices(services) 57 if err != nil { 58 t.Fatalf("create services fail, err is %s", err.Error()) 59 } 60 for index, item := range ret.GetResponses() { 61 services[index].Token = item.GetService().GetToken() 62 } 63 t.Log("create services success") 64 65 // ------------------------------------------------------- 66 67 rateLimits := resource.CreateRateLimits(services) 68 69 // 创建限流规则 70 ret, err = client.CreateRateLimits(rateLimits) 71 if err != nil { 72 t.Fatalf("create rate limits fail, err is %s", err.Error()) 73 } 74 for index, item := range ret.GetResponses() { 75 rateLimits[index].Id = item.GetRateLimit().GetId() 76 } 77 t.Log("create rate limits success") 78 79 // 查询限流规则 80 err = client.GetRateLimits(rateLimits) 81 if err != nil { 82 t.Fatalf("get rate limits fail, err is %s", err.Error()) 83 } 84 t.Log("get rate limits success") 85 86 // 更新限流规则 87 resource.UpdateRateLimits(rateLimits) 88 89 err = client.UpdateRateLimits(rateLimits) 90 if err != nil { 91 t.Fatalf("update rate limits fail, err is %s", err.Error()) 92 } 93 t.Log("update rate limits success") 94 95 // 查询限流规则 96 err = client.GetRateLimits(rateLimits) 97 if err != nil { 98 t.Fatalf("get rate limits fail, err is %s", err.Error()) 99 } 100 t.Log("get rate limits success") 101 102 // 禁用限流规则 103 err = client.EnableRateLimits(rateLimits) 104 if err != nil { 105 t.Fatalf("enable rate limits fail, err is %s", err.Error()) 106 } 107 t.Log("enable rate limits success") 108 109 // 删除限流规则 110 err = client.DeleteRateLimits(rateLimits) 111 if err != nil { 112 t.Fatalf("delete rate limits fail, err is %s", err.Error()) 113 } 114 t.Log("delete rate limits success") 115 116 // ------------------------------------------------------- 117 118 // 删除服务 119 err = client.DeleteServices(services) 120 if err != nil { 121 t.Fatalf("delete services fail, err is %s", err.Error()) 122 } 123 t.Log("delete services success") 124 125 // 删除命名空间 126 err = client.DeleteNamespaces(namespaces) 127 if err != nil { 128 t.Fatalf("delete namespaces fail, err is %s", err.Error()) 129 } 130 t.Log("delete namespaces success") 131 }