Skip to content

Commit

Permalink
test(app): #40505 added test for issue #40505
Browse files Browse the repository at this point in the history
Added test for the issue #40505 to verify if the name is the same as in input of the resource configuration and not a default name
  • Loading branch information
Hugo Joubert authored and Hugo Joubert committed Dec 27, 2024
1 parent 5ee5088 commit 4a1a105
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions internal/service/apigatewayv2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,35 @@ func TestAccAPIGatewayV2API_quickCreate(t *testing.T) {
})
}

func TestAccAPIGatewayV2API_name(t *testing.T) {
ctx := acctest.Context(t)
var v apigatewayv2.GetApiOutput
resourceName := "aws_apigatewayv2_api.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayV2ServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAPIDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAPIConfig_open(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAPIExists(ctx, resourceName, &v),
testAccCheckAPIName(ctx, resourceName, rName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"body"},
},
},
})
}

func testAccCheckAPIDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayV2Client(ctx)
Expand Down Expand Up @@ -875,6 +904,31 @@ func testAccCheckAPIQuickCreateStage(ctx context.Context, n, expectedName string
}
}

func testAccCheckAPIName(ctx context.Context, n, expectedName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.ID == "" {
return fmt.Errorf("No API Gateway v2 API ID is set")
}

conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayV2Client(ctx)

output, err := tfapigatewayv2.FindAPIByID(ctx, conn, rs.Primary.ID)
if err != nil {
return err
}

if aws.ToString(output.Name) != expectedName {
return fmt.Errorf("Incorrect API name. Expected: %s, got: %s", expectedName, aws.ToString(output.Name))
}

return nil
}
}
func testAccAPIConfig_basicWebSocket(rName string) string {
return fmt.Sprintf(`
resource "aws_apigatewayv2_api" "test" {
Expand Down

0 comments on commit 4a1a105

Please sign in to comment.