@@ -8,6 +8,10 @@ import (
88 exec "k8s.io/utils/exec/testing"
99)
1010
11+ const (
12+ giB = 1 << 30
13+ )
14+
1115type fakeMounter struct {
1216 mount.SafeFormatAndMount
1317}
@@ -35,7 +39,13 @@ func (m *fakeMounter) GetDeviceName(mountPath string) (string, int, error) {
3539 return mount .GetDeviceNameFromMount (m , mountPath )
3640}
3741
38- func (* fakeMounter ) PathExists (_ string ) (bool , error ) {
42+ func (* fakeMounter ) PathExists (path string ) (bool , error ) {
43+ if _ , err := os .Stat (path ); os .IsNotExist (err ) {
44+ return false , nil
45+ } else if err != nil {
46+ return false , err
47+ }
48+
3949 return true , nil
4050}
4151
@@ -50,34 +60,52 @@ func (*fakeMounter) MakeDir(pathname string) error {
5060 return nil
5161}
5262
53- func (* fakeMounter ) MakeFile (_ string ) error {
63+ func (* fakeMounter ) MakeFile (pathname string ) error {
64+ file , err := os .OpenFile (pathname , os .O_CREATE , os .FileMode (0o644 ))
65+ if err != nil {
66+ if ! os .IsExist (err ) {
67+ return err
68+ }
69+ }
70+ if err = file .Close (); err != nil {
71+ return err
72+ }
73+
5474 return nil
5575}
5676
5777func (m * fakeMounter ) GetStatistics (_ string ) (volumeStatistics , error ) {
58- return volumeStatistics {}, nil
78+ return volumeStatistics {
79+ AvailableBytes : 3 * giB ,
80+ TotalBytes : 10 * giB ,
81+ UsedBytes : 7 * giB ,
82+
83+ AvailableInodes : 3000 ,
84+ TotalInodes : 10000 ,
85+ UsedInodes : 7000 ,
86+ }, nil
5987}
6088
6189func (m * fakeMounter ) IsBlockDevice (_ string ) (bool , error ) {
62- return true , nil
90+ return false , nil
6391}
6492
6593func (m * fakeMounter ) IsCorruptedMnt (_ error ) bool {
6694 return false
6795}
6896
6997func (m * fakeMounter ) NeedResize (_ string , _ string ) (bool , error ) {
70- return true , nil
98+ return false , nil
7199}
72100
73101func (m * fakeMounter ) Resize (_ string , _ string ) (bool , error ) {
74102 return true , nil
75103}
76104
77- func (m * fakeMounter ) Unpublish (_ string ) error {
78- return nil
105+ func (m * fakeMounter ) Unpublish (path string ) error {
106+ return m . Unstage ( path )
79107}
80108
81- func (m * fakeMounter ) Unstage (_ string ) error {
82- return nil
109+ func (m * fakeMounter ) Unstage (path string ) error {
110+ return mount . CleanupMountPoint ( path , m , true )
83111}
0 commit comments