Skip to content

Conversation

@lsierant
Copy link
Contributor

@lsierant lsierant commented Jul 23, 2025

Summary

This PR simplifies unit tests execution to allow a simple go test ./... to always correctly execute all golang unit tests without running community e2e tests.
Additionally we use gotestsum wrapper by default to better present test output in the command line.

Changes

  • There is only one, unified go.mod in the repo now, so running go test ./... correctly identifies all go files. The last one from init-ops-manager was removed in this PR, and another one from kubectl plugin was removed recently in [CLOUDP-332196] Move kubectl-mongodb plugin to cmd dir for atomic releases #271.
  • All community e2e tests were marked with community_e2e tag, so we don't need to run tests with a filtered package list anymore.
  • gotestsum test runner is used to execute unit tests giving more readable output
  • gotestsum has been added as a tool in go.mod by running go get -tool gotest.tools/gotestsum@latest.
    • While using go.mod's tool directive allows for easy tool access (by go tool <tool>) and is not resulting in adding dependencies into the operators binary, it is still cluttering dependency list (in require section). We might consider removing it from go mod and installing it as a separate step.
  • All test (python and golang) are reporting results as xml and are all gathered by evg. Test output is gathered in the teardown_task section now.
  • Enabled back golang race tests - those were mistakenly disabled during operator merge to MCK (diff unit-tests.sh)

How to run tests now

Essentially as before:

$ make golang-tests

or

$ make test

Difference: we don't run with coverage enabled by default, thus allowing to use test caching for faster repeated runs from cli.

In order to run all unit tests without cache and with coverage run:

$ make golang-tests-race

We is use gotestsum as:

go tool gotestsum --junitfile golang-unit-result.xml --format-icons hivis -- -v ./...

But thanks to the overall go.mod/unitest simplifications you can use whatever suits you:

  1. Use gotestsum
$ go tool gotestsum
  1. Use plain go test
$ go test ./...
  1. Use other test runner/viewers. I recommend to look into gotestsum options as well..

  2. Also there is tparse which also has very nice summary table:

go get -tool github.com/mfridman/tparse@latest
go test -v ./... -json | go tool tparse

tparse is not supporting xunit output thus it's not used here as a default.

Proof of Work

Golang unit tests with remove locks to trigger race test error: link
Python unit test with injected error: evg link

Passing tests: evg link

@lsierant lsierant self-assigned this Jul 23, 2025
@lsierant lsierant changed the title tparse Refactor unit test execution Jul 23, 2025
@lsierant lsierant changed the title Refactor unit test execution CLOUDP-332943: Refactor unit test execution Jul 23, 2025
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch 3 times, most recently from f3cd1b8 to 80c4de1 Compare July 29, 2025 11:38
@github-actions
Copy link

github-actions bot commented Jul 29, 2025

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.6.1 Release Notes

Bug Fixes

  • Backed up the agent password in a secret for SCRAM authentication to prevent unnecessary password rotations.
  • MongoDB Adding missing ownerrefs to ensure proper resource deletion by kubernetes.
  • Single Cluster Deleting resources created by CRD now only happens on multi-cluster deployments. Single Cluster will solely rely on ownerrefs.
  • MongoDB, MongoDBOpsManager: Improve validation for featureCompatibilityVersion field in MongoDB and MongoDBOpsManager spec.
    The field now enforces proper semantic versioning. Previously, invalid semver values could be accepted,
    potentially resulting in incorrect configurations.
  • Roles configured via Ops Manager UI or API will no longer be removed by the operator

Other Changes

  • Future releases will include a new asset, release_info_.json, which provides detailed information about each MongoDB Controllers for Kubernetes release, including a clear list of all container images. This will help customers, especially those running in air-gapped environments, easily identify all required images for a given release.
  • Operator configuration: Removed the unused MDB_IMAGE_TYPE environment variable and the corresponding mongodb.imageType Helm value. This variable was deprecated in v1.28.0 of the MongoDB Enterprise Kubernetes Operator when it switched to architecture-based image selection (ubi9 for static, ubi8 for non-static). This is a cleanup change with no functional impact.

@lsierant lsierant force-pushed the lsierant/unit-test-parse branch from d3f907a to f4e132b Compare August 23, 2025 21:20
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch 2 times, most recently from bf880c6 to 24e9157 Compare September 22, 2025 10:34
@lsierant lsierant added the skip-changelog Use this label in Pull Request to not require new changelog entry file label Sep 22, 2025
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch 2 times, most recently from d95212e to 481f562 Compare September 25, 2025 07:37
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch from 481f562 to 23c4209 Compare October 1, 2025 09:08
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch 2 times, most recently from 71839e7 to b051325 Compare December 3, 2025 10:19
@lsierant lsierant force-pushed the lsierant/unit-test-parse branch from 89163da to 75962dc Compare December 12, 2025 12:48
@lsierant lsierant marked this pull request as ready for review December 12, 2025 12:52
@lsierant lsierant requested a review from a team as a code owner December 12, 2025 12:52
func init() {
logger, _ := zap.NewDevelopment()
zap.ReplaceGlobals(logger)
os.Clearenv() // nolint:forbidigo
Copy link
Contributor Author

@lsierant lsierant Dec 12, 2025

Choose a reason for hiding this comment

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

this (and similar additions in other pkgs) is allowing for consistent exec of tests that runs reconcile code across all contexts. The biggest offender was static architecture env which caused different reconcile behavior if tests were executed with different contexts.
Unit tests should never rely on env vars set outside. If those are needed then should be specified in the test itself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

but in theory - the proper way is to fix all those tests which are using global env to t.setEnv() instead, right?
Have you considered doing this instead? Or is that too much of a change?

}

check_backup_daemon_alive
check_backup_daemon_alive
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
check_backup_daemon_alive
check_backup_daemon_alive

pkg/client/
docker/mongodb-kubernetes-tests
scripts/
# scripts/
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just remove this, or commenting it ok?

pkg/client/
docker/mongodb-kubernetes-tests
scripts/
# scripts/
Copy link
Collaborator

Choose a reason for hiding this comment

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

q: on purpose?

func init() {
logger, _ := zap.NewDevelopment()
zap.ReplaceGlobals(logger)
os.Clearenv() // nolint:forbidigo
Copy link
Collaborator

Choose a reason for hiding this comment

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

but in theory - the proper way is to fix all those tests which are using global env to t.setEnv() instead, right?
Have you considered doing this instead? Or is that too much of a change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants