Skip to content

Commit

Permalink
linting, update method used in testcheckdestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
anGie44 committed Feb 25, 2021
1 parent dc397fb commit c18646d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 60 deletions.
38 changes: 1 addition & 37 deletions aws/resource_aws_cognito_user_pool_ui_customization.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func resourceAwsCognitoUserPoolUICustomizationDelete(d *schema.ResourceData, met
UserPoolId: aws.String(userPoolId),
}

output, err := conn.SetUICustomization(input)
_, err = conn.SetUICustomization(input)

if tfawserr.ErrCodeEquals(err, cognitoidentityprovider.ErrCodeResourceNotFoundException) {
return nil
Expand All @@ -173,45 +173,9 @@ func resourceAwsCognitoUserPoolUICustomizationDelete(d *schema.ResourceData, met
return fmt.Errorf("error deleting Cognito User Pool UI customization (UserPoolId: %s, ClientId: %s): %w", userPoolId, clientId, err)
}

if output == nil || output.UICustomization == nil {
return nil
}

if cognitoUserPoolUICustomizationExists(output.UICustomization) {
return fmt.Errorf("error deleting Cognito User Pool UI customization (UserPoolId: %s, ClientId: %s): still exists", userPoolId, clientId)
}

return nil
}

// cognitoUserPoolUICustomizationExists validates the API object such that
// we define resource existence when the object is non-nil and
// at least one of the object's fields are non-nil with the exception of CSSVersion
// which remains as an artifact even after UI customization removal
func cognitoUserPoolUICustomizationExists(ui *cognitoidentityprovider.UICustomizationType) bool {
if ui == nil {
return false
}

if ui.CSS != nil {
return true
}

if ui.CreationDate != nil {
return true
}

if ui.ImageUrl != nil {
return true
}

if ui.LastModifiedDate != nil {
return true
}

return false
}

func parseCognitoUserPoolUICustomizationID(id string) (string, string, error) {
idParts := strings.SplitN(id, ",", 2)

Expand Down
74 changes: 51 additions & 23 deletions aws/resource_aws_cognito_user_pool_ui_customization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func testAccCheckAWSCognitoUserPoolUICustomizationDestroy(s *terraform.State) er
return err
}

if cognitoUserPoolUICustomizationExists(output) {
if testAccAWSCognitoUserPoolUICustomizationExists(output) {
return fmt.Errorf("Cognito User Pool UI Customization (UserPoolId: %s, ClientId: %s) still exists", userPoolId, clientId)
}
}
Expand Down Expand Up @@ -619,21 +619,21 @@ resource "aws_cognito_user_pool_ui_customization" "test" {
func testAccAWSCognitoUserPoolUICustomizationConfig_Client_CSS(rName, css string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "test" {
name = %[1]q
name = %[1]q
}
resource "aws_cognito_user_pool_domain" "test" {
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_client" "test" {
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_ui_customization" "test" {
client_id = aws_cognito_user_pool_client.test.id
client_id = aws_cognito_user_pool_client.test.id
css = %q
# Refer to the aws_cognito_user_pool_domain resource's
Expand All @@ -646,25 +646,25 @@ resource "aws_cognito_user_pool_ui_customization" "test" {
func testAccAWSCognitoUserPoolUICustomizationConfig_Client_Image(rName, filename string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "test" {
name = %[1]q
name = %[1]q
}
resource "aws_cognito_user_pool_domain" "test" {
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_client" "test" {
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_ui_customization" "test" {
client_id = aws_cognito_user_pool_client.test.id
client_id = aws_cognito_user_pool_client.test.id
image_file = filebase64(%q)
# Refer to the aws_cognito_user_pool_domain resource's
# user_pool_id attribute to ensure it is in an 'Active' state
# user_pool_id attribute to ensure it is in an 'Active' state
user_pool_id = aws_cognito_user_pool_domain.test.user_pool_id
}
`, rName, filename)
Expand All @@ -673,34 +673,62 @@ resource "aws_cognito_user_pool_ui_customization" "test" {
func testAccAWSCognitoUserPoolUICustomizationConfig_ClientAndAllCustomizations_CSS(rName, allCSS, clientCSS string) string {
return fmt.Sprintf(`
resource "aws_cognito_user_pool" "test" {
name = %[1]q
name = %[1]q
}
resource "aws_cognito_user_pool_domain" "test" {
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
domain = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_client" "test" {
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
name = %[1]q
user_pool_id = aws_cognito_user_pool.test.id
}
resource "aws_cognito_user_pool_ui_customization" "ui_all" {
css = %q
# Refer to the aws_cognito_user_pool_domain resource's
# user_pool_id attribute to ensure it is in an 'Active' state
# user_pool_id attribute to ensure it is in an 'Active' state
user_pool_id = aws_cognito_user_pool_domain.test.user_pool_id
}
resource "aws_cognito_user_pool_ui_customization" "ui_client" {
client_id = aws_cognito_user_pool_client.test.id
css = %q
client_id = aws_cognito_user_pool_client.test.id
css = %q
# Refer to the aws_cognito_user_pool_domain resource's
# user_pool_id attribute to ensure it is in an 'Active' state
# user_pool_id attribute to ensure it is in an 'Active' state
user_pool_id = aws_cognito_user_pool_domain.test.user_pool_id
}
`, rName, allCSS, clientCSS)
}

// testAccAWSCognitoUserPoolUICustomizationExists validates the API object such that
// we define resource existence when the object is non-nil and
// at least one of the object's fields are non-nil with the exception of CSSVersion
// which remains as an artifact even after UI customization removal
func testAccAWSCognitoUserPoolUICustomizationExists(ui *cognitoidentityprovider.UICustomizationType) bool {
if ui == nil {
return false
}

if ui.CSS != nil {
return true
}

if ui.CreationDate != nil {
return true
}

if ui.ImageUrl != nil {
return true
}

if ui.LastModifiedDate != nil {
return true
}

return false
}

0 comments on commit c18646d

Please sign in to comment.