Skip to content

Emit less logs during unit test runs & remove spurious test defers#4948

Open
hawkowl wants to merge 9 commits into
masterfrom
hawkowl/less-logging-noise
Open

Emit less logs during unit test runs & remove spurious test defers#4948
hawkowl wants to merge 9 commits into
masterfrom
hawkowl/less-logging-noise

Conversation

@hawkowl

@hawkowl hawkowl commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

This PR:

  • Cleans up all the places where we write to stdout during unit test running. This significantly cleans up our unit test output and reduces a bunch of noise on successful tests.
  • Removes gomock.Controller.Finish() calls which aren't needed for recent Go, and removes where this was the only thing interacting with gomock

Copilot AI review requested due to automatic review settings July 2, 2026 04:42
@hawkowl hawkowl added the size-small Size small label Jul 2, 2026
@hawkowl hawkowl added go Pull requests that update Go code skippy pull requests raised by member of Team Skippy labels Jul 2, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces unit test noise by standardizing how tests construct loggers, preventing unintended writes to stdout during successful runs. It also adds a linter rule to enforce the new test logging pattern.

Changes:

  • Replace logrus.NewEntry(...) usage across many _test.go files with testlog.LogForTesting(t) (and pass the resulting *logrus.Entry into code under test).
  • Add a forbidigo rule to discourage logrus.NewEntry construction in tests.
  • Adjust a few tests/helpers to accept and propagate the test logger rather than creating new loggers internally.

Reviewed changes

Copilot reviewed 103 out of 103 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
pkg/validate/dynamic/serviceprincipal_test.go Use testlog.LogForTesting logger in tests
pkg/validate/dynamic/platformworkloadidentityprofile_test.go Use testlog.LogForTesting logger in tests
pkg/validate/dynamic/loadbalancerprofile_test.go Use testlog.LogForTesting logger in tests
pkg/validate/dynamic/dynamic_test.go Use testlog.LogForTesting logger in tests
pkg/validate/dynamic/diskencryptionset_test.go Use testlog.LogForTesting logger in tests
pkg/util/purge/serviceprincipals_test.go Use testlog.LogForTesting logger in tests
pkg/util/dynamichelper/dynamichelper_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterdata/worker_profile_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterdata/service_principal_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterdata/ingress_profile_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterdata/clusterdata_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterdata/cluster_version_test.go Use testlog.LogForTesting logger in tests
pkg/util/clusterauthorizer/authorizer_test.go Use testlog.LogForTesting logger in tests
pkg/util/cluster/workloadidentity_test.go Use testlog.LogForTesting logger in tests
pkg/util/clienthelper/clienthelper_test.go Use testlog.LogForTesting logger in tests
pkg/util/clientauthorizer/subject_name_and_issuer_test.go Use testlog.LogForTesting logger in tests
pkg/util/billing/billing_test.go Use testlog.LogForTesting logger in tests
pkg/util/azureclient/azuresdk/azcertificates/helpers_test.go Use testlog.LogForTesting logger in tests
pkg/util/arm/deploy_test.go Use testlog.LogForTesting logger in tests
pkg/portal/ssh/ssh_test.go Use testlog.LogForTesting logger in tests
pkg/portal/security_test.go Use testlog.LogForTesting logger in tests
pkg/portal/prometheus/proxy_test.go Use testlog.LogForTesting logger in tests
pkg/operator/deploy/deploy_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/subnets/subnet_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/storageaccounts/storageaccounts_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/pullsecret/pullsecret_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/node/node_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/muo/muo_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/monitoring/monitoring_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/machineset/machineset_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/machinehealthcheck/machinehealthcheck_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/machine/machine_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/ingress/ingress_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/imageconfig/image_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/guardrails/guardrails_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/etchosts/machineconfig_controller_test.go Use testlog.LogForTesting logger/hook in tests
pkg/operator/controllers/etchosts/cluster_controller_test.go Use testlog.LogForTesting logger/hook in tests
pkg/operator/controllers/dnsmasq/machineconfigpool_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/dnsmasq/machineconfig_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/dnsmasq/cluster_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/cpms/cpms_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/clusteroperatoraro/clusteroperatoraro_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/cloudproviderconfig/cloudproviderconfig_controller_test.go Use testlog.LogForTesting logger/hook in tests
pkg/operator/controllers/checkers/serviceprincipalchecker/checker_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/base/aro_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/autosizednodes/autosizednodes_controller_test.go Use testlog.LogForTesting logger in tests
pkg/operator/controllers/alertwebhook/alertwebhook_controller_test.go Use testlog.LogForTesting logger in tests
pkg/monitor/test_helpers.go Use testlog.LogForTesting in shared test setup
pkg/monitor/hive/hiveregistrationstatus_test.go Use testlog.LogForTesting logger/hook in tests
pkg/monitor/hive/clustersync_test.go Use testlog.LogForTesting logger/hook in tests
pkg/monitor/cluster/clusterwideproxystatus_test.go Use testlog.LogForTesting logger in tests
pkg/monitor/cluster/clusterauthenticationtype_test.go Use testlog.LogForTesting logger in tests
pkg/monitor/azure/nsg/rulechecker_test.go Use testlog.LogForTesting logger in tests
pkg/monitor/azure/nsg/nsg_test.go Use testlog.LogForTesting logger in tests
pkg/mirror/acrauth_test.go Use testlog.LogForTesting logger in tests
pkg/mimo/actuator/service_test.go Use testlog.LogForTesting logger in ginkgo tests
pkg/metrics/statsd/cosmosdb/metrics_test.go Use testlog.LogForTesting logger in tests
pkg/hive/manager_test.go Use testlog.LogForTesting logger in tests
pkg/gateway/gateway_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/validate_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/shared_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/security_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/frontend_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/common_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/adminactions/vmserialconsole_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/adminactions/resources_list_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/adminactions/reconcilefailednic_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/adminactions/kubeactions_exec_test.go Thread test logger through exec helpers
pkg/frontend/adminactions/delete_managedresource_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/admin_openshiftcluster_vmresize_pre_validation_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/admin_openshiftcluster_serialconsole_test.go Use testlog.LogForTesting logger in request context
pkg/frontend/admin_openshiftcluster_runjob_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/admin_openshiftcluster_investigate_test.go Use testlog.LogForTesting logger in request context
pkg/frontend/admin_openshiftcluster_exec_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/admin_openshiftcluster_etcdcertificaterenew_test.go Use testlog.LogForTesting logger in tests
pkg/frontend/admin_hive_k8s_objects_list_test.go Use testlog.LogForTesting logger in request context
pkg/env/certificateRefresher_test.go Use testlog.LogForTesting logger in tests
pkg/deploy/vmsscleaner/clean_test.go Use testlog.LogForTesting logger in tests
pkg/deploy/predeploy_test.go Use testlog.LogForTesting logger in tests
pkg/deploy/deploy_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/workloadidentityresources_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/start_vms_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/platformworkloadidentities_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/loadbalancerprofile_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/ipaddresses_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/hive_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/graph/manager_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/fixssh_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/fixmcscert_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/fixinfraid_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/deploybaseresources_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/deploybaseresources_additional_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/denyassignment_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/delete_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/consolebranding_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/condition_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/clusterserviceprincipal_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/clustermsi_test.go Use testlog.LogForTesting logger in tests
pkg/cluster/arooperator_test.go Use testlog.LogForTesting logger in tests
pkg/backend/openshiftcluster_test.go Use testlog.LogForTesting logger in tests
pkg/backend/metrics_test.go Use testlog.LogForTesting logger in tests
hack/clean/clean_test.go Use testlog.LogForTesting logger in tests
.golangci.yml Enable forbidigo rule to discourage logrus.NewEntry in tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .golangci.yml Outdated
Comment thread pkg/util/clusterauthorizer/authorizer_test.go
Comment thread pkg/cluster/fixmcscert_test.go Outdated
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Please rebase pull request.

