1
1
package tencentcloud
2
2
3
3
import (
4
- "context"
5
- "fmt"
6
- "strings"
7
4
"testing"
8
5
9
6
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
10
- "github.com/hashicorp/terraform-plugin-sdk/terraform"
11
7
)
12
8
13
9
var testAPIGatewaythrottlingApiDataSourceName = "data.tencentcloud_api_gateway_throttling_apis"
@@ -16,12 +12,12 @@ func TestAccTencentAPIGatewayThrottlingApisDataSource(t *testing.T) {
16
12
resource .Test (t , resource.TestCase {
17
13
PreCheck : func () { testAccPreCheck (t ) },
18
14
Providers : testAccProviders ,
19
- CheckDestroy : testAccCheckThrottlingAPIDestroy ,
15
+ CheckDestroy : testAccCheckAPIGatewayAPIDestroy ,
20
16
Steps : []resource.TestStep {
21
17
{
22
18
Config : testAccTestAccTencentAPIGatewayThrottlingApis (),
23
19
Check : resource .ComposeAggregateTestCheckFunc (
24
- testAccCheckThrottlingAPIExists ( "tencentcloud_api_gateway_throttling_api.service " ),
20
+ testAccCheckAPIGatewayAPIExists ( "tencentcloud_api_gateway_api.api " ),
25
21
resource .TestCheckResourceAttrSet (testAPIGatewaythrottlingApiDataSourceName + ".id" , "list.#" ),
26
22
resource .TestCheckResourceAttrSet (testAPIGatewaythrottlingApiDataSourceName + ".id" , "list.0.service_id" ),
27
23
resource .TestCheckResourceAttrSet (testAPIGatewaythrottlingApiDataSourceName + ".id" , "list.0.api_environment_strategies.#" ),
@@ -49,87 +45,6 @@ func TestAccTencentAPIGatewayThrottlingApisDataSource(t *testing.T) {
49
45
})
50
46
}
51
47
52
- func testAccCheckThrottlingAPIDestroy (s * terraform.State ) error {
53
- var (
54
- logId = getLogId (contextNil )
55
- ctx = context .WithValue (context .TODO (), logIdKey , logId )
56
- throttlingService = APIGatewayService {client : testAccProvider .Meta ().(* TencentCloudClient ).apiV3Conn }
57
- )
58
- for _ , rs := range s .RootModule ().Resources {
59
- if rs .Type != "tencentcloud_api_gateway_throttling_api" {
60
- continue
61
- }
62
-
63
- serviceId := rs .Primary .Attributes ["service_id" ]
64
- environmentName := rs .Primary .Attributes ["environment_name" ]
65
- apiIds := rs .Primary .Attributes ["api_ids" ]
66
- environmentList , err := throttlingService .DescribeApiEnvironmentStrategyList (ctx , serviceId , []string {environmentName }, "" )
67
- if err != nil {
68
- return err
69
- }
70
-
71
- for _ , v := range environmentList {
72
- if v == nil || ! strings .Contains (apiIds , * v .ApiId ) {
73
- continue
74
- }
75
- environmentSet := v .EnvironmentStrategySet
76
- for _ , env := range environmentSet {
77
- if env == nil || * env .EnvironmentName != environmentName {
78
- continue
79
- }
80
-
81
- if * env .Quota == QUOTA || * env .Quota == QUOTA_MAX {
82
- continue
83
- }
84
- return fmt .Errorf ("throttling API still not restore: %s" , rs .Primary .ID )
85
- }
86
- }
87
- }
88
- return nil
89
- }
90
-
91
- func testAccCheckThrottlingAPIExists (n string ) resource.TestCheckFunc {
92
- return func (s * terraform.State ) error {
93
- var (
94
- logId = getLogId (contextNil )
95
- ctx = context .WithValue (context .TODO (), logIdKey , logId )
96
- throttlingService = APIGatewayService {client : testAccProvider .Meta ().(* TencentCloudClient ).apiV3Conn }
97
- )
98
-
99
- rs , ok := s .RootModule ().Resources [n ]
100
- if ! ok {
101
- return fmt .Errorf ("API Getway throttling API %s is not found" , n )
102
- }
103
- if rs .Primary .ID == "" {
104
- return fmt .Errorf ("API Getway throttling API id is not set" )
105
- }
106
- serviceId := rs .Primary .Attributes ["service_id" ]
107
- environmentName := rs .Primary .Attributes ["environment_name" ]
108
- apiIds := rs .Primary .Attributes ["api_ids" ]
109
- environmentList , err := throttlingService .DescribeApiEnvironmentStrategyList (ctx , serviceId , []string {environmentName }, "" )
110
- if err != nil {
111
- return err
112
- }
113
-
114
- for _ , v := range environmentList {
115
- if v == nil || ! strings .Contains (apiIds , * v .ApiId ) {
116
- continue
117
- }
118
- environmentSet := v .EnvironmentStrategySet
119
- for _ , env := range environmentSet {
120
- if env == nil || * env .EnvironmentName != environmentName {
121
- continue
122
- }
123
-
124
- if * env .Quota == QUOTA {
125
- return fmt .Errorf ("throttling API still not set value: %s" , rs .Primary .ID )
126
- }
127
- }
128
- }
129
- return nil
130
- }
131
- }
132
-
133
48
func testAccTestAccTencentAPIGatewayThrottlingApis () string {
134
49
return `
135
50
resource "tencentcloud_api_gateway_service" "service" {
@@ -164,29 +79,27 @@ resource "tencentcloud_api_gateway_api" "api" {
164
79
service_config_method = "POST"
165
80
response_type = "XML"
166
81
response_success_example = "<note>success</note>"
167
- response_fail_example = "<note>fail</note>"
82
+ response_fail_example = "<note>fail</note>"
83
+
168
84
response_error_codes {
169
85
code = 10
170
86
msg = "system error"
171
87
desc = "system error code"
172
88
converted_code = -10
173
89
need_convert = true
174
- }
175
- }
176
-
177
- resource "tencentcloud_api_gateway_throttling_api" "service" {
178
- service_id = tencentcloud_api_gateway_service.service.id
179
- strategy = "400"
180
- environment_name = "test"
181
- api_ids = [tencentcloud_api_gateway_api.api.id]
90
+ }
91
+
92
+ release_limit = 100
93
+ pre_limit = 100
94
+ test_limit = 100
182
95
}
183
96
184
97
data "tencentcloud_api_gateway_throttling_apis" "id" {
185
- service_id = tencentcloud_api_gateway_throttling_api.service .service_id
98
+ service_id = tencentcloud_api_gateway_api.api .service_id
186
99
}
187
100
188
101
data "tencentcloud_api_gateway_throttling_apis" "foo" {
189
- service_id = tencentcloud_api_gateway_throttling_api.service .service_id
102
+ service_id = tencentcloud_api_gateway_api.api .service_id
190
103
environment_names = ["release", "test"]
191
104
}
192
105
`
0 commit comments