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

[TF-7941] Add support for Terraform Test #755

Merged
merged 10 commits into from
Sep 11, 2023
Merged

Conversation

aaabdelgany
Copy link
Contributor

@aaabdelgany aaabdelgany commented Aug 15, 2023

Description

This PR adds support for the new Terraform Test Runs API.

We can create new kinds of registry modules (branch-based), upload configuration versions against registry modules, and create, monitor, and cancel test runs.

Testing plan

I've ran numerous e2e tests manually using my local build of Terraform Core. You can see the PR in the Terraform repo that uses this to integrate the testing framework with TFC: hashicorp/terraform#33710

I've added integration tests for the new API calls in this PR as well, but they are unfortunately untestable at the moment as the test endpoints are protected by a feature flag while the testing framework is going through the Beta rollout. This means that organisations created newly within the testing framework don't have access to the test runs endpoint.

Testing output

I have executed the tests locally, by hacking the create organisation helper function to load an already whitelisted organisation from the staging environment instead of creating a new one and they've passed.

~/hashicorp/go-tfe (nexus/terraform_test_cli) > envchain go-tfe go test -run TestTestRuns -v ./...
?       github.com/hashicorp/go-tfe/examples/configuration_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/organizations      [no test files]
?       github.com/hashicorp/go-tfe/examples/registry_modules   [no test files]
?       github.com/hashicorp/go-tfe/examples/state_versions     [no test files]
?       github.com/hashicorp/go-tfe/examples/users      [no test files]
?       github.com/hashicorp/go-tfe/examples/workspaces [no test files]
?       github.com/hashicorp/go-tfe/mocks       [no test files]
=== RUN   TestTestRunsList
=== RUN   TestTestRunsList/without_list_options
=== RUN   TestTestRunsList/empty_list_options
=== RUN   TestTestRunsList/with_page_size
--- PASS: TestTestRunsList (5.82s)
    --- PASS: TestTestRunsList/without_list_options (0.23s)
    --- PASS: TestTestRunsList/empty_list_options (0.23s)
    --- PASS: TestTestRunsList/with_page_size (0.21s)
=== RUN   TestTestRunsRead
=== RUN   TestTestRunsRead/when_the_test_run_exists
=== RUN   TestTestRunsRead/when_the_test_run_does_not_exist
--- PASS: TestTestRunsRead (4.55s)
    --- PASS: TestTestRunsRead/when_the_test_run_exists (0.23s)
    --- PASS: TestTestRunsRead/when_the_test_run_does_not_exist (0.20s)
=== RUN   TestTestRunsCreate
=== RUN   TestTestRunsCreate/with_a_configuration_version
=== RUN   TestTestRunsCreate/without_a_configuration_version
=== RUN   TestTestRunsCreate/without_a_module
--- PASS: TestTestRunsCreate (4.09s)
    --- PASS: TestTestRunsCreate/with_a_configuration_version (0.29s)
    --- PASS: TestTestRunsCreate/without_a_configuration_version (0.00s)
    --- PASS: TestTestRunsCreate/without_a_module (0.00s)
=== RUN   TestTestRunsLogs
=== RUN   TestTestRunsLogs/when_the_log_exists
=== RUN   TestTestRunsLogs/when_the_log_does_not_exist
--- PASS: TestTestRunsLogs (11.90s)
    --- PASS: TestTestRunsLogs/when_the_log_exists (7.54s)
    --- PASS: TestTestRunsLogs/when_the_log_does_not_exist (0.21s)
=== RUN   TestTestRunsCancel
=== RUN   TestTestRunsCancel/when_the_run_exists
=== RUN   TestTestRunsCancel/when_the_run_does_not_exist
--- PASS: TestTestRunsCancel (4.63s)
    --- PASS: TestTestRunsCancel/when_the_run_exists (0.24s)
    --- PASS: TestTestRunsCancel/when_the_run_does_not_exist (0.21s)
PASS
ok      github.com/hashicorp/go-tfe     31.696s

@liamcervante liamcervante changed the title [BETA] Terraform Test implementation [WIP][TF-7941] Add support for Terraform Test Aug 25, 2023
@liamcervante liamcervante changed the title [WIP][TF-7941] Add support for Terraform Test [TF-7941] Add support for Terraform Test Sep 1, 2023
@liamcervante liamcervante marked this pull request as ready for review September 1, 2023 14:30
@liamcervante liamcervante requested a review from a team as a code owner September 1, 2023 14:30
@liamcervante liamcervante marked this pull request as draft September 1, 2023 14:31
@aaabdelgany aaabdelgany marked this pull request as ready for review September 1, 2023 18:41
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Looks highly idiomatic! Just a few minor concerns

helper_test.go Outdated Show resolved Hide resolved
helper_test.go Outdated Show resolved Hide resolved
}

moduleID := RegistryModuleID{
Organization: options.RegistryModule.Organization.Name,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Organization could be nil here, causing a panic. You could check for this in TestRunCreateOptions valid

Copy link
Member

Choose a reason for hiding this comment

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

Done!

errors.go Outdated
@@ -354,6 +354,10 @@ var (

ErrRequiredRegistryModule = errors.New("registry module is required")

ErrInvalidRegistryModuleID = errors.New("invalid value for registry module ID")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is being used

Copy link
Member

Choose a reason for hiding this comment

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

Removed!

liamcervante and others added 2 commits September 11, 2023 16:14
Co-authored-by: Brandon Croft <brandon.croft@gmail.com>
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

👍

@liamcervante liamcervante merged commit c69ce29 into main Sep 11, 2023
10 checks passed
@liamcervante liamcervante deleted the nexus/terraform_test_cli branch September 11, 2023 15:13
@github-actions
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

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.

3 participants