[MAINT] Fix actions_hosted_runner tests#3521
Conversation
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
stevehipwell
left a comment
There was a problem hiding this comment.
Just a quick pre-review, the comments apply to all matching patterns not just the ones I commented on.
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…_error` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…figStateChecks` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…cks` and `ConfigPlanChecks` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…lanChecks` Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…` API methods Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…are CRUD functions Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
35fd280 to
47f2e38
Compare
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used.
This PR modernizes the github_actions_hosted_runner resource and its acceptance tests. It migrates the resource CRUD functions to the *Context variants returning diag.Diagnostics, replaces hand-rolled client.NewRequest/client.Do calls and map[string]any payload plumbing with typed go-github Actions.*HostedRunner methods, and stops calling Read after Create/Update (consistent with this provider's no-read-after-write convention). The tests are rewritten to use ConfigStateChecks/ConfigPlanChecks, share a single runner group created via a new helper, and use non-colliding subtest names. A new sweeper for organization runner groups (and their hosted runners) is added, and the default sweep target is broadened.
Changes:
- Refactor the hosted-runner resource to context-aware CRUD + typed
go-githubAPI calls, with newexpand/flattenhelpers operating on typed structs. - Rewrite acceptance tests to
statecheck/plancheck, unique subtest names, and a sharedmustCreateTestOrganizationActionsRunnerGrouphelper. - Add
sweepOrganizationRunnerGroups/sweepRunnerGroupRunnerssweepers and changeSWEEPdefault toall.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
github/resource_github_actions_hosted_runner.go |
Context-aware CRUD, typed API calls, new flatten/expand helpers; introduces GoString() state bug and nil-runner dereferences on the 202/AcceptedError paths. |
github/resource_github_actions_hosted_runner_test.go |
Tests migrated to state/plan checks, unique subtest names, shared runner group, updated import-verify ignore list. |
github/acc_test.go |
Adds organization runner-group sweeper and helper; contains a redundant nested if err != nil. |
github/acc_helpers_test.go |
Adds mustCreateTestOrganizationActionsRunnerGroup helper with cleanup. |
GNUmakefile |
Broadens default SWEEP to all and targets ./github for the sweep run. |
Key findings
- HIGH —
Deletepassesrunner.GetID()towaitForRunnerDeletion, butrunneris nil on the async202path, so it polls runner ID0, returns "deleted" immediately, and skips the real wait. - MEDIUM —
last_active_onis set fromTimestamp.GoString(), writinggithub.Timestamp{...}into state instead of the documented RFC3339 value (3 locations). - MEDIUM —
Createsets the resource ID from a nil runner on the202path, producing ID"0"and empty computed state.
| if err != nil { | ||
| if err != nil { | ||
| if resp != nil && resp.StatusCode == http.StatusNotFound { | ||
| continue | ||
| } | ||
| if _, ok := errors.AsType[*github.AcceptedError](err); ok { | ||
| if err := waitForRunnerDeletion(ctx, client, owner, r.GetID(), 5*time.Minute); err != nil { | ||
| return fmt.Errorf("failed to wait for runner deletion %s: %w", r.GetName(), err) | ||
| } | ||
| continue | ||
| } | ||
| return fmt.Errorf("failed to delete hosted runner %s: %w", r.GetName(), err) | ||
| } | ||
| } |
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Resolves #3405
Closes #3406
Before the change?
resource_github_actions_hosted_runnertests have naming collisionsresource_github_actions_hosted_runneruses legacy patternsAfter the change?
resource_github_actions_hosted_runnertests useConfigStateChecksandConfigPlanChecksresource_github_actions_hosted_runnertests don't use conflicting namesresource_github_actions_hosted_runnerto use Context-aware CRUD functionsresource_github_actions_hosted_runnerto not callReadafterUpdateandCreateresource_github_actions_hosted_runnerto usego-githubAPI methodsPull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!