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

Add simple Organization DataSource and implement integration acceptance tests #8

Merged
merged 23 commits into from
Apr 11, 2024

Conversation

vandyliu
Copy link
Collaborator

@vandyliu vandyliu commented Apr 10, 2024

Description

This PR

  • adds Organization Data Source (will add more fields later)
  • adds integration acceptance tests for workspace data source, workspaces data source, org data source, workspace resource and the provider
  • we use the org data source for the provider tests which is why i added a basic version of it first
  • it also runs the tests on every push
  • in the future, we will not want to have that since creating deployments and clusters would be expensive
  • also removed ginkgo framework and using the go testing framework since thats how the acceptance tests use it and i didnt want to use two testing frameworks

🎟 Issue(s)

  • Creating acceptance tests

🧪 Functional Testing

📸 Screenshots

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make fmt before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

@vandyliu
Copy link
Collaborator Author

/run-testacc

@vandyliu
Copy link
Collaborator Author

/run-testacc

@vandyliu
Copy link
Collaborator Author

/testacc

1 similar comment
@vandyliu
Copy link
Collaborator Author

/testacc

@vandyliu
Copy link
Collaborator Author

/testacc

@vandyliu
Copy link
Collaborator Author

/testacc

@vandyliu
Copy link
Collaborator Author

/testacc

@vandyliu
Copy link
Collaborator Author

/testacc

@vandyliu vandyliu changed the title wip Add simple Organization DataSource and implement integration acceptance tests Apr 10, 2024
@vandyliu vandyliu marked this pull request as ready for review April 10, 2024 21:43
@vandyliu vandyliu requested review from sunkickr and a team as code owners April 10, 2024 21:43
@@ -0,0 +1,67 @@
# Terraform Provider testing workflow.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these imported from somewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're the ones terraform provide as sample GH action workflows to use for terraform provider repos

),
},
{
PreConfig: func() { deleteWorkspaceOutsideOfTerraform(t, workspaceName) },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind explaining a bit how these tests work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this to the readme

### Acceptance tests
Acceptance integration tests use a Terraform CLI binary to run real Terraform commands against the Astro API. The goal is to approximate using the provider with Terraform in production as closely as possible.

Using the terraform-plugin-testing framework, each `resource.Test` runs an acceptance test on a resource.
- `ProtoV6ProviderFactories`: map of the provider factories that the test suite will use to create the provider - just has the `astronomer` provider
- `PreCheck`: a function that runs before the test suite starts to check that all the required environment variables are set
- `Steps`: a list of `terraform apply` sequences that the test suite will run. Each step is a `resource.TestStep` that contains a `Config` and `Check` function.
  - `Config`: the Terraform configuration that the test will run (ie. the `.tf` file)
  - `Check`: function that will verify the state of the resources after the `terraform apply` command has run.

Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("astronomer_workspace.test", "name", workspaceName),
resource.TestCheckResourceAttr("astronomer_workspace.test", "description", utils.TestResourceDescription),
testAccCheckWorkspaceExistence(t, workspaceName, true),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we expect that once the workspace is deleted, it will be recreated by terraform right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we run terraform apply again then yes

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so basically this test is doing:

  • nuke the workspace from api
  • apply terraform
  • expect the workspace to be recreated

is this understanding correct? ^^

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea

  1. nuke workspace via api call (not terraform)
  2. run terraform apply
  3. check that the workspace is recreated with correct properties

resource.TestCheckResourceAttr("astronomer_workspace.test", "cicd_enforced_default", "true"),
),
},
// IMPORT
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this import do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uses the previous step, and imports the resource and checks that the properties are correct
https://stackoverflow.com/questions/68824711/how-can-i-test-terraform-import-in-acceptance-tests

will also add a comment

Copy link

@fredzhy fredzhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some questions only

@vandyliu vandyliu merged commit bde8d98 into main Apr 11, 2024
5 checks passed
@vandyliu vandyliu deleted the tests branch April 11, 2024 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants