Skip to content

test(utils): fix tests that assert nothing and run them in CI#1680

Open
ihopenre-eng wants to merge 1 commit into
dapr:masterfrom
ihopenre-eng:fix/utils-tests-and-ci-coverage
Open

test(utils): fix tests that assert nothing and run them in CI#1680
ihopenre-eng wants to merge 1 commit into
dapr:masterfrom
ihopenre-eng:fix/utils-tests-and-ci-coverage

Conversation

@ihopenre-eng

Copy link
Copy Markdown

Description

The utils package is not part of make test, which runs ./pkg/... only, so its tests never ran in CI. Three of them fail today on a clean master.

TestValidateFilePaths and TestReadFile create a temp fixture and remove it with defer while their subtests call t.Parallel(). A parallel subtest is paused until its parent function returns, so the deferred cleanup deletes the fixture before any subtest reads it, and the "valid file path" cases assert an error that only proves the file is already gone. They fail on Linux and Windows alike. Both move to t.Cleanup, which runs after parallel subtests finish, matching what TestFindFileInDir in the same file already does.

TestGetAbsPath fails on Windows only: /absolute/path carries no volume name, so filepath.IsAbs reports false for it and GetAbsPath joins it with baseDir. The absolute path is now chosen per platform.

./utils/... is added to the test target so these keep working.

Before:

$ go test ./utils/
--- FAIL: TestValidateFilePaths (0.00s)
    --- FAIL: TestValidateFilePaths/valid_file_path (0.00s)
--- FAIL: TestGetAbsPath (0.00s)
    --- FAIL: TestGetAbsPath/absolute_path (0.00s)
--- FAIL: TestReadFile (0.00s)
    --- FAIL: TestReadFile/valid_file_path (0.00s)
FAIL	github.com/dapr/cli/utils

After, on windows/amd64 and on linux/amd64 (cross-compiled test binary run under WSL):

$ go test ./utils/
ok  	github.com/dapr/cli/utils

$ ./utils.test
PASS

No production code is touched.

Issue reference

Please reference the issue this PR will close: #1679

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

The utils package is not part of `make test`, which runs `./pkg/...`
only, so its tests never ran in CI. Three of them fail today.

TestValidateFilePaths and TestReadFile create a temp fixture and remove
it with `defer` while their subtests call `t.Parallel()`. A parallel
subtest is paused until its parent returns, so the deferred cleanup
deletes the fixture before any subtest reads it, and the "valid file
path" cases assert an error that only proves the file is gone. This
fails on every platform:

    --- FAIL: TestValidateFilePaths (0.01s)
    --- FAIL: TestReadFile (0.00s)

Move both to t.Cleanup, which runs after parallel subtests finish, the
pattern TestFindFileInDir in this same file already uses.

TestGetAbsPath additionally fails on Windows: "/absolute/path" has no
volume name, so filepath.IsAbs reports false for it and GetAbsPath joins
it with baseDir. Pick the absolute path per platform.

Add ./utils/... to the test target so these stay honest.

Signed-off-by: ihopenre-eng <247072151+ihopenre-eng@users.noreply.github.com>
@ihopenre-eng
ihopenre-eng requested review from a team as code owners July 21, 2026 16:16
@ihopenre-eng

Copy link
Copy Markdown
Author

The CI workflows on this PR are queued at action_required and haven't started, so there are no check results to review yet. This is the first-time contributor approval gate for this repository.

Could a maintainer approve the workflow runs when convenient? Happy to rebase if anything has drifted in the meantime.

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.

utils package tests never run in CI, and three of them fail

1 participant