Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NE-1187: Use t.Run for table-driven tests #884

Merged
merged 1 commit into from Jul 24, 2023

Conversation

gcs278
Copy link
Contributor

@gcs278 gcs278 commented Jan 27, 2023

Use t.Run to run test cases for table-driven unit tests, for consistency.

  • pkg/operator/controller/canary/controller_test.go (Test_cycleServicePort):
  • pkg/operator/controller/canary/daemonset_test.go (Test_canaryDaemonsetChanged):
  • pkg/operator/controller/canary/namespace_test.go (Test_canaryNamespaceChanged):
  • pkg/operator/controller/canary/route_test.go (Test_canaryRouteChanged):
  • pkg/operator/controller/certificate/default_cert_test.go (Test_desiredRouterDefaultCertificateSecret):
  • pkg/operator/controller/dns/controller_test.go (Test_publishRecordToZones, TestPublishRecordToZonesMergesStatus) (Test_migrateRecordStatusConditions, Test_dnsZoneStatusSlicesEqual) (Test_recordIsAlreadyPublishedToZone):
  • pkg/operator/controller/ingress/controller_test.go (Test_tlsProfileSpecForSecurityProfile)
    (Test_tlsProfileSpecForIngressController)
    (Test_validateHTTPHeaderBufferValues, Test_validateClientTLS) (Test_IsProxyProtocolNeeded):
  • pkg/operator/controller/ingress/deployment_test.go (Test_inferTLSProfileSpecFromDeployment, TestDeploymentHash) (Test_deploymentConfigChanged):
  • pkg/operator/controller/ingress/dns_test.go (Test_desiredWildcardDNSRecord, Test_manageDNSForDomain):
  • pkg/operator/controller/ingress/load_balancer_service_test.go (Test_desiredLoadBalancerService, Test_shouldUseLocalWithFallback) (Test_isServiceOwnedByIngressController):
  • pkg/operator/controller/ingress/namespace_test.go (Test_routerNamespaceChanged):
  • pkg/operator/controller/ingress/nodeport_service_test.go (Test_nodePortServiceChanged):
  • pkg/operator/controller/ingress/poddisruptionbudget_test.go (Test_desiredRouterPodDisruptionBudget):
  • pkg/operator/controller/ingress/status_test.go (Test_computeDeploymentPodsScheduledCondition)
    (Test_computeIngressDegradedCondition)
    (Test_computeDeploymentRollingOutCondition)
    (Test_computeLoadBalancerProgressingStatus)
    (Test_computeDeploymentAvailableCondition)
    (Test_computeDeploymentReplicasMinAvailableCondition) (Test_computeDeploymentReplicasAllAvailableCondition) (Test_computeLoadBalancerStatus, Test_computeIngressProgressingCondition) (Test_computeIngressAvailableCondition, Test_ingressStatusesEqual) (Test_computeDNSStatus, Test_MergeConditions)
    (Test_computeAllowedSourceRanges):
  • pkg/operator/controller/ingressclass/ingressclass_test.go (Test_ingressClassChanged):
  • pkg/operator/controller/status/controller_test.go (Test_computeOperatorProgressingCondition, Test_operatorStatusesEqual) (Test_computeOperatorStatusVersions)
    (Test_computeOperatorUpgradeableCondition)
    (Test_computeOperatorEvaluationConditionsDetectedCondition):
  • pkg/operator/controller/sync-http-error-code-configmap/controller_test.go (Test_desiredHttpErrorCodeConfigMap):
  • pkg/util/network_test.go (Test_URI):
  • pkg/util/retryableerror/retryableerror_test.go (TestRetryableError): Use t.Run.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 27, 2023
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Jan 27, 2023

@gcs278: This pull request references NE-1187 which is a valid jira issue.

In response to this:

