Skip to content

fix: ensure usrlocalsharelima.Dir() works when called from tests #3401

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Konikz
Copy link

@Konikz Konikz commented Apr 3, 2025

Fixes #3208

During tests, usrlocalsharelima.Dir() fails to find the guestagent binary because the test executable is in a temp directory. This PR adds a test that verifies the binary can be found in both expected locations:

  1. Same directory as the test executable
  2. share/lima directory relative to the test executable

The test creates dummy binaries in both locations and verifies Dir() can find them. This ensures the function works correctly in test environments where os.Executable returns a temp directory path.

@jandubois
Copy link
Member

There is something wrong with this PR; it adds almost 2000 lines, many unrelated to the issue it is supposed to fix. This may be responsible for the various test failures.

Don't merge master into your branch, but rebase on latest master if there are merge conflicts.

Please squash commits into a single commit and add a DCO signature.

Thanks!

@jandubois jandubois marked this pull request as draft April 10, 2025 01:17
@jandubois
Copy link
Member

There is something wrong with this PR; it adds almost 2000 lines, many unrelated to the issue it is supposed to fix. This may be responsible for the various test failures.

@Konikz Are you planning to fix this PR? There is nothing we can do with it until the extraneous commits are removed and the lint failures addressed.

@Konikz
Copy link
Author

Konikz commented Apr 10, 2025

@jandubois I'll rectify the issue with the pr

@Konikz Konikz force-pushed the fix/guestagent-test-location branch 2 times, most recently from 76f3619 to f0883e9 Compare April 15, 2025 09:32
@Konikz Konikz closed this Apr 15, 2025
@Konikz Konikz force-pushed the fix/guestagent-test-location branch from 216015b to 4c82f35 Compare April 15, 2025 16:40
@Konikz Konikz deleted the fix/guestagent-test-location branch April 15, 2025 17:07
@Konikz Konikz restored the fix/guestagent-test-location branch April 15, 2025 17:11
@Konikz Konikz reopened this Apr 15, 2025
@Konikz Konikz marked this pull request as ready for review April 15, 2025 18:26
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

I would change the logic to use Must(), but feel free to ignore if you like your approach better.

However, you do need to squash commits before we can merge.

@@ -16,8 +16,11 @@ import (
"github.com/sirupsen/logrus"
)

// executable is a variable that can be overridden in tests.
var executable = os.Executable
Copy link
Member

Choose a reason for hiding this comment

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

I would just cache the return value of the function because it is constant over the lifetime of the process. Import Must at the top:

import (
    …
    . "github.com/lima-vm/lima/pkg/must"
)

and then use

Suggested change
var executable = os.Executable
var self = Must(os.Executable())

later you can simply assign to it:

    self = limactlPath

See osutil/user.go for an example of using Must().

Copy link
Author

Choose a reason for hiding this comment

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

Sir @jandubois ,
I have tried implementing the above suggestions, I need your suggestion with the failing tests.

@Konikz Konikz force-pushed the fix/guestagent-test-location branch 3 times, most recently from 13e5ad3 to a69b55d Compare April 16, 2025 05:39
@Konikz Konikz marked this pull request as draft April 16, 2025 05:43
@Konikz Konikz force-pushed the fix/guestagent-test-location branch 2 times, most recently from 16b393d to abf44b3 Compare April 16, 2025 06:52
This commit implements the following improvements:\n- Caches the executable path at package level using Must()\n- Makes the Dir() function testable\n- Adds a test to verify functionality

Signed-off-by: Konikz <[email protected]>
@Konikz Konikz force-pushed the fix/guestagent-test-location branch from abf44b3 to c390ecc Compare April 16, 2025 07:09
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.

usrlocalsharelima.Dir() doesn't work when called from tests
2 participants