bake: remove stale path evaluation shim
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -560,7 +560,3 @@ func evaluateToExistingPaths(in map[string]struct{}) (map[string]struct{}, error
|
|||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func evaluateToExistingPath(in string) (string, string, error) {
|
|
||||||
return osutil.EvaluateToExistingPath(in)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,92 +18,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEvaluateToExistingPath(t *testing.T) {
|
|
||||||
tempDir, err := osutil.GetLongPathName(t.TempDir())
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// Setup temporary directory structure for testing
|
|
||||||
existingFile := filepath.Join(tempDir, "existing_file")
|
|
||||||
require.NoError(t, os.WriteFile(existingFile, []byte("test"), 0644))
|
|
||||||
|
|
||||||
existingDir := filepath.Join(tempDir, "existing_dir")
|
|
||||||
require.NoError(t, os.Mkdir(existingDir, 0755))
|
|
||||||
|
|
||||||
symlinkToFile := filepath.Join(tempDir, "symlink_to_file")
|
|
||||||
require.NoError(t, os.Symlink(existingFile, symlinkToFile))
|
|
||||||
|
|
||||||
symlinkToDir := filepath.Join(tempDir, "symlink_to_dir")
|
|
||||||
require.NoError(t, os.Symlink(existingDir, symlinkToDir))
|
|
||||||
|
|
||||||
nonexistentPath := filepath.Join(tempDir, "nonexistent", "path", "file.txt")
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
expectErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "Existing file",
|
|
||||||
input: existingFile,
|
|
||||||
expected: existingFile,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Existing directory",
|
|
||||||
input: existingDir,
|
|
||||||
expected: existingDir,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Symlink to file",
|
|
||||||
input: symlinkToFile,
|
|
||||||
expected: existingFile,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Symlink to directory",
|
|
||||||
input: symlinkToDir,
|
|
||||||
expected: existingDir,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Non-existent path",
|
|
||||||
input: nonexistentPath,
|
|
||||||
expected: tempDir,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Non-existent intermediate path",
|
|
||||||
input: filepath.Join(tempDir, "nonexistent", "file.txt"),
|
|
||||||
expected: tempDir,
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Root path",
|
|
||||||
input: "/",
|
|
||||||
expected: func() string {
|
|
||||||
root, _ := filepath.Abs("/")
|
|
||||||
return root
|
|
||||||
}(),
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
result, _, err := evaluateToExistingPath(tt.input)
|
|
||||||
|
|
||||||
if tt.expectErr {
|
|
||||||
require.Error(t, err)
|
|
||||||
} else {
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tt.expected, result)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDedupePaths(t *testing.T) {
|
func TestDedupePaths(t *testing.T) {
|
||||||
wd := osutil.GetWd()
|
wd := osutil.GetWd()
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
@@ -344,7 +258,7 @@ func TestValidateEntitlements(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// if not, then escapeLink is not allowed
|
// if not, then escapeLink is not allowed
|
||||||
exp, _, err := evaluateToExistingPath(escapeLink)
|
exp, _, err := osutil.EvaluateToExistingPath(escapeLink)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
exp, err = filepath.EvalSymlinks(exp)
|
exp, err = filepath.EvalSymlinks(exp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package osutil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEvaluateToExistingPath(t *testing.T) {
|
||||||
|
tempDir, err := GetLongPathName(t.TempDir())
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
existingFile := filepath.Join(tempDir, "existing_file")
|
||||||
|
require.NoError(t, os.WriteFile(existingFile, []byte("test"), 0644))
|
||||||
|
|
||||||
|
existingDir := filepath.Join(tempDir, "existing_dir")
|
||||||
|
require.NoError(t, os.Mkdir(existingDir, 0755))
|
||||||
|
|
||||||
|
symlinkToFile := filepath.Join(tempDir, "symlink_to_file")
|
||||||
|
require.NoError(t, os.Symlink(existingFile, symlinkToFile))
|
||||||
|
|
||||||
|
symlinkToDir := filepath.Join(tempDir, "symlink_to_dir")
|
||||||
|
require.NoError(t, os.Symlink(existingDir, symlinkToDir))
|
||||||
|
|
||||||
|
nonexistentPath := filepath.Join(tempDir, "nonexistent", "path", "file.txt")
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
input string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Existing file",
|
||||||
|
input: existingFile,
|
||||||
|
expected: existingFile,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Existing directory",
|
||||||
|
input: existingDir,
|
||||||
|
expected: existingDir,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Symlink to file",
|
||||||
|
input: symlinkToFile,
|
||||||
|
expected: existingFile,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Symlink to directory",
|
||||||
|
input: symlinkToDir,
|
||||||
|
expected: existingDir,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Non-existent path",
|
||||||
|
input: nonexistentPath,
|
||||||
|
expected: tempDir,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Non-existent intermediate path",
|
||||||
|
input: filepath.Join(tempDir, "nonexistent", "file.txt"),
|
||||||
|
expected: tempDir,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Root path",
|
||||||
|
input: "/",
|
||||||
|
expected: func() string {
|
||||||
|
root, _ := filepath.Abs("/")
|
||||||
|
return root
|
||||||
|
}(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
result, _, err := EvaluateToExistingPath(tt.input)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, tt.expected, result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user