Use t.Run to run test cases for table-driven unit tests, for consistency.

  • pkg/operator/controller/canary/controller_test.go (Test_cycleServicePort):
  • pkg/operator/controller/canary/daemonset_test.go (Test_canaryDaemonsetChanged):
  • pkg/operator/controller/canary/namespace_test.go (Test_canaryNamespaceChanged):
  • pkg/operator/controller/canary/route_test.go (Test_canaryRouteChanged):
  • pkg/operator/controller/certificate/default_cert_test.go (Test_desiredRouterDefaultCertificateSecret):
  • pkg/operator/controller/dns/controller_test.go (Test_publishRecordToZones, TestPublishRecordToZonesMergesStatus) (Test_migrateRecordStatusConditions, Test_dnsZoneStatusSlicesEqual) (Test_recordIsAlreadyPublishedToZone):
  • pkg/operator/controller/ingress/controller_test.go (Test_tlsProfileSpecForSecurityProfile)
    (Test_tlsProfileSpecForIngressController)
    (Test_validateHTTPHeaderBufferValues, Test_validateClientTLS) (Test_IsProxyProtocolNeeded):
  • pkg/operator/controller/ingress/deployment_test.go (Test_inferTLSProfileSpecFromDeployment, TestDeploymentHash) (Test_deploymentConfigChanged):
  • pkg/operator/controller/ingress/dns_test.go (Test_desiredWildcardDNSRecord, Test_manageDNSForDomain):
  • pkg/operator/controller/ingress/load_balancer_service_test.go (Test_desiredLoadBalancerService, Test_shouldUseLocalWithFallback) (Test_isServiceOwnedByIngressController):
  • pkg/operator/controller/ingress/namespace_test.go (Test_routerNamespaceChanged):
  • pkg/operator/controller/ingress/nodeport_service_test.go (Test_nodePortServiceChanged):
  • pkg/operator/controller/ingress/poddisruptionbudget_test.go (Test_desiredRouterPodDisruptionBudget):
  • pkg/operator/controller/ingress/status_test.go (Test_computeDeploymentPodsScheduledCondition)
    (Test_computeIngressDegradedCondition)
    (Test_computeDeploymentRollingOutCondition)
    (Test_computeLoadBalancerProgressingStatus)
    (Test_computeDeploymentAvailableCondition)
    (Test_computeDeploymentReplicasMinAvailableCondition) (Test_computeDeploymentReplicasAllAvailableCondition) (Test_computeLoadBalancerStatus, Test_computeIngressProgressingCondition) (Test_computeIngressAvailableCondition, Test_ingressStatusesEqual) (Test_computeDNSStatus, Test_MergeConditions)
    (Test_computeAllowedSourceRanges):
  • pkg/operator/controller/ingressclass/ingressclass_test.go (Test_ingressClassChanged):
  • pkg/operator/controller/status/controller_test.go (Test_computeOperatorProgressingCondition, Test_operatorStatusesEqual) (Test_computeOperatorStatusVersions)
    (Test_computeOperatorUpgradeableCondition)
    (Test_computeOperatorEvaluationConditionsDetectedCondition):
  • pkg/operator/controller/sync-http-error-code-configmap/controller_test.go (Test_desiredHttpErrorCodeConfigMap):
  • pkg/util/network_test.go (Test_URI):
  • pkg/util/retryableerror/retryableerror_test.go (TestRetryableError): Use t.Run.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@gcs278
Copy link
Contributor Author

gcs278 commented Jan 30, 2023

/retest-required

1 similar comment
@gcs278
Copy link
Contributor Author

gcs278 commented Jan 31, 2023

/retest-required

