Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func GetMountOptions(options []string) string {
}

func MakeDir(pathname string, perm os.FileMode) error {
err := os.MkdirAll(pathname, perm)
if err != nil {
if err := os.MkdirAll(pathname, perm); err != nil {
if !os.IsExist(err) {
return err
}
Expand Down
60 changes: 55 additions & 5 deletions pkg/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package util
import (
"fmt"
"os"
"path/filepath"
"reflect"
"testing"
"time"

"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
"k8s.io/kubernetes/pkg/volume"
)

func TestRoundUpBytes(t *testing.T) {
Expand Down Expand Up @@ -164,14 +166,19 @@ func TestGetMountOptions(t *testing.T) {
}

func TestMakeDir(t *testing.T) {
//Successfully create directory
targetTest := "./target_test"
// Successfully create directory
targetTest := filepath.Join(os.TempDir(), "TestMakeDir")
err := MakeDir(targetTest, 0777)
defer func() {
err := os.RemoveAll(targetTest)
assert.NoError(t, err)
}()
assert.NoError(t, err)

// Remove the directory created
err = os.RemoveAll(targetTest)
assert.NoError(t, err)
// create an existing directory
if err = MakeDir(targetTest, 0755); err != nil {
t.Errorf("Unexpected error: %v", err)
}
}

func TestConvertTagsToMap(t *testing.T) {
Expand Down Expand Up @@ -614,6 +621,11 @@ users:
envVariableHasConfig: false,
envVariableConfigIsValid: false,
},
{
desc: "no-need-kubeconfig",
kubeconfig: "no-need-kubeconfig",
expectError: false,
},
}

for _, test := range tests {
Expand All @@ -625,6 +637,44 @@ users:
}
}

func TestVolumeMounter(t *testing.T) {
path := "/mnt/data"
attributes := volume.Attributes{}

mounter := &VolumeMounter{
path: path,
attributes: attributes,
}

if mounter.GetPath() != path {
t.Errorf("Expected path %s, but got %s", path, mounter.GetPath())
}

if mounter.GetAttributes() != attributes {
t.Errorf("Expected attributes %v, but got %v", attributes, mounter.GetAttributes())
}

if err := mounter.CanMount(); err != nil {
t.Errorf("Unexpected error: %v", err)
}

if err := mounter.SetUp(volume.MounterArgs{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}

if err := mounter.SetUpAt("", volume.MounterArgs{}); err != nil {
t.Errorf("Unexpected error: %v", err)
}

metrics, err := mounter.GetMetrics()
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if metrics != nil {
t.Errorf("Expected nil metrics, but got %v", metrics)
}
}

func TestSetVolumeOwnership(t *testing.T) {
tmpVDir, err := os.MkdirTemp(os.TempDir(), "SetVolumeOwnership")
if err != nil {
Expand Down
Loading