Replaces path.Operation with filepath.Operation (kubelet)

The path module has a few different functions:
Clean, Split, Join, Ext, Dir, Base, IsAbs. These functions do not
take into account the OS-specific path separator, meaning that they
won't behave as intended on Windows.

For example, Dir is supposed to return all but the last element of the
path. For the path "C:\some\dir\somewhere", it is supposed to return
"C:\some\dir\", however, it returns ".".

Instead of these functions, the ones in filepath should be used instead.
This commit is contained in:
Claudiu Belu
2022-06-15 15:17:24 +03:00
parent f2c89045f4
commit b9bf3e5c49
13 changed files with 39 additions and 44 deletions

View File

@@ -19,7 +19,7 @@ package kuberuntime
import (
"fmt"
"math/rand"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
@@ -42,7 +42,7 @@ func TestLogSymLink(t *testing.T) {
containerName := randStringBytes(70)
dockerID := randStringBytes(80)
// The file name cannot exceed 255 characters. Since .log suffix is required, the prefix cannot exceed 251 characters.
expectedPath := path.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s", podFullName, containerName, dockerID)[:251]+".log")
expectedPath := filepath.Join(containerLogsDir, fmt.Sprintf("%s_%s-%s", podFullName, containerName, dockerID)[:251]+".log")
as.Equal(expectedPath, logSymlink(containerLogsDir, podFullName, containerName, dockerID))
}
@@ -53,6 +53,6 @@ func TestLegacyLogSymLink(t *testing.T) {
podName := randStringBytes(128)
podNamespace := randStringBytes(10)
// The file name cannot exceed 255 characters. Since .log suffix is required, the prefix cannot exceed 251 characters.
expectedPath := path.Join(legacyContainerLogsDir, fmt.Sprintf("%s_%s_%s-%s", podName, podNamespace, containerName, containerID)[:251]+".log")
expectedPath := filepath.Join(legacyContainerLogsDir, fmt.Sprintf("%s_%s_%s-%s", podName, podNamespace, containerName, containerID)[:251]+".log")
as.Equal(expectedPath, legacyLogSymlink(containerID, containerName, podName, podNamespace))
}