-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b379d3
commit 910366b
Showing
4 changed files
with
126 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,112 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/appsync" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccAwsAppsyncGraphqlApi_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckAwsAppsyncGraphqlApiDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAppsyncGraphqlApiConfig_apikey(acctest.RandString(5)), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsAppsyncGraphqlApiExists("aws_appsync_graphql_api.test_apikey"), | ||
resource.TestCheckResourceAttrSet("aws_appsync_graphql_api.test_apikey", "arn"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAppsyncGraphqlApiConfig_iam(acctest.RandString(5)), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsAppsyncGraphqlApiExists("aws_appsync_graphql_api.test_iam"), | ||
resource.TestCheckResourceAttrSet("aws_appsync_graphql_api.test_iam", "arn"), | ||
), | ||
}, | ||
{ | ||
Config: testAccAppsyncGraphqlApiConfig_cognito(acctest.RandString(5)), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAwsAppsyncGraphqlApiExists("aws_appsync_graphql_api.test_cognito"), | ||
resource.TestCheckResourceAttrSet("aws_appsync_graphql_api.test_cognito", "arn"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckAwsAppsyncGraphqlApiDestroy(s *terraform.State) error { | ||
conn := testAccProvider.Meta().(*AWSClient).appsyncconn | ||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "aws_appsync_graphql_api" { | ||
continue | ||
} | ||
|
||
input := &appsync.GetGraphqlApiInput{ | ||
ApiId: aws.String(rs.Primary.ID), | ||
} | ||
|
||
_, err := conn.GetGraphqlApi(input) | ||
if err != nil { | ||
if isAWSErr(err, appsync.ErrCodeNotFoundException, "") { | ||
return nil | ||
} | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func testAccCheckAwsAppsyncGraphqlApiExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
_, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccAppsyncGraphqlApiConfig_apikey(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_appsync_graphql_api" "test_apikey" { | ||
authentication_type = "API_KEY" | ||
name = "tf_appsync_%s" | ||
} | ||
`, rName) | ||
} | ||
|
||
func testAccAppsyncGraphqlApiConfig_iam(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_appsync_graphql_api" "test_iam" { | ||
authentication_type = "AWS_IAM" | ||
name = "tf_appsync_%s" | ||
} | ||
`, rName) | ||
} | ||
|
||
func testAccAppsyncGraphqlApiConfig_cognito(rName string) string { | ||
return fmt.Sprintf(` | ||
resource "aws_cognito_user_pool" "test" { | ||
name = "tf-%s" | ||
} | ||
resource "aws_appsync_graphql_api" "test_cognito" { | ||
authentication_type = "AMAZON_COGNITO_USER_POOLS" | ||
name = "tf_appsync_%s" | ||
user_pool_config { | ||
aws_region = "us-west-2" | ||
default_action = "ALLOW" | ||
user_pool_id = "${aws_cognito_user_pool.test.id}" | ||
} | ||
} | ||
`, rName, rName) | ||
} |