Skip to content

Commit f3cf83e

Browse files
Prachi Shivanand AnurePrachi Shivanand Anure
authored andcommitted
minor canges
1 parent ade7ad3 commit f3cf83e

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

pkg/mounter/mounter_test.go

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13+
func stringSlicesEqualIgnoreOrder(a, b []string) bool {
14+
if len(a) != len(b) {
15+
return false
16+
}
17+
aCopy := make([]string, len(a))
18+
bCopy := make([]string, len(b))
19+
copy(aCopy, a)
20+
copy(bCopy, b)
21+
sort.Strings(aCopy)
22+
sort.Strings(bCopy)
23+
return reflect.DeepEqual(aCopy, bCopy)
24+
}
25+
1326
func TestNewMounter(t *testing.T) {
1427
tests := []struct {
1528
name string
@@ -41,8 +54,8 @@ func TestNewMounter(t *testing.T) {
4154
AccessKeys: ":test-api-key",
4255
AuthType: "iam",
4356
KpRootKeyCrn: "test-kp-root-key-crn",
44-
MountOptions: []string{"cipher_suites=default", "opt1=val1"},
45-
MounterUtils: &(mounterUtils.MounterOptsUtils{}),
57+
MountOptions: []string{"opt1=val1", "cipher_suites=default"},
58+
MounterUtils: &mounterUtils.MounterOptsUtils{},
4659
},
4760
expectedErr: nil,
4861
},
@@ -72,7 +85,7 @@ func TestNewMounter(t *testing.T) {
7285
UID: "fake-uid",
7386
GID: "fake-gid",
7487
MountOptions: []string{"opt1=val1", "opt2=val2"},
75-
MounterUtils: &(mounterUtils.MounterOptsUtils{}),
88+
MounterUtils: &mounterUtils.MounterOptsUtils{},
7689
},
7790
expectedErr: nil,
7891
},
@@ -98,7 +111,7 @@ func TestNewMounter(t *testing.T) {
98111
AuthType: "hmac",
99112
KpRootKeyCrn: "test-kp-root-key-crn",
100113
MountOptions: []string{"cipher_suites=default"},
101-
MounterUtils: &(mounterUtils.MounterOptsUtils{}),
114+
MounterUtils: &mounterUtils.MounterOptsUtils{},
102115
},
103116
expectedErr: nil,
104117
},
@@ -110,8 +123,23 @@ func TestNewMounter(t *testing.T) {
110123

111124
result := factory.NewMounter(test.attrib, test.secretMap, test.mountOptions, nil)
112125

113-
sort.Strings(test.expected.(*S3fsMounter).MountOptions)
114-
sort.Strings(result.(*S3fsMounter).MountOptions)
126+
if s3fs, ok := result.(*S3fsMounter); ok {
127+
expected := test.expected.(*S3fsMounter)
128+
if !stringSlicesEqualIgnoreOrder(s3fs.MountOptions, expected.MountOptions) {
129+
t.Errorf("MountOptions mismatch.\nGot: %v\nWant: %v", s3fs.MountOptions, expected.MountOptions)
130+
}
131+
s3fs.MountOptions = nil
132+
expected.MountOptions = nil
133+
}
134+
if rclone, ok := result.(*RcloneMounter); ok {
135+
expected := test.expected.(*RcloneMounter)
136+
if !stringSlicesEqualIgnoreOrder(rclone.MountOptions, expected.MountOptions) {
137+
t.Errorf("MountOptions mismatch.\nGot: %v\nWant: %v", rclone.MountOptions, expected.MountOptions)
138+
}
139+
rclone.MountOptions = nil
140+
expected.MountOptions = nil
141+
}
142+
115143
assert.Equal(t, result, test.expected)
116144

117145
if !reflect.DeepEqual(result, test.expected) {

0 commit comments

Comments
 (0)