@@ -19,12 +19,14 @@ package util
19
19
import (
20
20
"fmt"
21
21
"os"
22
+ "path/filepath"
22
23
"reflect"
23
24
"testing"
24
25
"time"
25
26
26
27
"github.com/stretchr/testify/assert"
27
28
"go.uber.org/mock/gomock"
29
+ "k8s.io/kubernetes/pkg/volume"
28
30
)
29
31
30
32
func TestRoundUpBytes (t * testing.T ) {
@@ -164,14 +166,19 @@ func TestGetMountOptions(t *testing.T) {
164
166
}
165
167
166
168
func TestMakeDir (t * testing.T ) {
167
- //Successfully create directory
168
- targetTest := "./target_test"
169
+ // Successfully create directory
170
+ targetTest := filepath . Join ( os . TempDir (), "TestMakeDir" )
169
171
err := MakeDir (targetTest , 0777 )
172
+ defer func () {
173
+ err := os .RemoveAll (targetTest )
174
+ assert .NoError (t , err )
175
+ }()
170
176
assert .NoError (t , err )
171
177
172
- // Remove the directory created
173
- err = os .RemoveAll (targetTest )
174
- assert .NoError (t , err )
178
+ // create an existing directory
179
+ if err = MakeDir (targetTest , 0755 ); err != nil {
180
+ t .Errorf ("Unexpected error: %v" , err )
181
+ }
175
182
}
176
183
177
184
func TestConvertTagsToMap (t * testing.T ) {
@@ -614,6 +621,11 @@ users:
614
621
envVariableHasConfig : false ,
615
622
envVariableConfigIsValid : false ,
616
623
},
624
+ {
625
+ desc : "no-need-kubeconfig" ,
626
+ kubeconfig : "no-need-kubeconfig" ,
627
+ expectError : false ,
628
+ },
617
629
}
618
630
619
631
for _ , test := range tests {
@@ -625,6 +637,44 @@ users:
625
637
}
626
638
}
627
639
640
+ func TestVolumeMounter (t * testing.T ) {
641
+ path := "/mnt/data"
642
+ attributes := volume.Attributes {}
643
+
644
+ mounter := & VolumeMounter {
645
+ path : path ,
646
+ attributes : attributes ,
647
+ }
648
+
649
+ if mounter .GetPath () != path {
650
+ t .Errorf ("Expected path %s, but got %s" , path , mounter .GetPath ())
651
+ }
652
+
653
+ if mounter .GetAttributes () != attributes {
654
+ t .Errorf ("Expected attributes %v, but got %v" , attributes , mounter .GetAttributes ())
655
+ }
656
+
657
+ if err := mounter .CanMount (); err != nil {
658
+ t .Errorf ("Unexpected error: %v" , err )
659
+ }
660
+
661
+ if err := mounter .SetUp (volume.MounterArgs {}); err != nil {
662
+ t .Errorf ("Unexpected error: %v" , err )
663
+ }
664
+
665
+ if err := mounter .SetUpAt ("" , volume.MounterArgs {}); err != nil {
666
+ t .Errorf ("Unexpected error: %v" , err )
667
+ }
668
+
669
+ metrics , err := mounter .GetMetrics ()
670
+ if err != nil {
671
+ t .Errorf ("Unexpected error: %v" , err )
672
+ }
673
+ if metrics != nil {
674
+ t .Errorf ("Expected nil metrics, but got %v" , metrics )
675
+ }
676
+ }
677
+
628
678
func TestSetVolumeOwnership (t * testing.T ) {
629
679
tmpVDir , err := os .MkdirTemp (os .TempDir (), "SetVolumeOwnership" )
630
680
if err != nil {
0 commit comments