@gcs278 gcs278 force-pushed the NE-1187 branch 2 times, most recently from 54d2b8b to cd113e6 Compare April 6, 2023 18:03
tlsProfileSpec := tlsProfileSpecForSecurityProfile(ic.Spec.TLSSecurityProfile)
err := validateTLSSecurityProfile(ic)
if tc.valid && err != nil {
t.Fatalf("unexpected error: %v\nprofile:\n%s", err, util.ToYaml(tlsProfileSpec))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this update after reviewing ,original commit was missing removal of tc.description.

mutated := original.DeepCopy()
tc.mutate(mutated)
if changed, updated := deploymentConfigChanged(&original, mutated); changed != tc.expect {
t.Errorf("expect deploymentConfigChanged to be %t, got %t", tc.expect, changed)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this after code review

@@ -2293,11 +2315,11 @@ func TestComputeIngressUpgradeableCondition(t *testing.T) {
}
wantSvc, service, err := desiredLoadBalancerService(ic, deploymentRef, platformStatus)
if err != nil {
t.Errorf("%q: unexpected error from desiredLoadBalancerService: %v", tc.description, err)
t.Errorf("unexpected error from desiredLoadBalancerService: %v", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this also after reviewing

@@ -2315,7 +2337,7 @@ func TestComputeIngressUpgradeableCondition(t *testing.T) {

actual := computeIngressUpgradeableCondition(ic, deploymentRef, service, platformStatus, secret)
if actual.Status != expectedStatus {
t.Errorf("%q: expected Upgradeable to be %q, got %q", tc.description, expectedStatus, actual.Status)
t.Errorf("expected Upgradeable to be %q, got %q", expectedStatus, actual.Status)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also updated this after reviewing

@gcs278
Copy link
Contributor Author

gcs278 commented Apr 12, 2023

/retest-required

@candita
Copy link
Contributor

candita commented Jun 28, 2023

Merge late in release cycle to avoid backport issues, revisit 7/5

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2023
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2023
@gcs278
Copy link
Contributor Author

gcs278 commented Jul 5, 2023

must gather failure
/test e2e-aws-operator

TestUnmanagedDNSToManagedDNSInternalIngressController failure, but it is the same failure as https://issues.redhat.com/browse/OCPBUGS-13106
/test e2e-gcp-operator

@gcs278
Copy link
Contributor Author

gcs278 commented Jul 5, 2023

/hold
Waiting until the end of the release to check this in.

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 5, 2023
@candita
Copy link
Contributor

candita commented Jul 5, 2023

/assign @rfredette

Comment on lines 75 to 90
wantPDB, pdb, err := desiredRouterPodDisruptionBudget(ic, deploymentRef)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !wantPDB {
if tc.expectPDB {
t.Error("expected true, got false")
}
} else if pdb == nil {
t.Error("expected pointer, got nil")
} else if pdb.Spec.MaxUnavailable == nil {
t.Errorf("expected PDB with non-nil MaxUnavailable, got %#v", pdb)
} else if *pdb.Spec.MaxUnavailable != tc.expectMaxUnavailable {
t.Errorf("expected %#v, got %#v", tc.expectMaxUnavailable, pdb.Spec.MaxUnavailable)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe convert this to switch/case like you've done elsewhere in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rfredette
Copy link
Contributor

One nit, otherwise this looks good.
/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 5, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rfredette

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 5, 2023
Use t.Run to run test cases for table-driven unit tests, for consistency.

* pkg/operator/controller/canary/controller_test.go
(Test_cycleServicePort):
* pkg/operator/controller/canary/daemonset_test.go
(Test_canaryDaemonsetChanged):
* pkg/operator/controller/canary/namespace_test.go
(Test_canaryNamespaceChanged):
* pkg/operator/controller/canary/route_test.go (Test_canaryRouteChanged):
* pkg/operator/controller/certificate/default_cert_test.go
(Test_desiredRouterDefaultCertificateSecret):
* pkg/operator/controller/dns/controller_test.go
(Test_publishRecordToZones, TestPublishRecordToZonesMergesStatus)
(Test_migrateRecordStatusConditions, Test_dnsZoneStatusSlicesEqual)
(Test_recordIsAlreadyPublishedToZone):
* pkg/operator/controller/ingress/controller_test.go
(Test_tlsProfileSpecForSecurityProfile)
(Test_tlsProfileSpecForIngressController)
(Test_validateHTTPHeaderBufferValues, Test_validateClientTLS)
(Test_IsProxyProtocolNeeded):
* pkg/operator/controller/ingress/deployment_test.go
(Test_inferTLSProfileSpecFromDeployment, TestDeploymentHash)
(Test_deploymentConfigChanged):
* pkg/operator/controller/ingress/dns_test.go
(Test_desiredWildcardDNSRecord, Test_manageDNSForDomain):
* pkg/operator/controller/ingress/load_balancer_service_test.go
(Test_desiredLoadBalancerService, Test_shouldUseLocalWithFallback)
(Test_isServiceOwnedByIngressController):
* pkg/operator/controller/ingress/namespace_test.go
(Test_routerNamespaceChanged):
* pkg/operator/controller/ingress/nodeport_service_test.go
(Test_nodePortServiceChanged):
* pkg/operator/controller/ingress/poddisruptionbudget_test.go
(Test_desiredRouterPodDisruptionBudget):
* pkg/operator/controller/ingress/status_test.go
(Test_computeDeploymentPodsScheduledCondition)
(Test_computeIngressDegradedCondition)
(Test_computeDeploymentRollingOutCondition)
(Test_computeLoadBalancerProgressingStatus)
(Test_computeDeploymentAvailableCondition)
(Test_computeDeploymentReplicasMinAvailableCondition)
(Test_computeDeploymentReplicasAllAvailableCondition)
(Test_computeLoadBalancerStatus, Test_computeIngressProgressingCondition)
(Test_computeIngressAvailableCondition, Test_ingressStatusesEqual)
(Test_computeDNSStatus, Test_MergeConditions)
(Test_computeAllowedSourceRanges):
* pkg/operator/controller/ingressclass/ingressclass_test.go
(Test_ingressClassChanged):
* pkg/operator/controller/status/controller_test.go
(Test_computeOperatorProgressingCondition, Test_operatorStatusesEqual)
(Test_computeOperatorStatusVersions)
(Test_computeOperatorUpgradeableCondition)
(Test_computeOperatorEvaluationConditionsDetectedCondition):
* pkg/operator/controller/sync-http-error-code-configmap/controller_test.go
(Test_desiredHttpErrorCodeConfigMap):
* pkg/util/network_test.go (Test_URI):
* pkg/util/retryableerror/retryableerror_test.go (TestRetryableError):
Use t.Run.
@rfredette
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 6, 2023
@gcs278
Copy link
Contributor Author

gcs278 commented Jul 10, 2023

/retest

@gcs278
Copy link
Contributor Author

gcs278 commented Jul 19, 2023

/unhold
Close to the end of the release cycle, and ready to merge.

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 19, 2023
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD 0cdc132 and 2 for PR HEAD f2327ab in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD 80cfabf and 1 for PR HEAD f2327ab in total

@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD b4b5f42 and 0 for PR HEAD f2327ab in total

@openshift-ci-robot
Copy link
Contributor

/hold

Revision f2327ab was retested 3 times: holding

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 20, 2023
@gcs278
Copy link
Contributor Author

gcs278 commented Jul 24, 2023

must gather test failures
/test e2e-aws-operator

Flaky CI...this is a unit test fix.
/hold cancel

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 24, 2023
@openshift-ci-robot
Copy link
Contributor

/retest-required

Remaining retests: 0 against base HEAD 31d9a02 and 2 for PR HEAD f2327ab in total

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 24, 2023

@gcs278: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit 83c9c41 into openshift:master Jul 24, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants