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

Improve the end-to-end tests and fix the issue with 'BeforeEach' code block #118

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

AvielSegev
Copy link
Contributor

@AvielSegev AvielSegev commented Jan 12, 2025

Hi,

This PR introduces four additional test cases as part of the end-to-end (e2e) tests to validate login behavior under the following scenarios:

  1. Valid credentialsI
  2. Invalid credentials
  3. Empty username or password
  4. Invalid URL

To ensure these tests pass, this PR also addresses the following issues:

BeforeEach and AfterEach Conflict:

Previously, the afterEach block did not remove agent records from the database, even though the associated VM was deleted. This caused failures in the beforeEach block due to unexpected matches between newly created agents and old database records. This has now been fixed.

Error Handling in testVmwareConnection:

When an error occurred in the testVmwareConnection method, the expected behavior was to return:
Unauthorized (401) for invalid credentials
BadRequest (400) for other errors
However, this logic was broken due to a if statement that checked wrong substring compare to what returned by the vCenter client. The issue has been resolved.

Additionally, the Vcsim (vSphere simulator) used in the e2e tests is now configured with a core username and password (123456) instead of allowing any non-empty credentials by default.

@@ -63,7 +63,7 @@ jobs:

- name: Deploy vcsim
run: |
kubectl create deployment vcsim --image=docker.io/vmware/vcsim
make deploy-vsphere-simulator
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is cool! With this we can deploy multiple vcsims and test multiple environemnts :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank's. Yes, it's much more convenient and also provides the flexibility to override the arguments passed to the container's ENTRYPOINT, allowing the simulator to be loaded with customizations.

…ch causes errors when running more than one test.

Signed-off-by: Aviel Segev <[email protected]>
@@ -132,7 +132,7 @@ func testVmwareConnection(requestCtx context.Context, credentials *config.Creden
err = client.Login(ctx, u.User)
if err != nil {
err = liberr.Wrap(err)
if strings.Contains(err.Error(), "incorrect") && strings.Contains(err.Error(), "password") {
if strings.Contains(err.Error(), "Login failure") {
Copy link
Collaborator

@machacekondra machacekondra Jan 13, 2025

Choose a reason for hiding this comment

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

Can you double check this works also in real env?

@machacekondra machacekondra merged commit cab7a33 into kubev2v:main Jan 13, 2025
4 of 5 checks passed
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.

2 participants