Skip to content

Commit

Permalink
Add test to account for symlinks as sources
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Feb 12, 2023
1 parent d05c10d commit 7e79560
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions pkg/bindfilter/bind_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,56 @@ func getWindowsBuildNumber() (int, error) {
}
return buildNum, nil
}

func TestGetBindMappingsSymlinks(t *testing.T) {
version, err := getWindowsBuildNumber()
if err != nil {
t.Fatalf("couldn't get version number: %s", err)
}

if version <= 17763 {
t.Skip("not supported on RS5 or earlier")
}

srcShort := t.TempDir()
sourceNested := filepath.Join(srcShort, "source")
if err := os.MkdirAll(sourceNested, 0600); err != nil {
t.Fatalf("failed to create folder: %s", err)
}
simlinkSource := filepath.Join(srcShort, "symlink")
if err := os.Symlink(sourceNested, simlinkSource); err != nil {
t.Fatalf("failed to create symlink: %s", err)
}

// We'll need the long form of the source folder, as we expect bfSetupFilter()
// to resolve the symlink and create a mapping to the actual source the symlink
// points to.
source, err := getFinalPath(sourceNested)
if err != nil {
t.Fatalf("failed to get long path")
}

dstShort := t.TempDir()
destination, err := getFinalPath(dstShort)
if err != nil {
t.Fatalf("failed to get long path")
}

// Use the symlink as a source for the mapping.
err = ApplyFileBinding(destination, simlinkSource, false)
if err != nil {
t.Fatal(err)
}
defer removeFileBinding(t, destination)

// We expect the mapping to point to the folder the symlink points to, not to the
// actual symlink.
hasMapping, err := checkSourceIsMountedOnDestination(source, destination)
if err != nil {
t.Fatal(err)
}

if !hasMapping {
t.Fatalf("expected to find %s mounted on %s, but could not", source, destination)
}
}

0 comments on commit 7e79560

Please sign in to comment.