Emit less logs during unit test runs & remove spurious test defers#4948
Emit less logs during unit test runs & remove spurious test defers#4948hawkowl wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
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.gofiles withtestlog.LogForTesting(t)(and pass the resulting*logrus.Entryinto code under test). - Add a
forbidigorule to discouragelogrus.NewEntryconstruction 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.
|
Please rebase pull request. |
e91a95c to
9d5fe0d
Compare
|
Please rebase pull request. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…k was being instantiated pointlessly
38680f3 to
4ebd2ce
Compare
tuxerrante
left a comment
There was a problem hiding this comment.
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.
This PR: