@@ -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,18 @@ 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 )
170
- assert .NoError (t , err )
172
+ defer func () {
173
+ err := os .RemoveAll (targetTest )
174
+ assert .NoError (t , err )
175
+ }()
171
176
172
- // Remove the directory created
173
- err = os .RemoveAll (targetTest )
174
- assert .NoError (t , err )
177
+ // create an existing directory
178
+ if err = MakeDir (targetTest , 0755 ); err != nil {
179
+ t .Errorf ("Unexpected error: %v" , err )
180
+ }
175
181
}
176
182
177
183
func TestConvertTagsToMap (t * testing.T ) {
@@ -614,6 +620,11 @@ users:
614
620
envVariableHasConfig : false ,
615
621
envVariableConfigIsValid : false ,
616
622
},
623
+ {
624
+ desc : "no-need-kubeconfig" ,
625
+ kubeconfig : "no-need-kubeconfig" ,
626
+ expectError : false ,
627
+ },
617
628
}
618
629
619
630
for _ , test := range tests {
@@ -625,6 +636,44 @@ users:
625
636
}
626
637
}
627
638
639
+ func TestVolumeMounter (t * testing.T ) {
640
+ path := "/mnt/data"
641
+ attributes := volume.Attributes {}
642
+
643
+ mounter := & VolumeMounter {
644
+ path : path ,
645
+ attributes : attributes ,
646
+ }
647
+
648
+ if mounter .GetPath () != path {
649
+ t .Errorf ("Expected path %s, but got %s" , path , mounter .GetPath ())
650
+ }
651
+
652
+ if mounter .GetAttributes () != attributes {
653
+ t .Errorf ("Expected attributes %v, but got %v" , attributes , mounter .GetAttributes ())
654
+ }
655
+
656
+ if err := mounter .CanMount (); err != nil {
657
+ t .Errorf ("Unexpected error: %v" , err )
658
+ }
659
+
660
+ if err := mounter .SetUp (volume.MounterArgs {}); err != nil {
661
+ t .Errorf ("Unexpected error: %v" , err )
662
+ }
663
+
664
+ if err := mounter .SetUpAt ("" , volume.MounterArgs {}); err != nil {
665
+ t .Errorf ("Unexpected error: %v" , err )
666
+ }
667
+
668
+ metrics , err := mounter .GetMetrics ()
669
+ if err != nil {
670
+ t .Errorf ("Unexpected error: %v" , err )
671
+ }
672
+ if metrics != nil {
673
+ t .Errorf ("Expected nil metrics, but got %v" , metrics )
674
+ }
675
+ }
676
+
628
677
func TestSetVolumeOwnership (t * testing.T ) {
629
678
tmpVDir , err := os .MkdirTemp (os .TempDir (), "SetVolumeOwnership" )
630
679
if err != nil {
0 commit comments