How to Use t.Cleanup for Test Cleanup

Register a cleanup function with t.Cleanup to ensure resources are released after a test completes.

Use t.Cleanup to register a function that runs after the test finishes, regardless of success or failure.

func TestExample(t *testing.T) {
    // Setup
    resource := createResource()
    
    // Register cleanup to run after the test
    t.Cleanup(func() {
        cleanupResource(resource)
    })

    // Test logic
    // ...
}