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

test: add and cleanup vm-console-proxy operand #509

Merged
merged 1 commit into from Mar 9, 2023
Merged

test: add and cleanup vm-console-proxy operand #509

merged 1 commit into from Mar 9, 2023

Conversation

codingben
Copy link
Member

@codingben codingben commented Mar 1, 2023

What this PR does / why we need it:

Add and cleanup operand unit tests.

Release note:

Add and cleanup vm-console-proxy operand unit tests

@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Mar 1, 2023
@codingben codingben marked this pull request as draft March 1, 2023 12:29
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2023
@codingben codingben mentioned this pull request Mar 1, 2023
@codingben codingben marked this pull request as ready for review March 1, 2023 14:55
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2023
@codingben
Copy link
Member Author

@akrejcir FYI, it can be reviewed except an issue in should create vm-console-proxy resources.

@codingben codingben marked this pull request as draft March 1, 2023 15:00
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 1, 2023
Copy link
Collaborator

@akrejcir akrejcir left a comment

Choose a reason for hiding this comment

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

Can you also cleanup the names of functions?

internal/operands/vm-console-proxy/resources.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile.go Outdated Show resolved Hide resolved
@codingben
Copy link
Member Author

I'll rename that PR to add only new tests, and open another PR to have refactored functions.

@codingben codingben changed the title refactor: cleanup vm-console-proxy operand test: add more vm-console-proxy operand tests Mar 2, 2023
@codingben
Copy link
Member Author

This PR is ready for review, except some issue with the commented lines:

It("should remove cluster resources on cleanup", func() {
...
		// ExpectResourceNotExists(bundle.serviceAccount, request)
		ExpectResourceNotExists(bundle.clusterRole, request)
		ExpectResourceNotExists(bundle.clusterRoleBinding, request)
		// ExpectResourceNotExists(bundle.configMap, request)
		// ExpectResourceNotExists(bundle.service, request)
		// ExpectResourceNotExists(bundle.deployment, request)
		ExpectResourceNotExists(newRoute(namespace, "vm-console-proxy"), request)
}

It throws nil error when I try to test it.

/cc @akrejcir @0xFelix

Copy link
Collaborator

@akrejcir akrejcir left a comment

Choose a reason for hiding this comment

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

A partial review.
In general, unit tests don't need to test every single private function. Private functions can change. Tests should cover visible behavior of a module:

  • Exported functions and methods
  • Exported structs
  • Exported fields of structs

In my opinion, an exception to this guideline is if a private function has complex implementation and we want to make sure that it works.

internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
internal/operands/vm-console-proxy/reconcile_test.go Outdated Show resolved Hide resolved
@codingben
Copy link
Member Author

@akrejcir Ah okay :) I'm so sorry. I never wrote before operator tests. I thought we should test all operand functions because it plays critical role in deploying vm-console-proxy, it's not just another library. Thanks!

@codingben codingben changed the title test: add more vm-console-proxy operand tests test: add and cleanup vm-console-proxy operand Mar 5, 2023
@codingben codingben marked this pull request as ready for review March 5, 2023 08:02
@codingben codingben requested a review from 0xFelix March 5, 2023 08:02
@codingben
Copy link
Member Author

@akrejcir @0xFelix Thanks a lot for your reviews, really appreciated. It should be okay now. :)

@codingben
Copy link
Member Author

codingben commented Mar 5, 2023

Can you also cleanup the names of functions?

@akrejcir Sorry, what do you mean?

@codingben
Copy link
Member Author

/retest

@akrejcir
Copy link
Collaborator

akrejcir commented Mar 6, 2023

Can you also cleanup the names of functions?

@akrejcir Sorry, what do you mean?

I meant that function names in reconcile.go can be made clearer. For example reconcileServiceAccountsFuncs() can just be reconcileServiceAccount(). But now that you've split this PR into 2, that comment is relevant to the other PR.

@akrejcir
Copy link
Collaborator

akrejcir commented Mar 6, 2023

Can you add unit tests for the annotations functionality? To test these cases:

  • proxy is deployed to the namespace specified by the vm-console-proxy-namespace annotation
  • when vm-console-proxy-enabled annotation is removed, the proxy resources are deleted

@codingben codingben marked this pull request as draft March 6, 2023 08:47
@kubevirt-bot kubevirt-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 6, 2023
@codingben
Copy link
Member Author

proxy is deployed to the namespace specified by the vm-console-proxy-namespace annotation

Done, please review.

when vm-console-proxy-enabled annotation is removed, the proxy resources are deleted

@akrejcir Done, please review as well.

But, what is the purpose of that test? Isn't similar to should remove cluster resources on cleanup? I mean, it sounds like it's the same test as should remove cluster resources on cleanup and we just need to remove annotation by:

request.Instance.Annotations = map[string]string{
    VmConsoleProxyNamespaceAnnotation: namespace,
}

Before we call to Cleanup?

Add and cleanup operand unit tests.

Signed-off-by: Ben Oukhanov <boukhanov@redhat.com>
@codingben codingben marked this pull request as ready for review March 8, 2023 10:23
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2023
@sonarcloud
Copy link

sonarcloud bot commented Mar 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codingben
Copy link
Member Author

/retest

@akrejcir
Copy link
Collaborator

akrejcir commented Mar 8, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 8, 2023
@codingben
Copy link
Member Author

@akrejcir Seems like approval is missing and it wasn't merged because of it.

@akrejcir
Copy link
Collaborator

akrejcir commented Mar 9, 2023

/approve

@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akrejcir

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

@kubevirt-bot kubevirt-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2023
@kubevirt-bot kubevirt-bot merged commit 3689c47 into kubevirt:master Mar 9, 2023
akrejcir added a commit to akrejcir/ssp-operator that referenced this pull request May 2, 2023
Cleanup() method of vm-console-proxy deletes resources from the correct namespace.

Manual backport of b72b74f.

NOTE: The PR could not be trivially backported, because intermediate PRs
were not backported, and that caused git conflicts. To fix the
conflicts, unit tests were not included.
- Refactoring PR: kubevirt#515
- PR that adds more unit tests: kubevirt#509

Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
@codingben codingben deleted the CNV-25395 branch June 28, 2023 14:22
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants