Skip to content

Coverage does not work for Go tests #1104

@JoelSpeed

Description

@JoelSpeed

We've been trying to unify our tooling to use the Gingko cli to run all of our test suites as we are migrating towards it for as many of our tests as we can.

As part of this, we are expecting to be able to include cover profiles from the tests, even if there are some Go tests still to be run.

The issue is, if you include --cover --coverprofile=<something>, we get to the following line to start the go test:

suite = runGoTest(suite, cliConfig, goFlagsConfig)

Which then calls GenerateGoTestRunArgs:

args, err := types.GenerateGoTestRunArgs(goFlagsConfig)

Which for the Go test, will now return --test.coverprofile=<something>. Issue is, when running the Go test, Ginkgo runs it from the directory of the suite, so the coverprofile ends up in the test suite directory with the value of the Ginkgo coverprofile as its name.

Next up, is the clean up phase, FinalizeProfilesAndReportsForSuites which observes the suite and says, yep, this should have a coverprofile.

So it calculates the location of the file to pick the coverage up from:

coverProfiles = append(coverProfiles, AbsPathForGeneratedAsset(goFlagsConfig.CoverProfile, suite, cliConfig, 0))

Which is a combination of the suite package name and the output directory - which does not align with where the file actually is.

So I see two solutions:

  • Fix the finalize to detect a Go suite and pick the file up from the Go suite
  • Fix the Go test args to put the coverprofile in the location expected by the finalize

Have I followed this right? Any thoughts on a preferred direction?

An example of the error output:

ginkgo run failed
  could not finalize profiles:
  Unable to read coverage file /logs/artifacts/pkg_cloud_azure_actuators_machine_test-unit-coverage.out:
  open /logs/artifacts/pkg_cloud_azure_actuators_machine_test-unit-coverage.out: no such file or directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions