@@ -17,7 +17,6 @@ limitations under the License.
17
17
package hostutil
18
18
19
19
import (
20
- "errors"
21
20
"fmt"
22
21
"net"
23
22
"os"
@@ -26,79 +25,9 @@ import (
26
25
"strings"
27
26
"testing"
28
27
29
- "github.com/stretchr/testify/assert"
30
- "k8s.io/mount-utils"
31
28
"k8s.io/utils/exec"
32
29
)
33
30
34
- // fakeMounter implements mount.Interface for tests.
35
- type fakeMounter struct {
36
- mount.FakeMounter
37
- mountRefs []string
38
- raiseError bool
39
- }
40
-
41
- // GetMountRefs finds all mount references to the path, returns a
42
- // list of paths.
43
- func (f * fakeMounter ) GetMountRefs (pathname string ) ([]string , error ) {
44
- if f .raiseError {
45
- return nil , errors .New ("Expected error." )
46
- }
47
-
48
- return f .mountRefs , nil
49
- }
50
-
51
- func TestDeviceNameFromMount (t * testing.T ) {
52
- hu := NewHostUtil ()
53
- path := "/tmp/foo"
54
- if goruntime .GOOS == "windows" {
55
- path = "C:" + path
56
- }
57
-
58
- testCases := map [string ]struct {
59
- mountRefs []string
60
- expectedPath string
61
- raiseError bool
62
- expectedError string
63
- }{
64
- "GetMountRefs error" : {
65
- raiseError : true ,
66
- expectedError : "Expected error." ,
67
- },
68
- "No Refs error" : {
69
- expectedError : fmt .Sprintf ("directory %s is not mounted" , path ),
70
- },
71
- "No Matching refs" : {
72
- mountRefs : []string {filepath .Join ("foo" , "lish" )},
73
- expectedPath : filepath .Base (path ),
74
- },
75
- "Matched ref" : {
76
- mountRefs : []string {filepath .Join (path , "lish" )},
77
- expectedPath : "lish" ,
78
- },
79
- }
80
-
81
- for name , tc := range testCases {
82
- t .Run (name , func (t * testing.T ) {
83
- mounter := & fakeMounter {
84
- mountRefs : tc .mountRefs ,
85
- raiseError : tc .raiseError ,
86
- }
87
-
88
- path , err := hu .GetDeviceNameFromMount (mounter , path , path )
89
- if tc .expectedError != "" {
90
- if err == nil || err .Error () != tc .expectedError {
91
- t .Fatalf ("expected error message `%s` but got `%v`" , tc .expectedError , err )
92
- }
93
- return
94
- }
95
-
96
- expectedPath := filepath .FromSlash (tc .expectedPath )
97
- assert .Equal (t , expectedPath , path )
98
- })
99
- }
100
- }
101
-
102
31
func createSocketFile (socketDir string ) (string , error ) {
103
32
testSocketFile := filepath .Join (socketDir , "mt.sock" )
104
33
0 commit comments