Merge pull request #41521 from spiffxp/osx-make-test

Automatic merge from submit-queue (batch tested with PRs 41401, 41195, 41664, 41521, 41651)

Allow `make test` to pass on OSX

**What this PR does / why we need it**: `make test` doesn't pass on my OSX setup (10.11.6, go1.7, docker 1.13.1) on `master`, `release-1.5`, nor `release-1.4`.  Our [docs on unit tests](https://github.com/kubernetes/community/blob/master/contributors/devel/testing.md#unit-tests) say they should always pass on OS X.  This PR allows them to pass.

**Release note**:
```release-note
NONE
```

ref: #24717 for the motivation behind dereferencing mount symlinks

/cc @kubernetes/sig-testing-pr-reviews
This commit is contained in:
Kubernetes Submit Queue 2017-02-17 19:46:42 -08:00 committed by GitHub
commit 112aa327ac
2 changed files with 32 additions and 13 deletions

View File

@ -267,7 +267,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk,
path: true,
age: 100,
age: time.Second,
upgraded: true,
touched: true,
goPath: gp,
@ -281,7 +281,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk,
path: true,
age: 100,
age: time.Second,
upgraded: false,
touched: false,
goPath: gpk,
@ -295,7 +295,7 @@ func TestGetKubetest(t *testing.T) {
stat: pk,
path: true,
age: 100,
age: time.Second,
upgraded: true,
touched: false,
goPath: gpk,
@ -314,7 +314,7 @@ func TestGetKubetest(t *testing.T) {
if p != c.stat {
return nil, fmt.Errorf("Failed to find %s", p)
}
return FileInfo{time.Now().Add(c.age)}, nil
return FileInfo{time.Now().Add(c.age * -1)}, nil
},
func(name string) (string, error) {
if c.path {

View File

@ -17,6 +17,7 @@ limitations under the License.
package mount
import (
"path/filepath"
"sync"
"github.com/golang/glog"
@ -80,9 +81,15 @@ func (f *FakeMounter) Mount(source string, target string, fstype string, options
}
}
f.MountPoints = append(f.MountPoints, MountPoint{Device: source, Path: target, Type: fstype})
glog.V(5).Infof("Fake mounter: mounted %s to %s", source, target)
f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: target, Source: source, FSType: fstype})
// If target is a symlink, get its absolute path
absTarget, err := filepath.EvalSymlinks(target)
if err != nil {
absTarget = target
}
f.MountPoints = append(f.MountPoints, MountPoint{Device: source, Path: absTarget, Type: fstype})
glog.V(5).Infof("Fake mounter: mounted %s to %s", source, absTarget)
f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: absTarget, Source: source, FSType: fstype})
return nil
}
@ -90,17 +97,23 @@ func (f *FakeMounter) Unmount(target string) error {
f.mutex.Lock()
defer f.mutex.Unlock()
// If target is a symlink, get its absolute path
absTarget, err := filepath.EvalSymlinks(target)
if err != nil {
absTarget = target
}
newMountpoints := []MountPoint{}
for _, mp := range f.MountPoints {
if mp.Path == target {
glog.V(5).Infof("Fake mounter: unmounted %s from %s", mp.Device, target)
if mp.Path == absTarget {
glog.V(5).Infof("Fake mounter: unmounted %s from %s", mp.Device, absTarget)
// Don't copy it to newMountpoints
continue
}
newMountpoints = append(newMountpoints, MountPoint{Device: mp.Device, Path: mp.Path, Type: mp.Type})
}
f.MountPoints = newMountpoints
f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: target})
f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: absTarget})
return nil
}
@ -115,13 +128,19 @@ func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
// If file is a symlink, get its absolute path
absFile, err := filepath.EvalSymlinks(file)
if err != nil {
absFile = file
}
for _, mp := range f.MountPoints {
if mp.Path == file {
glog.V(5).Infof("isLikelyMountPoint for %s: mounted %s, false", file, mp.Path)
if mp.Path == absFile {
glog.V(5).Infof("isLikelyNotMountPoint for %s: mounted %s, false", file, mp.Path)
return false, nil
}
}
glog.V(5).Infof("isLikelyMountPoint for %s: true", file)
glog.V(5).Infof("isLikelyNotMountPoint for %s: true", file)
return true, nil
}