unittests: Fixes unit tests for Windows (part 2)
Currently, there are some unit tests that are failing on Windows due to various reasons: - volume mounting is a bit different on Windows: Mount will create the parent dirs and mklink at the volume path later (otherwise mklink will raise an error). - os.Chmod is not working as intended on Windows. - path.Dir() will always return "." on Windows, and filepath.Dir() should be used instead (which works correctly). - on Windows, you can't typically run binaries without extensions. If the file C:\\foo.bat exists, we can still run C:\\foo because Windows will append one of the supported file extensions ($env:PATHEXT) to it and run it. - Windows file permissions do not work the same way as the Linux ones. - /tmp directory being used, which might not exist on Windows. Instead, the OS-specific Temp directory should be used. Fixes a few other issues: - rbd.go: Return error in a case in which an error is encountered. This will prevent "rbd: failed to setup" and "rbd: successfully setup" log messages to be logged at the same time.
This commit is contained in:
@@ -36,7 +36,7 @@ import (
|
||||
)
|
||||
|
||||
func newTestHost(t *testing.T) (string, volume.VolumeHost) {
|
||||
tempDir, err := ioutil.TempDir("/tmp", "git_repo_test.")
|
||||
tempDir, err := ioutil.TempDir("", "git_repo_test.")
|
||||
if err != nil {
|
||||
t.Fatalf("can't make a temp rootdir: %v", err)
|
||||
}
|
||||
@@ -314,7 +314,7 @@ func doTestPlugin(scenario struct {
|
||||
}
|
||||
|
||||
path := mounter.GetPath()
|
||||
suffix := fmt.Sprintf("pods/poduid/volumes/kubernetes.io~git-repo/%v", scenario.vol.Name)
|
||||
suffix := filepath.Join("pods/poduid/volumes/kubernetes.io~git-repo", scenario.vol.Name)
|
||||
if !strings.HasSuffix(path, suffix) {
|
||||
allErrs = append(allErrs,
|
||||
fmt.Errorf("got unexpected path: %s", path))
|
||||
@@ -439,7 +439,7 @@ func doTestSetUp(scenario struct {
|
||||
|
||||
var expectedPaths []string
|
||||
for _, expected := range expecteds {
|
||||
expectedPaths = append(expectedPaths, g.GetPath()+expected.dir)
|
||||
expectedPaths = append(expectedPaths, filepath.Join(g.GetPath(), expected.dir))
|
||||
}
|
||||
if len(fcmd.Dirs) != len(expectedPaths) || !reflect.DeepEqual(expectedPaths, fcmd.Dirs) {
|
||||
allErrs = append(allErrs,
|
||||
|
Reference in New Issue
Block a user