@github-actions github-actions Bot added needs-rebase branch needs a rebase and removed ready-for-review labels Jul 3, 2026
Copilot AI review requested due to automatic review settings July 3, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 103 out of 103 changed files in this pull request and generated 5 comments.

Comment thread pkg/cluster/fixmcscert_test.go Outdated
Comment thread pkg/hive/manager_test.go
Comment thread pkg/hive/manager_test.go
Comment thread pkg/deploy/vmsscleaner/clean_test.go
Comment thread pkg/cluster/deploybaseresources_test.go
@hawkowl hawkowl force-pushed the hawkowl/less-logging-noise branch from e91a95c to 9d5fe0d Compare July 3, 2026 04:09
@github-actions github-actions Bot removed the needs-rebase branch needs a rebase label Jul 3, 2026
Copilot AI review requested due to automatic review settings July 3, 2026 04:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 160 out of 161 changed files in this pull request and generated 1 comment.

Comment thread pkg/mimo/actuator/service_test.go
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Please rebase pull request.

@github-actions github-actions Bot added the needs-rebase branch needs a rebase label Jul 7, 2026
Copilot AI review requested due to automatic review settings July 8, 2026 06:13
@hawkowl hawkowl force-pushed the hawkowl/less-logging-noise branch from 38680f3 to 4ebd2ce Compare July 8, 2026 06:13
@github-actions github-actions Bot removed the needs-rebase branch needs a rebase label Jul 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 160 out of 161 changed files in this pull request and generated 1 comment.

Comment thread .golangci.yml
@hawkowl hawkowl changed the title Emit less logs during unit test runs Emit less logs during unit test runs & remove spurious test defers Jul 9, 2026

@tuxerrante tuxerrante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a nice cleanup overall. The test logging changes look good, and the Linux validation signal is clean on my side.

I do have one thing I’d ask to change before merge: the new forbidigo ban on gomock.Controller.Finish() in .golangci.yml is too broad. The “not needed since Go 1.14” guidance is only safe when the controller is created with gomock.NewController(t). We still have suites that use gomock.NewController(nil), where an explicit Finish() can still be what enforces mock expectations.

As written, this turns a specific cleanup into a repo-wide rule that is stronger than the actual guarantee. I’d suggest either:

  • narrowing the rule/message to the gomock.NewController(t) case, or
  • deferring that part until the remaining NewController(nil) suites are migrated.

If that part is adjusted, the rest of the PR looks good to me.

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

Labels

go Pull requests that update Go code ready-for-review size-small Size small skippy pull requests raised by member of Team Skippy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants