name cleanup in selectors and onedrive (#643)
This commit is contained in:
parent
2d88e59cd0
commit
15b12e634d
@ -84,7 +84,7 @@ func (oc *Collection) FullPath() []string {
|
||||
type Item struct {
|
||||
id string
|
||||
data io.ReadCloser
|
||||
info *details.OnedriveInfo
|
||||
info *details.OneDriveInfo
|
||||
}
|
||||
|
||||
func (od *Item) UUID() string {
|
||||
@ -96,7 +96,7 @@ func (od *Item) ToReader() io.ReadCloser {
|
||||
}
|
||||
|
||||
func (od *Item) Info() details.ItemInfo {
|
||||
return details.ItemInfo{Onedrive: od.info}
|
||||
return details.ItemInfo{OneDrive: od.info}
|
||||
}
|
||||
|
||||
// populateItems iterates through items added to the collection
|
||||
@ -119,7 +119,7 @@ func (oc *Collection) populateItems(ctx context.Context) {
|
||||
oc.data <- &Item{
|
||||
id: itemID,
|
||||
data: itemData,
|
||||
info: &details.OnedriveInfo{ItemName: itemName, ParentPath: oc.folderPath},
|
||||
info: &details.OneDriveInfo{ItemName: itemName, ParentPath: oc.folderPath},
|
||||
}
|
||||
}
|
||||
close(oc.data)
|
||||
|
||||
@ -17,30 +17,30 @@ import (
|
||||
"github.com/alcionai/corso/internal/data"
|
||||
)
|
||||
|
||||
type OnedriveCollectionSuite struct {
|
||||
type OneDriveCollectionSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
// Allows `*OnedriveCollectionSuite` to be used as a graph.Service
|
||||
// Allows `*OneDriveCollectionSuite` to be used as a graph.Service
|
||||
// TODO: Implement these methods
|
||||
|
||||
func (suite *OnedriveCollectionSuite) Client() *msgraphsdk.GraphServiceClient {
|
||||
func (suite *OneDriveCollectionSuite) Client() *msgraphsdk.GraphServiceClient {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (suite *OnedriveCollectionSuite) Adapter() *msgraphsdk.GraphRequestAdapter {
|
||||
func (suite *OneDriveCollectionSuite) Adapter() *msgraphsdk.GraphRequestAdapter {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (suite *OnedriveCollectionSuite) ErrPolicy() bool {
|
||||
func (suite *OneDriveCollectionSuite) ErrPolicy() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func TestOnedriveCollectionSuite(t *testing.T) {
|
||||
suite.Run(t, new(OnedriveCollectionSuite))
|
||||
func TestOneDriveCollectionSuite(t *testing.T) {
|
||||
suite.Run(t, new(OneDriveCollectionSuite))
|
||||
}
|
||||
|
||||
func (suite *OnedriveCollectionSuite) TestOnedriveCollection() {
|
||||
func (suite *OneDriveCollectionSuite) TestOneDriveCollection() {
|
||||
folderPath := "dir1/dir2/dir3"
|
||||
coll := NewCollection(folderPath, "fakeDriveID", suite, nil)
|
||||
require.NotNil(suite.T(), coll)
|
||||
@ -76,12 +76,12 @@ func (suite *OnedriveCollectionSuite) TestOnedriveCollection() {
|
||||
|
||||
assert.Equal(suite.T(), testItemData, readData)
|
||||
require.NotNil(suite.T(), readItemInfo.Info())
|
||||
require.NotNil(suite.T(), readItemInfo.Info().Onedrive)
|
||||
assert.Equal(suite.T(), testItemName, readItemInfo.Info().Onedrive.ItemName)
|
||||
assert.Equal(suite.T(), folderPath, readItemInfo.Info().Onedrive.ParentPath)
|
||||
require.NotNil(suite.T(), readItemInfo.Info().OneDrive)
|
||||
assert.Equal(suite.T(), testItemName, readItemInfo.Info().OneDrive.ItemName)
|
||||
assert.Equal(suite.T(), folderPath, readItemInfo.Info().OneDrive.ParentPath)
|
||||
}
|
||||
|
||||
func (suite *OnedriveCollectionSuite) TestOnedriveCollectionReadError() {
|
||||
func (suite *OneDriveCollectionSuite) TestOneDriveCollectionReadError() {
|
||||
coll := NewCollection("folderPath", "fakeDriveID", suite, nil)
|
||||
coll.Add("testItemID")
|
||||
|
||||
|
||||
@ -94,8 +94,8 @@ func (de DetailsEntry) Headers() []string {
|
||||
if de.ItemInfo.Sharepoint != nil {
|
||||
hs = append(hs, de.ItemInfo.Sharepoint.Headers()...)
|
||||
}
|
||||
if de.ItemInfo.Onedrive != nil {
|
||||
hs = append(hs, de.ItemInfo.Onedrive.Headers()...)
|
||||
if de.ItemInfo.OneDrive != nil {
|
||||
hs = append(hs, de.ItemInfo.OneDrive.Headers()...)
|
||||
}
|
||||
return hs
|
||||
}
|
||||
@ -109,8 +109,8 @@ func (de DetailsEntry) Values() []string {
|
||||
if de.ItemInfo.Sharepoint != nil {
|
||||
vs = append(vs, de.ItemInfo.Sharepoint.Values()...)
|
||||
}
|
||||
if de.ItemInfo.Onedrive != nil {
|
||||
vs = append(vs, de.ItemInfo.Onedrive.Values()...)
|
||||
if de.ItemInfo.OneDrive != nil {
|
||||
vs = append(vs, de.ItemInfo.OneDrive.Values()...)
|
||||
}
|
||||
return vs
|
||||
}
|
||||
@ -120,7 +120,7 @@ func (de DetailsEntry) Values() []string {
|
||||
type ItemInfo struct {
|
||||
Exchange *ExchangeInfo `json:"exchange,omitempty"`
|
||||
Sharepoint *SharepointInfo `json:"sharepoint,omitempty"`
|
||||
Onedrive *OnedriveInfo `json:"onedrive,omitempty"`
|
||||
OneDrive *OneDriveInfo `json:"oneDrive,omitempty"`
|
||||
}
|
||||
|
||||
// ExchangeInfo describes an exchange item
|
||||
@ -162,20 +162,20 @@ func (s SharepointInfo) Values() []string {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
// OnedriveInfo describes a onedrive item
|
||||
type OnedriveInfo struct {
|
||||
// OneDriveInfo describes a oneDrive item
|
||||
type OneDriveInfo struct {
|
||||
ParentPath string `json:"parentPath"`
|
||||
ItemName string `json:"itemName"`
|
||||
}
|
||||
|
||||
// Headers returns the human-readable names of properties in a OnedriveInfo
|
||||
// Headers returns the human-readable names of properties in a OneDriveInfo
|
||||
// for printing out to a terminal in a columnar display.
|
||||
func (oi OnedriveInfo) Headers() []string {
|
||||
func (oi OneDriveInfo) Headers() []string {
|
||||
return []string{"ItemName", "ParentPath"}
|
||||
}
|
||||
|
||||
// Values returns the values matching the Headers list for printing
|
||||
// out to a terminal in a columnar display.
|
||||
func (oi OnedriveInfo) Values() []string {
|
||||
func (oi OneDriveInfo) Values() []string {
|
||||
return []string{oi.ItemName, oi.ParentPath}
|
||||
}
|
||||
|
||||
@ -160,11 +160,11 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||
expectVs: []string{"reporef"},
|
||||
},
|
||||
{
|
||||
name: "onedrive info",
|
||||
name: "oneDrive info",
|
||||
entry: details.DetailsEntry{
|
||||
RepoRef: "reporef",
|
||||
ItemInfo: details.ItemInfo{
|
||||
Onedrive: &details.OnedriveInfo{
|
||||
OneDrive: &details.OneDriveInfo{
|
||||
ItemName: "itemName",
|
||||
ParentPath: "parentPath",
|
||||
},
|
||||
|
||||
@ -145,9 +145,9 @@ func (s *exchange) Scopes() []ExchangeScope {
|
||||
|
||||
// DiscreteScopes retrieves the list of exchangeScopes in the selector.
|
||||
// If any Include scope's User category is set to Any, replaces that
|
||||
// scope's value with the list of userIDs instead.
|
||||
func (s *exchange) DiscreteScopes(userIDs []string) []ExchangeScope {
|
||||
return discreteScopes[ExchangeScope](s.Selector, ExchangeUser, userIDs)
|
||||
// scope's value with the list of userPNs instead.
|
||||
func (s *exchange) DiscreteScopes(userPNs []string) []ExchangeScope {
|
||||
return discreteScopes[ExchangeScope](s.Selector, ExchangeUser, userPNs)
|
||||
}
|
||||
|
||||
// -------------------
|
||||
@ -440,12 +440,12 @@ func (ec exchangeCategory) unknownCat() categorizer {
|
||||
// transforms a path to a map of identified properties.
|
||||
// TODO: this should use service-specific funcs in the Paths pkg. Instead of
|
||||
// peeking at the path directly, the caller should compare against values like
|
||||
// path.UserID() and path.Folders().
|
||||
// path.UserPN() and path.Folders().
|
||||
//
|
||||
// Malformed (ie, short len) paths will return incomplete results.
|
||||
// Example:
|
||||
// [tenantID, userID, "mail", mailFolder, mailID]
|
||||
// => {exchUser: userID, exchMailFolder: mailFolder, exchMail: mailID}
|
||||
// [tenantID, userPN, "mail", mailFolder, mailID]
|
||||
// => {exchUser: userPN, exchMailFolder: mailFolder, exchMail: mailID}
|
||||
func (ec exchangeCategory) pathValues(path []string) map[categorizer]string {
|
||||
m := map[categorizer]string{}
|
||||
if len(path) < 2 {
|
||||
|
||||
@ -12,22 +12,22 @@ import (
|
||||
"github.com/alcionai/corso/pkg/backup/details"
|
||||
)
|
||||
|
||||
type ExchangeSourceSuite struct {
|
||||
type ExchangeSelectorSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestExchangeSourceSuite(t *testing.T) {
|
||||
suite.Run(t, new(ExchangeSourceSuite))
|
||||
func TestExchangeSelectorSuite(t *testing.T) {
|
||||
suite.Run(t, new(ExchangeSelectorSuite))
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestNewExchangeBackup() {
|
||||
func (suite *ExchangeSelectorSuite) TestNewExchangeBackup() {
|
||||
t := suite.T()
|
||||
eb := NewExchangeBackup()
|
||||
assert.Equal(t, eb.Service, ServiceExchange)
|
||||
assert.NotZero(t, eb.Scopes())
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestToExchangeBackup() {
|
||||
func (suite *ExchangeSelectorSuite) TestToExchangeBackup() {
|
||||
t := suite.T()
|
||||
eb := NewExchangeBackup()
|
||||
s := eb.Selector
|
||||
@ -37,14 +37,14 @@ func (suite *ExchangeSourceSuite) TestToExchangeBackup() {
|
||||
assert.NotZero(t, eb.Scopes())
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestNewExchangeRestore() {
|
||||
func (suite *ExchangeSelectorSuite) TestNewExchangeRestore() {
|
||||
t := suite.T()
|
||||
er := NewExchangeRestore()
|
||||
assert.Equal(t, er.Service, ServiceExchange)
|
||||
assert.NotZero(t, er.Scopes())
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestToExchangeRestore() {
|
||||
func (suite *ExchangeSelectorSuite) TestToExchangeRestore() {
|
||||
t := suite.T()
|
||||
eb := NewExchangeRestore()
|
||||
s := eb.Selector
|
||||
@ -54,7 +54,7 @@ func (suite *ExchangeSourceSuite) TestToExchangeRestore() {
|
||||
assert.NotZero(t, eb.Scopes())
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Contacts() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_Contacts() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -75,7 +75,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Contacts() {
|
||||
assert.Equal(t, scope[ExchangeContact.String()], join(c1, c2))
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Contacts() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_Contacts() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -98,7 +98,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Contacts() {
|
||||
assert.Equal(t, sel.Scopes()[0].Category(), ExchangeContact)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_ContactFolders() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_ContactFolders() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -118,7 +118,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_ContactFolders()
|
||||
assert.Equal(t, scope[ExchangeContact.String()], AnyTgt)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_ContactFolders() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_ContactFolders() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -140,7 +140,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_ContactFolders()
|
||||
assert.Equal(t, sel.Scopes()[0].Category(), ExchangeContactFolder)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Events() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_Events() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -159,7 +159,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Events() {
|
||||
assert.Equal(t, scope[ExchangeEvent.String()], join(e1, e2))
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Events() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_Events() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -180,7 +180,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Events() {
|
||||
assert.Equal(t, sel.Scopes()[0].Category(), ExchangeEvent)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Mails() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_Mails() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -201,7 +201,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Mails() {
|
||||
assert.Equal(t, scope[ExchangeMail.String()], join(m1, m2))
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Mails() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_Mails() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -224,7 +224,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Mails() {
|
||||
assert.Equal(t, sel.Scopes()[0].Category(), ExchangeMail)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_MailFolders() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_MailFolders() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -244,7 +244,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_MailFolders() {
|
||||
assert.Equal(t, scope[ExchangeMail.String()], AnyTgt)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_MailFolders() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_MailFolders() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -266,7 +266,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_MailFolders() {
|
||||
assert.Equal(t, sel.Scopes()[0].Category(), ExchangeMailFolder)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Users() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Exclude_Users() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -295,7 +295,7 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Exclude_Users() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Users() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeSelector_Include_Users() {
|
||||
t := suite.T()
|
||||
sel := NewExchangeBackup()
|
||||
|
||||
@ -324,13 +324,13 @@ func (suite *ExchangeSourceSuite) TestExchangeSelector_Include_Users() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestNewExchangeDestination() {
|
||||
func (suite *ExchangeSelectorSuite) TestNewExchangeDestination() {
|
||||
t := suite.T()
|
||||
dest := NewExchangeDestination()
|
||||
assert.Len(t, dest, 0)
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeDestination_Set() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeDestination_Set() {
|
||||
dest := NewExchangeDestination()
|
||||
|
||||
table := []exchangeCategory{
|
||||
@ -352,7 +352,7 @@ func (suite *ExchangeSourceSuite) TestExchangeDestination_Set() {
|
||||
assert.NoError(suite.T(), dest.Set(ExchangeUser, ""))
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeDestination_GetOrDefault() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeDestination_GetOrDefault() {
|
||||
dest := NewExchangeDestination()
|
||||
|
||||
table := []exchangeCategory{
|
||||
@ -373,7 +373,7 @@ func (suite *ExchangeSourceSuite) TestExchangeDestination_GetOrDefault() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeBackup_Scopes() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeBackup_Scopes() {
|
||||
eb := NewExchangeBackup()
|
||||
eb.Include(eb.Users(Any()))
|
||||
|
||||
@ -397,7 +397,7 @@ func (suite *ExchangeSourceSuite) TestExchangeBackup_Scopes() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeBackup_DiscreteScopes() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeBackup_DiscreteScopes() {
|
||||
usrs := []string{"u1", "u2"}
|
||||
table := []struct {
|
||||
name string
|
||||
@ -438,7 +438,7 @@ func (suite *ExchangeSourceSuite) TestExchangeBackup_DiscreteScopes() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeScope_Category() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeScope_Category() {
|
||||
table := []struct {
|
||||
is exchangeCategory
|
||||
expect exchangeCategory
|
||||
@ -469,7 +469,7 @@ func (suite *ExchangeSourceSuite) TestExchangeScope_Category() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeScope_IncludesCategory() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeScope_IncludesCategory() {
|
||||
table := []struct {
|
||||
is exchangeCategory
|
||||
expect exchangeCategory
|
||||
@ -501,7 +501,7 @@ func (suite *ExchangeSourceSuite) TestExchangeScope_IncludesCategory() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeScope_Get() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeScope_Get() {
|
||||
eb := NewExchangeBackup()
|
||||
eb.Include(eb.Users(Any()))
|
||||
|
||||
@ -536,7 +536,7 @@ func (suite *ExchangeSourceSuite) TestExchangeScope_Get() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeScope_MatchesInfo() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesInfo() {
|
||||
es := NewExchangeRestore()
|
||||
const (
|
||||
sender = "smarf@2many.cooks"
|
||||
@ -584,7 +584,7 @@ func (suite *ExchangeSourceSuite) TestExchangeScope_MatchesInfo() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeScope_MatchesPath() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
|
||||
const (
|
||||
usr = "userID"
|
||||
fld = "mailFolder"
|
||||
@ -632,7 +632,7 @@ func (suite *ExchangeSourceSuite) TestExchangeScope_MatchesPath() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestIdPath() {
|
||||
func (suite *ExchangeSelectorSuite) TestIdPath() {
|
||||
table := []struct {
|
||||
cat exchangeCategory
|
||||
path []string
|
||||
@ -677,7 +677,7 @@ func (suite *ExchangeSourceSuite) TestIdPath() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeRestore_Reduce() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
|
||||
makeDeets := func(refs ...string) *details.Details {
|
||||
deets := &details.Details{
|
||||
DetailsModel: details.DetailsModel{
|
||||
@ -829,7 +829,7 @@ func (suite *ExchangeSourceSuite) TestExchangeRestore_Reduce() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestScopesByCategory() {
|
||||
func (suite *ExchangeSelectorSuite) TestScopesByCategory() {
|
||||
var (
|
||||
es = NewExchangeRestore()
|
||||
users = es.Users(Any())
|
||||
@ -878,7 +878,7 @@ func (suite *ExchangeSourceSuite) TestScopesByCategory() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestPasses() {
|
||||
func (suite *ExchangeSelectorSuite) TestPasses() {
|
||||
deets := details.DetailsEntry{}
|
||||
const (
|
||||
mid = "mailID"
|
||||
@ -932,7 +932,7 @@ func (suite *ExchangeSourceSuite) TestPasses() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestContains() {
|
||||
func (suite *ExchangeSelectorSuite) TestContains() {
|
||||
target := "fnords"
|
||||
var (
|
||||
es = NewExchangeRestore()
|
||||
@ -969,7 +969,7 @@ func (suite *ExchangeSourceSuite) TestContains() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestIsAny() {
|
||||
func (suite *ExchangeSelectorSuite) TestIsAny() {
|
||||
var (
|
||||
es = NewExchangeRestore()
|
||||
anyUser = setScopesToDefault(es.Users(Any()))
|
||||
@ -1003,7 +1003,7 @@ func (suite *ExchangeSourceSuite) TestIsAny() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeCategory_leafCat() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeCategory_leafCat() {
|
||||
table := []struct {
|
||||
cat exchangeCategory
|
||||
expect exchangeCategory
|
||||
@ -1023,7 +1023,7 @@ func (suite *ExchangeSourceSuite) TestExchangeCategory_leafCat() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeCategory_PathValues() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeCategory_PathValues() {
|
||||
contactPath := []string{"ten", "user", "contact", "cfolder", "contactitem"}
|
||||
contactMap := map[categorizer]string{
|
||||
ExchangeUser: contactPath[1],
|
||||
@ -1059,7 +1059,7 @@ func (suite *ExchangeSourceSuite) TestExchangeCategory_PathValues() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *ExchangeSourceSuite) TestExchangeCategory_PathKeys() {
|
||||
func (suite *ExchangeSelectorSuite) TestExchangeCategory_PathKeys() {
|
||||
contact := []categorizer{ExchangeUser, ExchangeContactFolder, ExchangeContact}
|
||||
event := []categorizer{ExchangeUser, ExchangeEvent}
|
||||
mail := []categorizer{ExchangeUser, ExchangeMailFolder, ExchangeMail}
|
||||
|
||||
@ -9,9 +9,9 @@ import (
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
type (
|
||||
// onedrive provides an api for selecting
|
||||
// oneDrive provides an api for selecting
|
||||
// data scopes applicable to the OneDrive service.
|
||||
onedrive struct {
|
||||
oneDrive struct {
|
||||
Selector
|
||||
}
|
||||
|
||||
@ -19,14 +19,14 @@ type (
|
||||
// data scopes applicable to the OneDrive service,
|
||||
// plus backup-specific methods.
|
||||
OneDriveBackup struct {
|
||||
onedrive
|
||||
oneDrive
|
||||
}
|
||||
)
|
||||
|
||||
// NewOneDriveBackup produces a new Selector with the service set to ServiceOneDrive.
|
||||
func NewOneDriveBackup() *OneDriveBackup {
|
||||
src := OneDriveBackup{
|
||||
onedrive{
|
||||
oneDrive{
|
||||
newSelector(ServiceOneDrive),
|
||||
},
|
||||
}
|
||||
@ -39,7 +39,7 @@ func (s Selector) ToOneDriveBackup() (*OneDriveBackup, error) {
|
||||
if s.Service != ServiceOneDrive {
|
||||
return nil, badCastErr(ServiceOneDrive, s.Service)
|
||||
}
|
||||
src := OneDriveBackup{onedrive{s}}
|
||||
src := OneDriveBackup{oneDrive{s}}
|
||||
return &src, nil
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ func (s Selector) ToOneDriveBackup() (*OneDriveBackup, error) {
|
||||
// child properties.
|
||||
// ex: User(u1) automatically cascades to all folders and files owned
|
||||
// by u1.
|
||||
func (s *onedrive) Include(scopes ...[]OneDriveScope) {
|
||||
func (s *oneDrive) Include(scopes ...[]OneDriveScope) {
|
||||
s.Includes = appendScopes(s.Includes, scopes...)
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func (s *onedrive) Include(scopes ...[]OneDriveScope) {
|
||||
// child properties.
|
||||
// ex: User(u1) automatically cascades to all folders and files owned
|
||||
// by u1.
|
||||
func (s *onedrive) Exclude(scopes ...[]OneDriveScope) {
|
||||
func (s *oneDrive) Exclude(scopes ...[]OneDriveScope) {
|
||||
s.Excludes = appendScopes(s.Excludes, scopes...)
|
||||
}
|
||||
|
||||
@ -98,16 +98,16 @@ func (s *onedrive) Exclude(scopes ...[]OneDriveScope) {
|
||||
// child properties.
|
||||
// ex: User(u1) automatically cascades to all folders and files owned
|
||||
// by u1.
|
||||
func (s *onedrive) Filter(scopes ...[]OneDriveScope) {
|
||||
func (s *oneDrive) Filter(scopes ...[]OneDriveScope) {
|
||||
s.Filters = appendScopes(s.Filters, scopes...)
|
||||
}
|
||||
|
||||
// Produces one or more onedrive user scopes.
|
||||
// Produces one or more oneDrive user scopes.
|
||||
// One scope is created per user entry.
|
||||
// If any slice contains selectors.Any, that slice is reduced to [selectors.Any]
|
||||
// If any slice contains selectors.None, that slice is reduced to [selectors.None]
|
||||
// If any slice is empty, it defaults to [selectors.None]
|
||||
func (s *onedrive) Users(users []string) []OneDriveScope {
|
||||
func (s *oneDrive) Users(users []string) []OneDriveScope {
|
||||
users = normalize(users)
|
||||
scopes := []OneDriveScope{}
|
||||
for _, u := range users {
|
||||
@ -116,37 +116,37 @@ func (s *onedrive) Users(users []string) []OneDriveScope {
|
||||
return scopes
|
||||
}
|
||||
|
||||
// Scopes retrieves the list of onedriveScopes in the selector.
|
||||
func (s *onedrive) Scopes() []OneDriveScope {
|
||||
// Scopes retrieves the list of oneDriveScopes in the selector.
|
||||
func (s *oneDrive) Scopes() []OneDriveScope {
|
||||
return scopes[OneDriveScope](s.Selector)
|
||||
}
|
||||
|
||||
// DiscreteScopes retrieves the list of onedriveScopes in the selector.
|
||||
// DiscreteScopes retrieves the list of oneDriveScopes in the selector.
|
||||
// If any Include scope's User category is set to Any, replaces that
|
||||
// scope's value with the list of userIDs instead.
|
||||
func (s *onedrive) DiscreteScopes(userIDs []string) []OneDriveScope {
|
||||
return discreteScopes[OneDriveScope](s.Selector, OneDriveUser, userIDs)
|
||||
// scope's value with the list of userPNs instead.
|
||||
func (s *oneDrive) DiscreteScopes(userPNs []string) []OneDriveScope {
|
||||
return discreteScopes[OneDriveScope](s.Selector, OneDriveUser, userPNs)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Categories
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// onedriveCategory enumerates the type of the lowest level
|
||||
// oneDriveCategory enumerates the type of the lowest level
|
||||
// of data () in a scope.
|
||||
type onedriveCategory int
|
||||
type oneDriveCategory int
|
||||
|
||||
// interface compliance checks
|
||||
var _ categorizer = OneDriveCategoryUnknown
|
||||
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type=onedriveCategory
|
||||
//go:generate go run golang.org/x/tools/cmd/stringer -type=oneDriveCategory
|
||||
const (
|
||||
OneDriveCategoryUnknown onedriveCategory = iota
|
||||
OneDriveCategoryUnknown oneDriveCategory = iota
|
||||
// types of data identified by OneDrive
|
||||
OneDriveUser
|
||||
)
|
||||
|
||||
func onedriveCatAtoI(s string) onedriveCategory {
|
||||
func oneDriveCatAtoI(s string) oneDriveCategory {
|
||||
switch s {
|
||||
// data types
|
||||
case OneDriveUser.String():
|
||||
@ -169,30 +169,30 @@ var oneDrivePathSet = map[categorizer][]categorizer{
|
||||
// (ex: Unknown), the receiver itself is returned.
|
||||
// Ex: ServiceTypeFolder.leafCat() => ServiceTypeItem
|
||||
// Ex: ServiceUser.leafCat() => ServiceUser
|
||||
func (c onedriveCategory) leafCat() categorizer {
|
||||
func (c oneDriveCategory) leafCat() categorizer {
|
||||
return c
|
||||
}
|
||||
|
||||
// rootCat returns the root category type.
|
||||
func (c onedriveCategory) rootCat() categorizer {
|
||||
func (c oneDriveCategory) rootCat() categorizer {
|
||||
return OneDriveUser
|
||||
}
|
||||
|
||||
// unknownCat returns the unknown category type.
|
||||
func (c onedriveCategory) unknownCat() categorizer {
|
||||
func (c oneDriveCategory) unknownCat() categorizer {
|
||||
return OneDriveCategoryUnknown
|
||||
}
|
||||
|
||||
// pathValues transforms a path to a map of identified properties.
|
||||
// TODO: this should use service-specific funcs in the Paths pkg. Instead of
|
||||
// peeking at the path directly, the caller should compare against values like
|
||||
// path.UserID() and path.Folders().
|
||||
// path.UserPN() and path.Folders().
|
||||
//
|
||||
// Malformed (ie, short len) paths will return incomplete results.
|
||||
// Example:
|
||||
// [tenantID, userID, "files", folder, fileID]
|
||||
// => {odUser: userID, odFolder: folder, odFileID: fileID}
|
||||
func (c onedriveCategory) pathValues(path []string) map[categorizer]string {
|
||||
// [tenantID, userPN, "files", folder, fileID]
|
||||
// => {odUser: userPN, odFolder: folder, odFileID: fileID}
|
||||
func (c oneDriveCategory) pathValues(path []string) map[categorizer]string {
|
||||
m := map[categorizer]string{}
|
||||
if len(path) < 2 {
|
||||
return m
|
||||
@ -211,7 +211,7 @@ func (c onedriveCategory) pathValues(path []string) map[categorizer]string {
|
||||
}
|
||||
|
||||
// pathKeys returns the path keys recognized by the receiver's leaf type.
|
||||
func (c onedriveCategory) pathKeys() []categorizer {
|
||||
func (c oneDriveCategory) pathKeys() []categorizer {
|
||||
return oneDrivePathSet[c.leafCat()]
|
||||
}
|
||||
|
||||
@ -227,8 +227,8 @@ type OneDriveScope scope
|
||||
var _ scoper = &OneDriveScope{}
|
||||
|
||||
// Category describes the type of the data in scope.
|
||||
func (s OneDriveScope) Category() onedriveCategory {
|
||||
return onedriveCatAtoI(s[scopeKeyCategory])
|
||||
func (s OneDriveScope) Category() oneDriveCategory {
|
||||
return oneDriveCatAtoI(s[scopeKeyCategory])
|
||||
}
|
||||
|
||||
// categorizer type is a generic wrapper around Category.
|
||||
@ -239,8 +239,8 @@ func (s OneDriveScope) categorizer() categorizer {
|
||||
|
||||
// FilterCategory returns the category enum of the scope filter.
|
||||
// If the scope is not a filter type, returns OneDriveUnknownCategory.
|
||||
func (s OneDriveScope) FilterCategory() onedriveCategory {
|
||||
return onedriveCatAtoI(s[scopeKeyInfoFilter])
|
||||
func (s OneDriveScope) FilterCategory() oneDriveCategory {
|
||||
return oneDriveCatAtoI(s[scopeKeyInfoFilter])
|
||||
}
|
||||
|
||||
// Granularity describes the granularity (directory || item)
|
||||
@ -253,31 +253,31 @@ func (s OneDriveScope) Granularity() string {
|
||||
// certain category of data.
|
||||
// Ex: to check if the scope includes file data:
|
||||
// s.IncludesCategory(selector.OneDriveFile)
|
||||
func (s OneDriveScope) IncludesCategory(cat onedriveCategory) bool {
|
||||
func (s OneDriveScope) IncludesCategory(cat oneDriveCategory) bool {
|
||||
return categoryMatches(s.Category(), cat)
|
||||
}
|
||||
|
||||
// Contains returns true if the category is included in the scope's
|
||||
// data type, and the target string is included in the scope.
|
||||
func (s OneDriveScope) Contains(cat onedriveCategory, target string) bool {
|
||||
func (s OneDriveScope) Contains(cat oneDriveCategory, target string) bool {
|
||||
return contains(s, cat, target)
|
||||
}
|
||||
|
||||
// returns true if the category is included in the scope's data type,
|
||||
// and the value is set to Any().
|
||||
func (s OneDriveScope) IsAny(cat onedriveCategory) bool {
|
||||
func (s OneDriveScope) IsAny(cat oneDriveCategory) bool {
|
||||
return isAnyTarget(s, cat)
|
||||
}
|
||||
|
||||
// Get returns the data category in the scope. If the scope
|
||||
// contains all data types for a user, it'll return the
|
||||
// OneDriveUser category.
|
||||
func (s OneDriveScope) Get(cat onedriveCategory) []string {
|
||||
func (s OneDriveScope) Get(cat oneDriveCategory) []string {
|
||||
return getCatValue(s, cat)
|
||||
}
|
||||
|
||||
// sets a value by category to the scope. Only intended for internal use.
|
||||
// func (s OneDriveScope) set(cat onedriveCategory, v string) OneDriveScope {
|
||||
// func (s OneDriveScope) set(cat oneDriveCategory, v string) OneDriveScope {
|
||||
// return set(s, cat, v)
|
||||
// }
|
||||
|
||||
@ -286,19 +286,19 @@ func (s OneDriveScope) setDefaults() {
|
||||
// no-op while no child scope types below user are identified
|
||||
}
|
||||
|
||||
// matchesEntry returns true if either the path or the info in the onedriveEntry matches the scope details.
|
||||
// matchesEntry returns true if either the path or the info in the oneDriveEntry matches the scope details.
|
||||
func (s OneDriveScope) matchesEntry(
|
||||
cat categorizer,
|
||||
pathValues map[categorizer]string,
|
||||
entry details.DetailsEntry,
|
||||
) bool {
|
||||
// matchesPathValues can be handled generically, thanks to SCIENCE.
|
||||
return matchesPathValues(s, cat.(onedriveCategory), pathValues) || s.matchesInfo(entry.Onedrive)
|
||||
return matchesPathValues(s, cat.(oneDriveCategory), pathValues) || s.matchesInfo(entry.OneDrive)
|
||||
}
|
||||
|
||||
// matchesInfo handles the standard behavior when comparing a scope and an onedriveInfo
|
||||
// matchesInfo handles the standard behavior when comparing a scope and an oneDriveInfo
|
||||
// returns true if the scope and info match for the provided category.
|
||||
func (s OneDriveScope) matchesInfo(info *details.OnedriveInfo) bool {
|
||||
func (s OneDriveScope) matchesInfo(info *details.OneDriveInfo) bool {
|
||||
// we need values to match against
|
||||
if info == nil {
|
||||
return false
|
||||
@ -318,7 +318,7 @@ func (s OneDriveScope) matchesInfo(info *details.OnedriveInfo) bool {
|
||||
// any of the targets for a given info filter may succeed.
|
||||
for _, target := range targets {
|
||||
switch filterCat {
|
||||
// TODO: populate onedrive filter checks
|
||||
// TODO: populate oneDrive filter checks
|
||||
default:
|
||||
return target != NoneTgt
|
||||
}
|
||||
|
||||
@ -8,22 +8,22 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
type OnedriveSourceSuite struct {
|
||||
type OneDriveSelectorSuite struct {
|
||||
suite.Suite
|
||||
}
|
||||
|
||||
func TestOnedriveSourceSuite(t *testing.T) {
|
||||
suite.Run(t, new(OnedriveSourceSuite))
|
||||
func TestOneDriveSelectorSuite(t *testing.T) {
|
||||
suite.Run(t, new(OneDriveSelectorSuite))
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestNewOnedriveBackup() {
|
||||
func (suite *OneDriveSelectorSuite) TestNewOneDriveBackup() {
|
||||
t := suite.T()
|
||||
ob := NewOneDriveBackup()
|
||||
assert.Equal(t, ob.Service, ServiceOneDrive)
|
||||
assert.NotZero(t, ob.Scopes())
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestToOnedriveBackup() {
|
||||
func (suite *OneDriveSelectorSuite) TestToOneDriveBackup() {
|
||||
t := suite.T()
|
||||
ob := NewOneDriveBackup()
|
||||
s := ob.Selector
|
||||
@ -33,7 +33,7 @@ func (suite *OnedriveSourceSuite) TestToOnedriveBackup() {
|
||||
assert.NotZero(t, ob.Scopes())
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestOnedriveBackup_DiscreteScopes() {
|
||||
func (suite *OneDriveSelectorSuite) TestOneDriveBackup_DiscreteScopes() {
|
||||
usrs := []string{"u1", "u2"}
|
||||
table := []struct {
|
||||
name string
|
||||
@ -74,7 +74,7 @@ func (suite *OnedriveSourceSuite) TestOnedriveBackup_DiscreteScopes() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestOnedriveSelector_Users() {
|
||||
func (suite *OneDriveSelectorSuite) TestOneDriveSelector_Users() {
|
||||
t := suite.T()
|
||||
sel := NewOneDriveBackup()
|
||||
|
||||
@ -112,7 +112,7 @@ func (suite *OnedriveSourceSuite) TestOnedriveSelector_Users() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestOneDriveSelector_Include_Users() {
|
||||
func (suite *OneDriveSelectorSuite) TestOneDriveSelector_Include_Users() {
|
||||
t := suite.T()
|
||||
sel := NewOneDriveBackup()
|
||||
|
||||
@ -130,7 +130,7 @@ func (suite *OnedriveSourceSuite) TestOneDriveSelector_Include_Users() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *OnedriveSourceSuite) TestOneDriveSelector_Exclude_Users() {
|
||||
func (suite *OneDriveSelectorSuite) TestOneDriveSelector_Exclude_Users() {
|
||||
t := suite.T()
|
||||
sel := NewOneDriveBackup()
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
// Code generated by "stringer -type=onedriveCategory"; DO NOT EDIT.
|
||||
// Code generated by "stringer -type=oneDriveCategory"; DO NOT EDIT.
|
||||
|
||||
package selectors
|
||||
|
||||
@ -12,13 +12,13 @@ func _() {
|
||||
_ = x[OneDriveUser-1]
|
||||
}
|
||||
|
||||
const _onedriveCategory_name = "OneDriveCategoryUnknownOneDriveUser"
|
||||
const _oneDriveCategory_name = "OneDriveCategoryUnknownOneDriveUser"
|
||||
|
||||
var _onedriveCategory_index = [...]uint8{0, 23, 35}
|
||||
var _oneDriveCategory_index = [...]uint8{0, 23, 35}
|
||||
|
||||
func (i onedriveCategory) String() string {
|
||||
if i < 0 || i >= onedriveCategory(len(_onedriveCategory_index)-1) {
|
||||
return "onedriveCategory(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
func (i oneDriveCategory) String() string {
|
||||
if i < 0 || i >= oneDriveCategory(len(_oneDriveCategory_index)-1) {
|
||||
return "oneDriveCategory(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _onedriveCategory_name[_onedriveCategory_index[i]:_onedriveCategory_index[i+1]]
|
||||
return _oneDriveCategory_name[_oneDriveCategory_index[i]:_oneDriveCategory_index[i+1]]
|
||||
}
|
||||
|
||||
@ -10,11 +10,12 @@ func _() {
|
||||
var x [1]struct{}
|
||||
_ = x[ServiceUnknown-0]
|
||||
_ = x[ServiceExchange-1]
|
||||
_ = x[ServiceOneDrive-2]
|
||||
}
|
||||
|
||||
const _service_name = "Unknown ServiceExchange"
|
||||
const _service_name = "Unknown ServiceExchangeOneDrive"
|
||||
|
||||
var _service_index = [...]uint8{0, 15, 23}
|
||||
var _service_index = [...]uint8{0, 15, 23, 31}
|
||||
|
||||
func (i service) String() string {
|
||||
if i < 0 || i >= service(len(_service_index)-1) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user