forked from ggordan/go-onedrive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drive_option_test.go
60 lines (53 loc) · 1.55 KB
/
drive_option_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package onedrive
import (
"fmt"
"testing"
"gotest.tools/v3/assert"
)
func TestDriveOption_SearchPath(t *testing.T) {
cases := []struct {
name string
in DriveOption
out string
}{
{
name: "me scope returns onedrive search path",
in: DriveOption{Scope: MeScope{}, Query: "test"},
out: "/me/drive/search(q='test')",
},
{
name: "site scope returns sharepoint site search path",
in: DriveOption{Scope: SharepointSiteScope{SiteID: "sp_123"}, Query: "test"},
out: "/sites/sp_123/drive/search(q='test')",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.in.SearchPath(), tc.out)
})
}
t.Run("sanitizes dangerous characters from query", func(t *testing.T) {
cases := []struct {
in string
out string
}{
{"test*", "/search(q='test')"},
{"test<tom", "/search(q='testtom')"},
{">", "/search(q='')"},
{"test's & skill's", "/search(q='tests%20&%20skills')"},
{"some_path\\testfile", "/search(q='some_pathtestfile')"},
{"some_path/testfile", "/search(q='some_pathtestfile')"},
{"test?", "/search(q='test')"},
}
for _, tc := range cases {
t.Run(fmt.Sprintf("scoped to me with %s", tc.in), func(t *testing.T) {
ds := DriveOption{Query: tc.in, Scope: MeScope{}}
assert.Equal(t, ds.SearchPath(), "/me/drive"+tc.out)
})
t.Run(fmt.Sprintf("scoped to site with %s", tc.in), func(t *testing.T) {
ds := DriveOption{Query: tc.in, Scope: SharepointSiteScope{SiteID: "sp_234"}}
assert.Equal(t, ds.SearchPath(), "/sites/sp_234/drive"+tc.out)
})
}
})
}