github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/util/mount/fake.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package mount 18 19 // FakeMounter implements mount.Interface for tests. 20 type FakeMounter struct { 21 MountPoints []MountPoint 22 Log []FakeAction 23 } 24 25 var _ Interface = &FakeMounter{} 26 27 // Values for FakeAction.Action 28 const FakeActionMount = "mount" 29 const FakeActionUnmount = "unmount" 30 31 // FakeAction objects are logged every time a fake mount or unmount is called. 32 type FakeAction struct { 33 Action string // "mount" or "unmount" 34 Target string // applies to both mount and unmount actions 35 Source string // applies only to "mount" actions 36 FSType string // applies only to "mount" actions 37 } 38 39 func (f *FakeMounter) ResetLog() { 40 f.Log = []FakeAction{} 41 } 42 43 func (f *FakeMounter) Mount(source string, target string, fstype string, options []string) error { 44 f.MountPoints = append(f.MountPoints, MountPoint{Device: source, Path: target, Type: fstype}) 45 f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: target, Source: source, FSType: fstype}) 46 return nil 47 } 48 49 func (f *FakeMounter) Unmount(target string) error { 50 newMountpoints := []MountPoint{} 51 for _, mp := range f.MountPoints { 52 if mp.Path != target { 53 newMountpoints = append(newMountpoints, MountPoint{Device: mp.Device, Path: mp.Path, Type: mp.Type}) 54 } 55 } 56 f.MountPoints = newMountpoints 57 f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: target}) 58 return nil 59 } 60 61 func (f *FakeMounter) List() ([]MountPoint, error) { 62 return f.MountPoints, nil 63 } 64 65 func (f *FakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { 66 for _, mp := range f.MountPoints { 67 if mp.Path == file { 68 return false, nil 69 } 70 } 71 return true, nil 72 }