-
Notifications
You must be signed in to change notification settings - Fork 787
Hostpath mount validation #4419
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
Open
Horiodino
wants to merge
5
commits into
lima-vm:master
Choose a base branch
from
Horiodino:hostPath_mount_validation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+219
−24
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ee5b38
added validation for hostPath
Horiodino d3bafdf
added tests for hostPath validation
Horiodino ef0605a
return path translation logs to agent
Horiodino cf500f6
refactor : use constant for io.lima-vm/warnings
Horiodino 202d7c9
use path.Join for cross-platform abs paths
Horiodino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package toolset | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "gotest.tools/v3/assert" | ||
|
|
||
| "github.com/lima-vm/lima/v2/pkg/limatype" | ||
| ) | ||
|
|
||
| func TestTranslateHostPath(t *testing.T) { | ||
| mountPoint1 := "/mnt/home-user" | ||
| mountPoint2 := "/mnt/tmp" | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| hostPath string | ||
| toolSet ToolSet | ||
| wantGuestPath string | ||
| wantWarnings bool | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "file in mounted directory", | ||
| hostPath: "/home/user/documents/file.txt", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "/mnt/home-user/documents/file.txt", | ||
| wantWarnings: false, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "path outside mount - fallback to guest path", | ||
| hostPath: "/other/path/file.txt", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "/other/path/file.txt", | ||
| wantWarnings: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "similar prefix but not under mount", | ||
| hostPath: "/home/user2/file.txt", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "/home/user2/file.txt", | ||
| wantWarnings: true, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "multiple mounts", | ||
| hostPath: "/tmp/myfile", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| {Location: "/tmp", MountPoint: &mountPoint2}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "/mnt/tmp/myfile", | ||
| wantWarnings: false, | ||
| wantErr: false, | ||
| }, | ||
| { | ||
| name: "relative path should error", | ||
| hostPath: "relative/path", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "", | ||
| wantWarnings: false, | ||
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "empty path should error", | ||
| hostPath: "", | ||
| toolSet: ToolSet{ | ||
| inst: &limatype.Instance{ | ||
| Config: &limatype.LimaYAML{ | ||
| Mounts: []limatype.Mount{ | ||
| {Location: "/home/user", MountPoint: &mountPoint1}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| wantGuestPath: "", | ||
| wantWarnings: false, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| got, logs, err := test.toolSet.TranslateHostPath(test.hostPath) | ||
| if test.wantErr { | ||
| assert.Assert(t, err != nil) | ||
| } else { | ||
| assert.NilError(t, err) | ||
| assert.Equal(t, test.wantGuestPath, got) | ||
| if test.wantWarnings { | ||
| assert.Assert(t, logs != "") | ||
| } else { | ||
| assert.Equal(t, "", logs) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing on Windows
Also please squash the commits
https://lima-vm.io/docs/dev/git/#squashing-commits