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
14 changes: 14 additions & 0 deletions pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,20 @@ func setKeyValueInMap(m map[string]string, key, value string) {
m[key] = value
}

// getValueInMap get value from map by key
// key in the map is case insensitive
func getValueInMap(m map[string]string, key string) string {
if m == nil {
return ""
}
for k, v := range m {
if strings.EqualFold(k, key) {
return v
}
}
return ""
}

// replaceWithMap replace key with value for str
func replaceWithMap(str string, m map[string]string) string {
for k, v := range m {
Expand Down
46 changes: 46 additions & 0 deletions pkg/blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,52 @@ func TestSetKeyValueInMap(t *testing.T) {
}
}

func TestGetValueInMap(t *testing.T) {
tests := []struct {
desc string
m map[string]string
key string
expected string
}{
{
desc: "nil map",
key: "key",
expected: "",
},
{
desc: "empty map",
m: map[string]string{},
key: "key",
expected: "",
},
{
desc: "non-empty map",
m: map[string]string{"k": "v"},
key: "key",
expected: "",
},
{
desc: "same key already exists",
m: map[string]string{"subDir": "value2"},
key: "subDir",
expected: "value2",
},
{
desc: "case insensitive key already exists",
m: map[string]string{"subDir": "value2"},
key: "subdir",
expected: "value2",
},
}

for _, test := range tests {
result := getValueInMap(test.m, test.key)
if result != test.expected {
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expected)
}
}
}

func TestReplaceWithMap(t *testing.T) {
tests := []struct {
desc string
Expand Down
2 changes: 1 addition & 1 deletion pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
return &csi.NodePublishVolumeResponse{}, err
}

if perm := context[mountPermissionsField]; perm != "" {
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
var err error
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))
Expand Down