@@ -19,12 +19,14 @@ package util
1919import (
2020 "fmt"
2121 "os"
22+ "path/filepath"
2223 "reflect"
2324 "testing"
2425 "time"
2526
2627 "github.com/stretchr/testify/assert"
2728 "go.uber.org/mock/gomock"
29+ "k8s.io/kubernetes/pkg/volume"
2830)
2931
3032func TestRoundUpBytes (t * testing.T ) {
@@ -164,14 +166,19 @@ func TestGetMountOptions(t *testing.T) {
164166}
165167
166168func TestMakeDir (t * testing.T ) {
167- //Successfully create directory
168- targetTest := "./target_test"
169+ // Successfully create directory
170+ targetTest := filepath . Join ( os . TempDir (), "TestMakeDir" )
169171 err := MakeDir (targetTest , 0777 )
172+ defer func () {
173+ err := os .RemoveAll (targetTest )
174+ assert .NoError (t , err )
175+ }()
170176 assert .NoError (t , err )
171177
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+ }
175182}
176183
177184func TestConvertTagsToMap (t * testing.T ) {
@@ -614,6 +621,11 @@ users:
614621 envVariableHasConfig : false ,
615622 envVariableConfigIsValid : false ,
616623 },
624+ {
625+ desc : "no-need-kubeconfig" ,
626+ kubeconfig : "no-need-kubeconfig" ,
627+ expectError : false ,
628+ },
617629 }
618630
619631 for _ , test := range tests {
@@ -625,6 +637,44 @@ users:
625637 }
626638}
627639
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+
628678func TestSetVolumeOwnership (t * testing.T ) {
629679 tmpVDir , err := os .MkdirTemp (os .TempDir (), "SetVolumeOwnership" )
630680 if err != nil {
0 commit comments