Skip to content

Add comprehensive test coverage for controller and API types#348

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/add-test-coverage
Draft

Add comprehensive test coverage for controller and API types#348
Copilot wants to merge 6 commits intomainfrom
copilot/add-test-coverage

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

Coverage increased from 64.6% to 89.9% by adding unit tests for previously untested code paths in the migration controller and utility functions.

Coverage improvements

Controller (internal/controller): 64.6% → 89.9%

  • Reconcile(): 36.1% → 86.1%
  • jobIsCurrent(): 0% → 100%
  • isJobFinished(): 0% → 100%
  • hasFailed(): 0% → 100%
  • hasSucceeded(): 0% → 100%
  • getFlywayArgs(): 83.3% → 100%
  • IsValid(): 75% → 100%
  • getExistingJob(): 80% → 100%

API types (api/v1alpha1): 100% for all non-generated methods

Changes

New test file: api/v1alpha1/migration_types_test.go

Tests for all API type methods: IsPaused(), GenerationAsString(), GetConditions(), SetConditions(), GetCredentials(), GetPlaceholdersAsEnvVars()

Enhanced: internal/controller/jobutil_test.go

Added tests for job state checking functions and environment-based configuration:

  • Job currency checking against migration generation
  • Job completion state detection (complete, failed, running)
  • Flyway image selection with environment variables
  • JDBC properties argument formatting with validation of all properties

Enhanced: internal/controller/migration_controller_test.go

Added tests for reconciliation scenarios:

  • Migration not found, paused, being deleted
  • Existing jobs: running, succeeded (current/outdated), failed
  • Invalid migration type validation

Example test coverage for reconciliation branches:

func TestMigrationReconcile_WithOutdatedJob(t *testing.T) {
    migration := &flywayv1alpha1.Migration{
        ObjectMeta: metav1.ObjectMeta{Generation: 5},
        // ... spec
    }
    
    outdatedJob := &batchv1.Job{
        ObjectMeta: metav1.ObjectMeta{
            Annotations: map[string]string{
                flywayv1alpha1.Generation: "3", // Old generation
            },
        },
        Status: batchv1.JobStatus{Succeeded: 1},
    }
    // Validates new job is submitted when generation changes
}

All tests follow existing patterns using standard Go testing framework and fake clients.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add test-coverage</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
Should have better test-coverage, use the codecov measurements to see what is missing

Describe the solution you'd like
Add to the test-suite, follow the existing pattern and add what is missing to cover more execution branches.

Describe alternatives you've considered
Write it myself

Additional context
It is the main functionality and errorhandling which matters. You might need to add integration-test tooling to have a proper api-server to run against. Use the tooling from kubebuilder for this.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 12, 2026 02:11
Co-authored-by: davidkarlsen <18299+davidkarlsen@users.noreply.github.com>
Co-authored-by: davidkarlsen <18299+davidkarlsen@users.noreply.github.com>
Co-authored-by: davidkarlsen <18299+davidkarlsen@users.noreply.github.com>
Co-authored-by: davidkarlsen <18299+davidkarlsen@users.noreply.github.com>
Co-authored-by: davidkarlsen <18299+davidkarlsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add test coverage for existing functionality Add comprehensive test coverage for controller and API types Feb 12, 2026
Copilot AI requested a review from davidkarlsen February 12, 2026 02:22
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.

Add test-coverage

2 participants