Remove selector pathType const in favor of path package const (#757)
* Remove pathType const The path package const only provides information on the category, not the service for the path. * Fix var name/package name clashes
This commit is contained in:
parent
110e874e5b
commit
dc0c7e49c4
@ -4,6 +4,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
|
"github.com/alcionai/corso/src/internal/path"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/filters"
|
"github.com/alcionai/corso/src/pkg/filters"
|
||||||
)
|
)
|
||||||
@ -558,27 +559,27 @@ func (ec exchangeCategory) unknownCat() categorizer {
|
|||||||
// Example:
|
// Example:
|
||||||
// [tenantID, userPN, "mail", mailFolder, mailID]
|
// [tenantID, userPN, "mail", mailFolder, mailID]
|
||||||
// => {exchUser: userPN, exchMailFolder: mailFolder, exchMail: mailID}
|
// => {exchUser: userPN, exchMailFolder: mailFolder, exchMail: mailID}
|
||||||
func (ec exchangeCategory) pathValues(path []string) map[categorizer]string {
|
func (ec exchangeCategory) pathValues(p []string) map[categorizer]string {
|
||||||
m := map[categorizer]string{}
|
m := map[categorizer]string{}
|
||||||
if len(path) < 5 {
|
if len(p) < 5 {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ec {
|
switch ec {
|
||||||
case ExchangeContact:
|
case ExchangeContact:
|
||||||
m[ExchangeUser] = path[1]
|
m[ExchangeUser] = p[1]
|
||||||
m[ExchangeContactFolder] = path[3]
|
m[ExchangeContactFolder] = p[3]
|
||||||
m[ExchangeContact] = path[4]
|
m[ExchangeContact] = p[4]
|
||||||
|
|
||||||
case ExchangeEvent:
|
case ExchangeEvent:
|
||||||
m[ExchangeUser] = path[1]
|
m[ExchangeUser] = p[1]
|
||||||
m[ExchangeEventCalendar] = path[3]
|
m[ExchangeEventCalendar] = p[3]
|
||||||
m[ExchangeEvent] = path[4]
|
m[ExchangeEvent] = p[4]
|
||||||
|
|
||||||
case ExchangeMail:
|
case ExchangeMail:
|
||||||
m[ExchangeUser] = path[2]
|
m[ExchangeUser] = p[2]
|
||||||
m[ExchangeMailFolder] = path[4]
|
m[ExchangeMailFolder] = p[4]
|
||||||
m[ExchangeMail] = path[5]
|
m[ExchangeMail] = p[5]
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
@ -680,10 +681,10 @@ func (s exchange) Reduce(deets *details.Details) *details.Details {
|
|||||||
return reduce[ExchangeScope](
|
return reduce[ExchangeScope](
|
||||||
deets,
|
deets,
|
||||||
s.Selector,
|
s.Selector,
|
||||||
map[pathType]exchangeCategory{
|
map[path.CategoryType]exchangeCategory{
|
||||||
exchangeContactPath: ExchangeContact,
|
path.ContactsCategory: ExchangeContact,
|
||||||
exchangeEventPath: ExchangeEvent,
|
path.EventsCategory: ExchangeEvent,
|
||||||
exchangeMailPath: ExchangeMail,
|
path.EmailCategory: ExchangeMail,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1054,10 +1054,10 @@ func (suite *ExchangeSelectorSuite) TestScopesByCategory() {
|
|||||||
|
|
||||||
return mss
|
return mss
|
||||||
}
|
}
|
||||||
cats := map[pathType]exchangeCategory{
|
cats := map[path.CategoryType]exchangeCategory{
|
||||||
exchangeContactPath: ExchangeContact,
|
path.ContactsCategory: ExchangeContact,
|
||||||
exchangeEventPath: ExchangeEvent,
|
path.EventsCategory: ExchangeEvent,
|
||||||
exchangeMailPath: ExchangeMail,
|
path.EmailCategory: ExchangeMail,
|
||||||
}
|
}
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
|
|||||||
@ -209,7 +209,7 @@ func isAnyTarget[T scopeT, C categoryT](s T, cat C) bool {
|
|||||||
func reduce[T scopeT, C categoryT](
|
func reduce[T scopeT, C categoryT](
|
||||||
deets *details.Details,
|
deets *details.Details,
|
||||||
s Selector,
|
s Selector,
|
||||||
dataCategories map[pathType]C,
|
dataCategories map[path.CategoryType]C,
|
||||||
) *details.Details {
|
) *details.Details {
|
||||||
if deets == nil {
|
if deets == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -251,50 +251,32 @@ func reduce[T scopeT, C categoryT](
|
|||||||
return reduced
|
return reduced
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this is a hack. We don't want these values declared here- it will get
|
|
||||||
// unwieldy to have all of them for all services. They should be declared in
|
|
||||||
// paths, since that's where service- and data-type-specific assertions are owned.
|
|
||||||
type pathType int
|
|
||||||
|
|
||||||
const (
|
|
||||||
unknownPathType pathType = iota
|
|
||||||
exchangeEventPath
|
|
||||||
exchangeContactPath
|
|
||||||
exchangeMailPath
|
|
||||||
)
|
|
||||||
|
|
||||||
// return the service data type of the path.
|
// return the service data type of the path.
|
||||||
// TODO: this is a hack. We don't want this identification to occur in this
|
// TODO: this is a hack. We don't want this identification to occur in this
|
||||||
// package. It should get handled in paths, since that's where service- and
|
// package. It should get handled in paths, since that's where service- and
|
||||||
// data-type-specific assertions are owned.
|
// data-type-specific assertions are owned.
|
||||||
// Ideally, we'd use something like path.DataType() instead of this func.
|
// Ideally, we'd use something like path.DataType() instead of this func.
|
||||||
func pathTypeIn(p []string) pathType {
|
func pathTypeIn(p []string) path.CategoryType {
|
||||||
// not all paths will be len=3. Most should be longer.
|
// not all paths will be len=3. Most should be longer.
|
||||||
// This just protects us from panicing below.
|
// This just protects us from panicing below.
|
||||||
if len(p) < 4 {
|
if len(p) < 4 {
|
||||||
return unknownPathType
|
return path.UnknownCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
switch p[3] {
|
if c := path.ToCategoryType(p[3]); c != path.UnknownCategory {
|
||||||
case path.EmailCategory.String():
|
return c
|
||||||
return exchangeMailPath
|
|
||||||
case path.ContactsCategory.String():
|
|
||||||
return exchangeContactPath
|
|
||||||
case path.EventsCategory.String():
|
|
||||||
return exchangeEventPath
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback for unmigrated events and contacts paths
|
|
||||||
switch p[2] {
|
switch p[2] {
|
||||||
case path.EmailCategory.String():
|
case path.EmailCategory.String():
|
||||||
return exchangeMailPath
|
return path.EmailCategory
|
||||||
case path.ContactsCategory.String():
|
case path.ContactsCategory.String():
|
||||||
return exchangeContactPath
|
return path.ContactsCategory
|
||||||
case path.EventsCategory.String():
|
case path.EventsCategory.String():
|
||||||
return exchangeEventPath
|
return path.EventsCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
return unknownPathType
|
return path.UnknownCategory
|
||||||
}
|
}
|
||||||
|
|
||||||
// groups each scope by its category of data (specified by the service-selector).
|
// groups each scope by its category of data (specified by the service-selector).
|
||||||
@ -303,7 +285,7 @@ func pathTypeIn(p []string) pathType {
|
|||||||
// so long as "mail" and "event" are contained in cats.
|
// so long as "mail" and "event" are contained in cats.
|
||||||
func scopesByCategory[T scopeT, C categoryT](
|
func scopesByCategory[T scopeT, C categoryT](
|
||||||
scopes []scope,
|
scopes []scope,
|
||||||
cats map[pathType]C,
|
cats map[path.CategoryType]C,
|
||||||
) map[C][]T {
|
) map[C][]T {
|
||||||
m := map[C][]T{}
|
m := map[C][]T{}
|
||||||
for _, cat := range cats {
|
for _, cat := range cats {
|
||||||
|
|||||||
@ -221,8 +221,8 @@ func (suite *SelectorScopesSuite) TestReduce() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataCats := map[pathType]mockCategorizer{
|
dataCats := map[path.CategoryType]mockCategorizer{
|
||||||
unknownPathType: rootCatStub,
|
path.UnknownCategory: rootCatStub,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range reduceTestTable {
|
for _, test := range reduceTestTable {
|
||||||
@ -238,32 +238,32 @@ func (suite *SelectorScopesSuite) TestReduce() {
|
|||||||
func (suite *SelectorScopesSuite) TestPathTypeIn() {
|
func (suite *SelectorScopesSuite) TestPathTypeIn() {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
pathType pathType
|
pathType path.CategoryType
|
||||||
pth []string
|
pth []string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "empty",
|
name: "empty",
|
||||||
pathType: unknownPathType,
|
pathType: path.UnknownCategory,
|
||||||
pth: []string{},
|
pth: []string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "email",
|
name: "email",
|
||||||
pathType: exchangeMailPath,
|
pathType: path.EmailCategory,
|
||||||
pth: stubPath(path.ExchangeService, path.EmailCategory, "", "", ""),
|
pth: stubPath(path.ExchangeService, path.EmailCategory, "", "", ""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "contact",
|
name: "contact",
|
||||||
pathType: exchangeContactPath,
|
pathType: path.ContactsCategory,
|
||||||
pth: stubPath(path.ExchangeService, path.ContactsCategory, "", "", ""),
|
pth: stubPath(path.ExchangeService, path.ContactsCategory, "", "", ""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "event",
|
name: "event",
|
||||||
pathType: exchangeEventPath,
|
pathType: path.EventsCategory,
|
||||||
pth: stubPath(path.ExchangeService, path.EventsCategory, "", "", ""),
|
pth: stubPath(path.ExchangeService, path.EventsCategory, "", "", ""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bogus",
|
name: "bogus",
|
||||||
pathType: unknownPathType,
|
pathType: path.UnknownCategory,
|
||||||
pth: []string{"", "", "", "fnords", "", ""},
|
pth: []string{"", "", "", "fnords", "", ""},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -282,8 +282,8 @@ func (suite *SelectorScopesSuite) TestScopesByCategory() {
|
|||||||
s2[scopeKeyCategory] = filterize(unknownCatStub.String())
|
s2[scopeKeyCategory] = filterize(unknownCatStub.String())
|
||||||
result := scopesByCategory[mockScope](
|
result := scopesByCategory[mockScope](
|
||||||
[]scope{scope(s1), scope(s2)},
|
[]scope{scope(s1), scope(s2)},
|
||||||
map[pathType]mockCategorizer{
|
map[path.CategoryType]mockCategorizer{
|
||||||
unknownPathType: rootCatStub,
|
path.UnknownCategory: rootCatStub,
|
||||||
})
|
})
|
||||||
assert.Len(t, result, 1)
|
assert.Len(t, result, 1)
|
||||||
assert.Len(t, result[rootCatStub], 1)
|
assert.Len(t, result[rootCatStub], 1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user