Skip to content

PO to GMP Migration Tool: Unit Test Cleanup - #2059

Closed
karthunni wants to merge 1 commit into
mainfrom
karthunni/po-migrate-test-cleanup
Closed

PO to GMP Migration Tool: Unit Test Cleanup#2059
karthunni wants to merge 1 commit into
mainfrom
karthunni/po-migrate-test-cleanup

Conversation

@karthunni

Copy link
Copy Markdown
Collaborator

This PR refactors the unit test suite across pkg/migrate to adhere strictly to table-driven testing standards, consolidating overlapping test suites and removing duplicate assertions.

Key Consolidations & Changes

  • Secret & ConfigMap Key Extraction: Consolidated TestExtractSecretKey and TestExtractConfigMapKey into a single, unified TestExtractResourceKey table test.
  • ConfigMap-to-Secret & Namespace Decoupling: Merged TestConvertConfigMapToSecretSelectorDeduplication and TestDecoupledNamespaces into TestExtractResourceKey and TestMergeFromPod table cases.
  • Cluster vs Namespaced PodMonitor Redundancy: Removed redundant ClusterPodMonitoring test cases in podmonitor_test.go that duplicated convertMonitorSpec assertions already verified in namespaced test cases.
  • Static Target Labels Cleanup: Removed duplicate TestConvertStaticTargetLabels from servicemonitor_test.go (covered by helpers_test.go).
  • End-to-End Pipeline Tests: Refactored migrate_test.go pipeline tests (Migrator.Run, directory scanning, error reporting) into table-driven cases.

@karthunni karthunni self-assigned this Aug 6, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors and consolidates several test suites in the pkg/migrate package into table-driven tests, specifically in helpers_test.go and migrate_test.go. While the refactoring simplifies the test structure, the review feedback highlights several regressions in test coverage due to the removal of critical test cases, including corrupted secret data handling, ConfigMap-to-Secret deduplication, cluster-scoped ClusterPodMonitoring logic, and static target label conversion. Additionally, the reviewer notes that errors from os.WriteFile are ignored in the refactored tests and should be properly handled.

}

func TestExtractSecretKey(t *testing.T) {
func TestExtractResourceKey(t *testing.T) {

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.

medium

This refactoring removed the test case Secret exists but data corrupted from the old TestExtractSecretKey function. This test case was valuable as it verified the error handling for malformed base64 data within a Secret, which is an important edge case. Its removal reduces test coverage. Please consider re-adding this test case to the new TestExtractResourceKey table.

References
  1. When a resource converter or migration tool encounters an invalid, empty, or broken configuration that prevents successful conversion, it should return an explicit error rather than silently skipping the resource or returning an empty result.

}
}

func TestConvertConfigMapToSecretSelectorDeduplication(t *testing.T) {

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.

medium

The removed test TestConvertConfigMapToSecretSelectorDeduplication verified an important behavior: that multiple calls to convertConfigMapToSecretSelector for the same ConfigMap would result in only one Secret being generated (deduplication). The new table-driven tests for TestConvertConfigMapToSecretSelector run in isolation and do not cover this scenario. This is a regression in test coverage. Please add a new test case that verifies this deduplication logic.

References
  1. Keep the input resource cache separate from generated output resources. Use an output map at the migrator level to detect collisions and handle deduplication of generated resources (such as generated Secrets).

Comment on lines +171 to +172
_ = os.WriteFile(p1, []byte(svcYAML), 0644)
_ = os.WriteFile(p2, []byte(pmYAML), 0644)

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.

medium

The errors returned by os.WriteFile are being ignored here. While this is in a test, it's best practice to handle these errors. If writing the test files fails, the test will fail later with a less clear message. Please check the errors and fail the test immediately using t.Fatalf for better test reliability and clearer failure reporting, as is done in other test cases in this file.

if err := os.WriteFile(p1, []byte(svcYAML), 0644); err != nil {
	t.Fatalf("failed to write service file: %v", err)
}
if err := os.WriteFile(p2, []byte(pmYAML), 0644); err != nil {
	t.Fatalf("failed to write podmonitor file: %v", err)
}

},
},
{
name: "Scope-aware Metadata: namespace metadata mapping dropped in namespaced PodMonitoring",

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.

medium

This PR removes several test cases for ClusterPodMonitoring, stating they are redundant with the namespaced PodMonitoring tests. However, some helper functions like resolveMetadata and resolveAttachMetadata have distinct logic paths for cluster-scoped resources (when isCluster is true). Removing all tests for ClusterPodMonitoring leaves these specific paths untested, which is a regression. Please consider re-instating at least one key test case for ClusterPodMonitoring to ensure the cluster-scoped logic is still covered, for example, a test that verifies namespace metadata handling.

return addServiceWithSelectorToCache(cache, namespace, name, labels, selector, ports)
}

// TestConvertStaticTargetLabels tests that label keys are sanitized and protected labels are renamed to exported_<label>.

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.

medium

The test TestConvertStaticTargetLabels has been removed. The PR description mentions it's covered in helpers_test.go, but a replacement test doesn't seem to exist there. This unit test was valuable as it directly tested the convertStaticTargetLabels helper function, including important edge cases like label sanitization and collisions. The integration-style tests in TestServiceMonitorConverter_Convert may not cover all these specific scenarios. Please consider re-adding this unit test to prevent regressions.

Base automatically changed from karthunni/po-migrate-servicemonitor-spec to main August 7, 2026 14:52
@karthunni
karthunni force-pushed the karthunni/po-migrate-test-cleanup branch from a9b5efb to 0ca8b33 Compare August 7, 2026 14:52
@karthunni karthunni closed this Aug 7, 2026
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.

1 participant