Improve test quality: migrate action_reference_test.go to testify#19310
Improve test quality: migrate action_reference_test.go to testify#19310
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Migrates pkg/workflow/action_reference_test.go from manual if/t.Errorf assertions and repetitive subtests to a more maintainable style using testify/assert and table-driven tests.
Changes:
- Replace manual equality/empty checks with
assert.Equal/assert.Empty. - Refactor
TestConvertToRemoteActionRefandTestCompilerActionTaginto table-driven subtests. - Use
descriptionfields as assertion messages for clearer failures.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Create mock action resolver and cache | ||
| cache := NewActionCache("") | ||
| resolver := NewActionResolver(cache) | ||
|
|
||
| // The resolver will fail to resolve github/gh-aw/actions/setup@v1.0.0 | ||
| // since it's not a real tag, but it should fall back gracefully | ||
| ref := ResolveSetupActionReference(ActionModeRelease, "v1.0.0", "", resolver) | ||
|
|
||
| // Without a valid pin or successful resolution, should return tag-based reference | ||
| expectedRef := "github/gh-aw/actions/setup@v1.0.0" | ||
| if ref != expectedRef { | ||
| t.Errorf("Expected %q, got %q", expectedRef, ref) | ||
| } | ||
| assert.Equal(t, "github/gh-aw/actions/setup@v1.0.0", ref, "should return tag-based reference when SHA resolution fails") |
There was a problem hiding this comment.
TestResolveSetupActionReferenceWithData constructs a real ActionResolver, which calls gh api and can block on network (20s timeout) and is subject to CI/firewall constraints. Since this test only needs to verify fallback behavior when SHA resolution fails, use a small stub ActionSHAResolver that immediately returns an error/empty SHA instead of the real resolver to keep unit tests deterministic and fast.
| name: "compiler actionTag with dev mode forces release behavior", | ||
| version: "v1.0.0", | ||
| compilerActionTag: "v2.0.0", | ||
| localPath: "./actions/setup", | ||
| useResolve: true, | ||
| expectedRef: "github/gh-aw/actions/setup@v2.0.0", |
There was a problem hiding this comment.
The table case name "compiler actionTag with dev mode forces release behavior" is misleading: the test always sets ActionModeRelease and the version is v1.0.0 (not a dev build). Rename this case to reflect what’s actually being asserted (e.g., action-tag flag priority/behavior in release mode) to avoid confusion when diagnosing failures.
pkg/workflow/action_reference_test.gohad zero testify usage — all assertions were rawif/t.Errorfcomparisons, and two test functions used repetitive per-caset.Runblocks instead of table-driven patterns.Changes
testify/assertimport — replaces all manual comparison blocksTestConvertToRemoteActionRef— converted 10 individualt.Runsubtests to a single table-driven test; addednilData boolandsetEmptyTag boolfields for clean nil/empty edge-case handlingTestCompilerActionTag— converted 5 individualt.Runsubtests to a single table-driven test; addeduseResolve boolto distinguishconvertToRemoteActionRefvsresolveActionReferencecall pathsTestResolveActionReference/TestResolveSetupActionReference— existingdescriptionstruct fields now flow into assertion messages instead of being embedded int.Errorfformat stringsTestResolveSetupActionReferenceWithData— assertions replaced with descriptiveassert.EqualcallsBefore:
After:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw GO111MODULE 64/bin/go git rev-�� --show-toplevel go /usr/bin/git cli/install.sh..git GO111MODULE 64/bin/go git(http block)https://api.github.com/repos/actions/ai-inference/git/ref/tags/v1/usr/bin/gh gh api /repos/actions/ai-inference/git/ref/tags/v1 --jq .object.sha GOMODCACHE erignore /usr/bin/git e=false GO111MODULE 64/bin/go git conf�� user.email resolved$ /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet -json GO111MODULE 64/bin/go /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v3/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v3 --jq .object.sha -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE /usr/bin/git GOINSECURE GOMOD GOMODCACHE git(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v5/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env 3980905719/custom/workflows GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha /tmp/gh-aw-test-runs/20260303-021924-27764/test-1969773630 status /usr/bin/git .github/workflowgit GOPROXY 64/bin/go git rev-�� --git-dir sh /opt/hostedtoolcache/node/24.13.1/x64/bin/node "prettier" --chegit sh 64/bin/go node(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v5 --jq .object.sha --show-toplevel go /usr/bin/git ithub/workflows GO111MODULE 64/bin/go git rev-�� --show-toplevel go /usr/bin/git plorer.md GO111MODULE aw.test git(http block)https://api.github.com/repos/actions/checkout/git/ref/tags/v6/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha s/test.md GOPROXY /usr/bin/infocmp GOSUMDB GOWORK 64/bin/go infocmp -1 xterm-color go /usr/bin/git -json GO111MODULE 64/bin/go git(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha list --json /usr/bin/git -json GO111MODULE 64/bin/go git -C /home/REDACTED/work/gh-aw/gh-aw/.github/workflows rev-parse /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet -json GO111MODULE 64/bin/go /opt/hostedtoolcache/go/1.25.0/x64/pkg/tool/linux_amd64/vet(http block)/usr/bin/gh gh api /repos/actions/checkout/git/ref/tags/v6 --jq .object.sha --show-toplevel x_amd64/link /usr/bin/git -json GO111MODULE x_amd64/link git rev-�� --show-toplevel x_amd64/link /usr/bin/git -json GO111MODULE 64/bin/go git(http block)https://api.github.com/repos/actions/github-script/git/ref/tags/v8/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go env ck 'scripts/**/*GOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha f9dd00c75c79c7baGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD erignore ache/go/1.25.0/xGO111MODULE env 1098574/b411/_pkGOINSECURE GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)/usr/bin/gh gh api /repos/actions/github-script/git/ref/tags/v8 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/actions/setup-go/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/setup-go/git/ref/tags/v4 --jq .object.sha runs/20260303-021924-27764/test-1969773630 -trimpath /usr/bin/git s/test.md github.com/githurev-parse -lang=go1.25 git -C /home/REDACTED/work/gh-aw/gh-aw/.github/workflows rev-parse /usr/bin/gh -c=4 -nolocalimports -importcfg gh(http block)https://api.github.com/repos/actions/setup-node/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/setup-node/git/ref/tags/v4 --jq .object.sha -test.paniconexit0 -test.v=true /usr/bin/git -test.timeout=10git -test.run=^Test -test.short=true--show-toplevel git rev-�� --show-toplevel go(http block)https://api.github.com/repos/actions/upload-artifact/git/ref/tags/v4/usr/bin/gh gh api /repos/actions/upload-artifact/git/ref/tags/v4 --jq .object.sha -json GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go env 1924-27764/test-1969773630 GO111MODULE /opt/hostedtoolcache/go/1.25.0/x64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/1/artifacts/usr/bin/gh gh run download 1 --dir test-logs/run-1 GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/12345/artifacts/usr/bin/gh gh run download 12345 --dir test-logs/run-12345 GO111MODULE x_amd64/compile GOINSECURE GOMOD GOMODCACHE x_amd64/compile env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/12346/artifacts/usr/bin/gh gh run download 12346 --dir test-logs/run-12346 GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/2/artifacts/usr/bin/gh gh run download 2 --dir test-logs/run-2 GO111MODULE x_amd64/link GOINSECURE GOMOD GOMODCACHE x_amd64/link env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE Xe/zd3aBy0104K8ZfExHKi7/u8U4vpCVJ6IIRF6zALNG(http block)https://api.github.com/repos/github/gh-aw/actions/runs/3/artifacts/usr/bin/gh gh run download 3 --dir test-logs/run-3 GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/4/artifacts/usr/bin/gh gh run download 4 --dir test-logs/run-4 GO111MODULE x_amd64/vet GOINSECURE GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/runs/5/artifacts/usr/bin/gh gh run download 5 --dir test-logs/run-5 GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go estl�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/actions/workflows/usr/bin/gh gh workflow list --json name,state,path -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go m/_n�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE ; \ fi(http block)/usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 100 GOMOD GOMODCACHE o fix."; \ exitGOPROXY env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE node(http block)/usr/bin/gh gh run list --json databaseId,number,url,status,conclusion,workflowName,createdAt,startedAt,updatedAt,event,headBranch,headSha,displayTitle --workflow nonexistent-workflow-12345 --limit 6 GOMOD GOMODCACHE x_amd64/vet env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/github/gh-aw/git/ref/tags/v1.0.0/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha(http block)/usr/bin/gh gh api /repos/github/gh-aw/git/ref/tags/v1.0.0 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/nonexistent/action/git/ref/tags/v999.999.999/usr/bin/gh gh api /repos/nonexistent/action/git/ref/tags/v999.999.999 --jq .object.sha -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go env 2716143650/.github/workflows GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/nonexistent/repo/actions/runs/12345/usr/bin/gh gh run view 12345 --repo nonexistent/repo --json status,conclusion GOINSECURE GOMOD GOMODCACHE 51RFpkM/58sERvdotCvyK1taGOl6 env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/owner/repo/actions/workflows/usr/bin/gh gh workflow list --json name,state,path --repo owner/repo 64/bin/go GOINSECURE GOMOD GOMODCACHE erignore env -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)https://api.github.com/repos/owner/repo/contents/file.md/tmp/go-build3514322672/b383/cli.test /tmp/go-build3514322672/b383/cli.test -test.testlogfile=/tmp/go-build3514322672/b383/testlog.txt -test.paniconexit0 -test.v=true -test.parallel=4 -test.timeout=10m0s -test.run=^Test -test.short=true GOINSECURE GOMOD GOMODCACHE go k/gh�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD erignore go(http block)https://api.github.com/repos/test-owner/test-repo/actions/secrets/usr/bin/gh gh api /repos/test-owner/test-repo/actions/secrets --jq .secrets[].name GOSUMDB GOWORK 64/bin/go GOINSECURE GOMOD GOMODCACHE go m/_n�� -json GO111MODULE 64/bin/go GOINSECURE GOMOD GOMODCACHE go(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[testify-expert] Improve Test Quality: pkg/workflow/action_reference_test.go</issue_title>
<issue_description>The test file
pkg/workflow/action_reference_test.gohas been selected for quality improvement by the Testify Uber Super Expert. This issue provides specific, actionable recommendations to enhance test quality and maintainability using testify best practices.Current State
pkg/workflow/action_reference_test.gopkg/workflow/action_reference.goTestConvertToRemoteActionRef,TestResolveActionReference,TestCompilerActionTag,TestResolveSetupActionReference,TestResolveSetupActionReferenceWithData)"testing"Test Quality Analysis
Strengths ✅
t.Run()subtests — tests are logically grouped and clearly namedTestResolveActionReferenceandTestResolveSetupActionReferencealready use table-driven patternsAreas for Improvement 🎯
1. No Testify Assertions — Replace All Manual Comparisons
The entire file uses raw
if ref != expected { t.Errorf(...) }comparisons. Zero testify usage. This is the most impactful change.Current Issues (throughout the file):
Recommended Changes:
Add this import:
2. Convert
TestConvertToRemoteActionRefto Table-Driven TestTestConvertToRemoteActionRefuses many repetitivet.Runsubtests with the same pattern: construct a compiler, callconvertToRemoteActionRef, compare result. These should be a single table-driven test.Current Pattern (repeated 9 times):
Recommended Change: