corso/src/cli/utils/onedrive_test.go
neha_gupta 245d3ee089
treat / as root for restore of onedrive and sharepoint (#3328)
<!-- PR description-->

passing '/' will select anything for backup details and restore for onedrive and sharepoint

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [x] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #https://github.com/alcionai/corso/issues/3252
#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
2023-05-11 05:34:13 +00:00

109 lines
2.3 KiB
Go

package utils_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/path"
)
type OneDriveUtilsSuite struct {
tester.Suite
}
func TestOneDriveUtilsSuite(t *testing.T) {
suite.Run(t, &OneDriveUtilsSuite{Suite: tester.NewUnitSuite(t)})
}
func (suite *OneDriveUtilsSuite) TestIncludeOneDriveRestoreDataSelectors() {
var (
empty = []string{}
single = []string{"single"}
multi = []string{"more", "than", "one"}
containsOnly = []string{"contains"}
prefixOnly = []string{"/prefix"}
containsAndPrefix = []string{"contains", "/prefix"}
onlySlash = []string{string(path.PathSeparator)}
)
table := []struct {
name string
opts utils.OneDriveOpts
expectIncludeLen int
}{
{
name: "no inputs",
opts: utils.OneDriveOpts{
Users: empty,
FileName: empty,
FolderPath: empty,
},
expectIncludeLen: 1,
},
{
name: "single inputs",
opts: utils.OneDriveOpts{
Users: single,
FileName: single,
FolderPath: single,
},
expectIncludeLen: 1,
},
{
name: "multi inputs",
opts: utils.OneDriveOpts{
Users: multi,
FileName: multi,
FolderPath: multi,
},
expectIncludeLen: 1,
},
{
name: "folder contains",
opts: utils.OneDriveOpts{
Users: empty,
FileName: empty,
FolderPath: containsOnly,
},
expectIncludeLen: 1,
},
{
name: "folder prefixes",
opts: utils.OneDriveOpts{
Users: empty,
FileName: empty,
FolderPath: prefixOnly,
},
expectIncludeLen: 1,
},
{
name: "folder prefixes and contains",
opts: utils.OneDriveOpts{
Users: empty,
FileName: empty,
FolderPath: containsAndPrefix,
},
expectIncludeLen: 2,
},
{
name: "folder with just /",
opts: utils.OneDriveOpts{
Users: empty,
FileName: empty,
FolderPath: onlySlash,
},
expectIncludeLen: 1,
},
}
for _, test := range table {
suite.Run(test.name, func() {
sel := utils.IncludeOneDriveRestoreDataSelectors(test.opts)
assert.Len(suite.T(), sel.Includes, test.expectIncludeLen)
})
}
}