|
| 1 | +// Copyright IBM Corp. 2014, 2026 |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package apigateway_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/YakDriver/regexache" |
| 10 | + "github.com/hashicorp/terraform-plugin-testing/config" |
| 11 | + "github.com/hashicorp/terraform-plugin-testing/helper/resource" |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/knownvalue" |
| 13 | + "github.com/hashicorp/terraform-plugin-testing/querycheck" |
| 14 | + "github.com/hashicorp/terraform-plugin-testing/statecheck" |
| 15 | + "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" |
| 16 | + "github.com/hashicorp/terraform-plugin-testing/tfversion" |
| 17 | + "github.com/hashicorp/terraform-provider-aws/internal/acctest" |
| 18 | + tfquerycheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/querycheck" |
| 19 | + tfqueryfilter "github.com/hashicorp/terraform-provider-aws/internal/acctest/queryfilter" |
| 20 | + tfstatecheck "github.com/hashicorp/terraform-provider-aws/internal/acctest/statecheck" |
| 21 | + "github.com/hashicorp/terraform-provider-aws/names" |
| 22 | +) |
| 23 | + |
| 24 | +func TestAccAPIGatewayIntegrationResponse_List_basic(t *testing.T) { |
| 25 | + ctx := acctest.Context(t) |
| 26 | + |
| 27 | + resourceName1 := "aws_api_gateway_integration_response.test[0]" |
| 28 | + resourceName2 := "aws_api_gateway_integration_response.test[1]" |
| 29 | + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) |
| 30 | + |
| 31 | + identity1 := tfstatecheck.Identity() |
| 32 | + identity2 := tfstatecheck.Identity() |
| 33 | + |
| 34 | + acctest.ParallelTest(ctx, t, resource.TestCase{ |
| 35 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 36 | + tfversion.SkipBelow(tfversion.Version1_14_0), |
| 37 | + }, |
| 38 | + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckAPIGatewayTypeEDGE(t) }, |
| 39 | + ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID), |
| 40 | + CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t), |
| 41 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 42 | + Steps: []resource.TestStep{ |
| 43 | + // Step 1: Setup |
| 44 | + { |
| 45 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_basic/"), |
| 46 | + ConfigVariables: config.Variables{ |
| 47 | + acctest.CtRName: config.StringVariable(rName), |
| 48 | + "status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")), |
| 49 | + }, |
| 50 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 51 | + identity1.GetIdentity(resourceName1), |
| 52 | + identity2.GetIdentity(resourceName2), |
| 53 | + }, |
| 54 | + }, |
| 55 | + // Step 2: Query |
| 56 | + { |
| 57 | + Query: true, |
| 58 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_basic/"), |
| 59 | + ConfigVariables: config.Variables{ |
| 60 | + acctest.CtRName: config.StringVariable(rName), |
| 61 | + "status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")), |
| 62 | + }, |
| 63 | + QueryResultChecks: []querycheck.QueryResultCheck{ |
| 64 | + tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()), |
| 65 | + querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), knownvalue.StringRegexp(regexache.MustCompile(`^GET (200|400)$`))), |
| 66 | + tfquerycheck.ExpectNoResourceObject("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks())), |
| 67 | + |
| 68 | + tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity2.Checks()), |
| 69 | + querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity2.Checks()), knownvalue.StringRegexp(regexache.MustCompile(`^GET (200|400)$`))), |
| 70 | + tfquerycheck.ExpectNoResourceObject("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity2.Checks())), |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
| 74 | + }) |
| 75 | +} |
| 76 | + |
| 77 | +func TestAccAPIGatewayIntegrationResponse_List_includeResource(t *testing.T) { |
| 78 | + ctx := acctest.Context(t) |
| 79 | + |
| 80 | + resourceName1 := "aws_api_gateway_integration_response.test[0]" |
| 81 | + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) |
| 82 | + |
| 83 | + identity1 := tfstatecheck.Identity() |
| 84 | + |
| 85 | + acctest.ParallelTest(ctx, t, resource.TestCase{ |
| 86 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 87 | + tfversion.SkipBelow(tfversion.Version1_14_0), |
| 88 | + }, |
| 89 | + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckAPIGatewayTypeEDGE(t) }, |
| 90 | + ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID), |
| 91 | + CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t), |
| 92 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 93 | + Steps: []resource.TestStep{ |
| 94 | + // Step 1: Setup |
| 95 | + { |
| 96 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_include_resource/"), |
| 97 | + ConfigVariables: config.Variables{ |
| 98 | + acctest.CtRName: config.StringVariable(rName), |
| 99 | + "status_codes": config.ListVariable(config.StringVariable("200")), |
| 100 | + }, |
| 101 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 102 | + identity1.GetIdentity(resourceName1), |
| 103 | + }, |
| 104 | + }, |
| 105 | + // Step 2: Query |
| 106 | + { |
| 107 | + Query: true, |
| 108 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_include_resource/"), |
| 109 | + ConfigVariables: config.Variables{ |
| 110 | + acctest.CtRName: config.StringVariable(rName), |
| 111 | + "status_codes": config.ListVariable(config.StringVariable("200")), |
| 112 | + }, |
| 113 | + QueryResultChecks: []querycheck.QueryResultCheck{ |
| 114 | + tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()), |
| 115 | + querycheck.ExpectResourceDisplayName("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), knownvalue.StringExact("GET 200")), |
| 116 | + querycheck.ExpectResourceKnownValues("aws_api_gateway_integration_response.test", tfqueryfilter.ByResourceIdentityFunc(identity1.Checks()), []querycheck.KnownValueCheck{ |
| 117 | + tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrID), knownvalue.NotNull()), |
| 118 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("content_handling"), knownvalue.StringExact("")), |
| 119 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("http_method"), knownvalue.StringExact("GET")), |
| 120 | + tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrResourceID), knownvalue.NotNull()), |
| 121 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("response_parameters"), knownvalue.MapExact(map[string]knownvalue.Check{})), |
| 122 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("response_templates"), knownvalue.MapExact(map[string]knownvalue.Check{})), |
| 123 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("rest_api_id"), knownvalue.NotNull()), |
| 124 | + tfquerycheck.KnownValueCheck(tfjsonpath.New("selection_pattern"), knownvalue.StringExact("")), |
| 125 | + tfquerycheck.KnownValueCheck(tfjsonpath.New(names.AttrStatusCode), knownvalue.StringExact("200")), |
| 126 | + }), |
| 127 | + }, |
| 128 | + }, |
| 129 | + }, |
| 130 | + }) |
| 131 | +} |
| 132 | + |
| 133 | +func TestAccAPIGatewayIntegrationResponse_List_regionOverride(t *testing.T) { |
| 134 | + ctx := acctest.Context(t) |
| 135 | + |
| 136 | + resourceName1 := "aws_api_gateway_integration_response.test[0]" |
| 137 | + resourceName2 := "aws_api_gateway_integration_response.test[1]" |
| 138 | + rName := acctest.RandomWithPrefix(t, acctest.ResourcePrefix) |
| 139 | + |
| 140 | + identity1 := tfstatecheck.Identity() |
| 141 | + identity2 := tfstatecheck.Identity() |
| 142 | + |
| 143 | + acctest.ParallelTest(ctx, t, resource.TestCase{ |
| 144 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 145 | + tfversion.SkipBelow(tfversion.Version1_14_0), |
| 146 | + }, |
| 147 | + PreCheck: func() { |
| 148 | + acctest.PreCheck(ctx, t) |
| 149 | + acctest.PreCheckMultipleRegion(t, 2) |
| 150 | + acctest.PreCheckAPIGatewayTypeEDGE(t) |
| 151 | + }, |
| 152 | + ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID), |
| 153 | + CheckDestroy: testAccCheckIntegrationResponseDestroy(ctx, t), |
| 154 | + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, |
| 155 | + Steps: []resource.TestStep{ |
| 156 | + // Step 1: Setup |
| 157 | + { |
| 158 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_region_override/"), |
| 159 | + ConfigVariables: config.Variables{ |
| 160 | + acctest.CtRName: config.StringVariable(rName), |
| 161 | + "status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")), |
| 162 | + "region": config.StringVariable(acctest.AlternateRegion()), |
| 163 | + }, |
| 164 | + ConfigStateChecks: []statecheck.StateCheck{ |
| 165 | + identity1.GetIdentity(resourceName1), |
| 166 | + identity2.GetIdentity(resourceName2), |
| 167 | + }, |
| 168 | + }, |
| 169 | + // Step 2: Query |
| 170 | + { |
| 171 | + Query: true, |
| 172 | + ConfigDirectory: config.StaticDirectory("testdata/IntegrationResponse/list_region_override/"), |
| 173 | + ConfigVariables: config.Variables{ |
| 174 | + acctest.CtRName: config.StringVariable(rName), |
| 175 | + "status_codes": config.ListVariable(config.StringVariable("200"), config.StringVariable("400")), |
| 176 | + "region": config.StringVariable(acctest.AlternateRegion()), |
| 177 | + }, |
| 178 | + QueryResultChecks: []querycheck.QueryResultCheck{ |
| 179 | + tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity1.Checks()), |
| 180 | + tfquerycheck.ExpectIdentityFunc("aws_api_gateway_integration_response.test", identity2.Checks()), |
| 181 | + }, |
| 182 | + }, |
| 183 | + }, |
| 184 | + }) |
| 185 | +} |
0 commit comments