Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/provider: Skip unsupported tests with PreChecks #14188

Open
gdavison opened this issue Jul 15, 2020 · 2 comments
Open

tests/provider: Skip unsupported tests with PreChecks #14188

gdavison opened this issue Jul 15, 2020 · 2 comments
Assignees
Labels
enhancement Requests to existing resources that expand the functionality or scope. partition/aws-us-gov Pertains to the aws-us-gov partition. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.

Comments

@gdavison
Copy link
Contributor

gdavison commented Jul 15, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

We currently use PreCheck functions in acceptance tests to ensure that acceptance tests can be executed in the current partition, account, and/or region. If an endpoint does not exist or a sample operation returns certain error values, the test is skipped.

These are some examples of what a precheck looks for:

  1. Endpoint existence: If a service's endpoint does not exist, the service cannot be tested. For instance, testAccPartitionHasServicePreCheck("codestar", t) verifies that the CodeStar service is available.
  2. Feature availability: Not all features of a service may exist in all partitions, accounts, and/or regions. Often you must add a custom precheck function to test for a feature. For instance, database performance insights are not supported in databases running in GovCloud. A custom function ensures that performance insights are available before testing the feature. NOTE: Ideally, the precheck should verify actual functionality instead of being a hardcoded partition check. That way, when AWS adds this feature to the RDS service in the future, the precheck won't need to be modified to start running tests as soon as the functionality is available.
  3. Environment & credentials: Many existing precheck functions check to make sure that credentials, environment variables, regions, alternate accounts, alternate regions, etc. are available for tests that require them.

In the acceptance test, add a call to an endpoint precheck (e.g., testAccPartitionHasServicePreCheck("codestar", t) below) and/or a custom precheck function that tests for necessary underlying conditions for the test to be run:

func TestAccAWSCodeStarNotificationsNotificationRule_Status(t *testing.T) {
	// code...

	resource.ParallelTest(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t); testAccPartitionHasServicePreCheck("codestar", t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccCheckAWSCodeStarNotificationsNotificationRuleDestroy,
		Steps: []resource.TestStep{
			// code ...
		},
	})
}

An example of a custom precheck:

func testAccPreCheckAWSCodePipeline(t *testing.T) {
	conn := testAccProvider.Meta().(*AWSClient).codepipelineconn

	input := &codepipeline.ListPipelinesInput{}

	_, err := conn.ListPipelines(input)

	if testAccPreCheckSkipError(err) {
		t.Skipf("skipping acceptance testing: %s", err)
	}

	if err != nil {
		t.Fatalf("unexpected PreCheck error: %s", err)
	}
}

These checks can only run against the default provider configuration. In some cases, a PreCheck needs to run against an alternate provider configuration, such as for an alternate region or account.

Add functions to the testing suite that will configure AWS API connections using the authentication configuration settings for acceptance tests.

@gdavison gdavison added the enhancement Requests to existing resources that expand the functionality or scope. label Jul 15, 2020
@YakDriver YakDriver added partition/aws-us-gov Pertains to the aws-us-gov partition. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 5, 2020
@YakDriver
Copy link
Member

YakDriver commented Oct 5, 2020

You do not need access to GovCloud to assist with adding prechecks!

When verifying that a precheck works properly, the test should be skipped when preconditions are not met. However, it is also important to ensure that the test is not skipped when preconditions are met. For example, if you add a precheck for a service and do not access to GovCloud, verifying that tests aren't skipped in the standard/AWS partition is sufficient.

What a skipped test will look like:

    provider_test.go:511: skipping tests; partition aws-us-gov does not support codestar service
--- SKIP: TestAccAWSCodeStarNotificationsNotificationRule_Status (1.61s)

What a test looks like that is not skipped:

--- PASS: TestAccAWSCodeStarNotificationsNotificationRule_basic (18.75s)

Endpoints still failing (e.g., no such host):

@YakDriver YakDriver added the technical-debt Addresses areas of the codebase that need refactoring or redesign. label Oct 5, 2020
@YakDriver YakDriver changed the title Enable acceptance test PreChecks to make API calls against non-default AWS regions or accounts Skip unsupported tests with PreChecks Oct 5, 2020
@YakDriver YakDriver changed the title Skip unsupported tests with PreChecks tests/provider: Skip unsupported tests with PreChecks Oct 5, 2020
@YakDriver YakDriver self-assigned this Oct 5, 2020
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label May 19, 2024
@gdavison gdavison removed the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Requests to existing resources that expand the functionality or scope. partition/aws-us-gov Pertains to the aws-us-gov partition. technical-debt Addresses areas of the codebase that need refactoring or redesign. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

No branches or pull requests

3 participants