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:
ashmrtn 2022-09-12 13:16:08 -07:00 committed by GitHub
parent 110e874e5b
commit dc0c7e49c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 57 deletions

View File

@ -4,6 +4,7 @@ import (
"strconv"
"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/filters"
)
@ -558,27 +559,27 @@ func (ec exchangeCategory) unknownCat() categorizer {
// Example:
// [tenantID, userPN, "mail", mailFolder, 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{}
if len(path) < 5 {
if len(p) < 5 {
return m
}
switch ec {
case ExchangeContact:
m[ExchangeUser] = path[1]
m[ExchangeContactFolder] = path[3]
m[ExchangeContact] = path[4]
m[ExchangeUser] = p[1]
m[ExchangeContactFolder] = p[3]
m[ExchangeContact] = p[4]
case ExchangeEvent:
m[ExchangeUser] = path[1]
m[ExchangeEventCalendar] = path[3]
m[ExchangeEvent] = path[4]
m[ExchangeUser] = p[1]
m[ExchangeEventCalendar] = p[3]
m[ExchangeEvent] = p[4]
case ExchangeMail:
m[ExchangeUser] = path[2]
m[ExchangeMailFolder] = path[4]
m[ExchangeMail] = path[5]
m[ExchangeUser] = p[2]
m[ExchangeMailFolder] = p[4]
m[ExchangeMail] = p[5]
}
return m
@ -680,10 +681,10 @@ func (s exchange) Reduce(deets *details.Details) *details.Details {
return reduce[ExchangeScope](
deets,
s.Selector,
map[pathType]exchangeCategory{
exchangeContactPath: ExchangeContact,
exchangeEventPath: ExchangeEvent,
exchangeMailPath: ExchangeMail,
map[path.CategoryType]exchangeCategory{
path.ContactsCategory: ExchangeContact,
path.EventsCategory: ExchangeEvent,
path.EmailCategory: ExchangeMail,
},
)
}

View File

@ -1054,10 +1054,10 @@ func (suite *ExchangeSelectorSuite) TestScopesByCategory() {
return mss
}
cats := map[pathType]exchangeCategory{
exchangeContactPath: ExchangeContact,
exchangeEventPath: ExchangeEvent,
exchangeMailPath: ExchangeMail,
cats := map[path.CategoryType]exchangeCategory{
path.ContactsCategory: ExchangeContact,
path.EventsCategory: ExchangeEvent,
path.EmailCategory: ExchangeMail,
}
table := []struct {

View File

@ -209,7 +209,7 @@ func isAnyTarget[T scopeT, C categoryT](s T, cat C) bool {
func reduce[T scopeT, C categoryT](
deets *details.Details,
s Selector,
dataCategories map[pathType]C,
dataCategories map[path.CategoryType]C,
) *details.Details {
if deets == nil {
return nil
@ -251,50 +251,32 @@ func reduce[T scopeT, C categoryT](
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.
// 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
// data-type-specific assertions are owned.
// 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.
// This just protects us from panicing below.
if len(p) < 4 {
return unknownPathType
return path.UnknownCategory
}
switch p[3] {
case path.EmailCategory.String():
return exchangeMailPath
case path.ContactsCategory.String():
return exchangeContactPath
case path.EventsCategory.String():
return exchangeEventPath
if c := path.ToCategoryType(p[3]); c != path.UnknownCategory {
return c
}
// fallback for unmigrated events and contacts paths
switch p[2] {
case path.EmailCategory.String():
return exchangeMailPath
return path.EmailCategory
case path.ContactsCategory.String():
return exchangeContactPath
return path.ContactsCategory
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).
@ -303,7 +285,7 @@ func pathTypeIn(p []string) pathType {
// so long as "mail" and "event" are contained in cats.
func scopesByCategory[T scopeT, C categoryT](
scopes []scope,
cats map[pathType]C,
cats map[path.CategoryType]C,
) map[C][]T {
m := map[C][]T{}
for _, cat := range cats {

View File

@ -221,8 +221,8 @@ func (suite *SelectorScopesSuite) TestReduce() {
},
}
}
dataCats := map[pathType]mockCategorizer{
unknownPathType: rootCatStub,
dataCats := map[path.CategoryType]mockCategorizer{
path.UnknownCategory: rootCatStub,
}
for _, test := range reduceTestTable {
@ -238,32 +238,32 @@ func (suite *SelectorScopesSuite) TestReduce() {
func (suite *SelectorScopesSuite) TestPathTypeIn() {
table := []struct {
name string
pathType pathType
pathType path.CategoryType
pth []string
}{
{
name: "empty",
pathType: unknownPathType,
pathType: path.UnknownCategory,
pth: []string{},
},
{
name: "email",
pathType: exchangeMailPath,
pathType: path.EmailCategory,
pth: stubPath(path.ExchangeService, path.EmailCategory, "", "", ""),
},
{
name: "contact",
pathType: exchangeContactPath,
pathType: path.ContactsCategory,
pth: stubPath(path.ExchangeService, path.ContactsCategory, "", "", ""),
},
{
name: "event",
pathType: exchangeEventPath,
pathType: path.EventsCategory,
pth: stubPath(path.ExchangeService, path.EventsCategory, "", "", ""),
},
{
name: "bogus",
pathType: unknownPathType,
pathType: path.UnknownCategory,
pth: []string{"", "", "", "fnords", "", ""},
},
}
@ -282,8 +282,8 @@ func (suite *SelectorScopesSuite) TestScopesByCategory() {
s2[scopeKeyCategory] = filterize(unknownCatStub.String())
result := scopesByCategory[mockScope](
[]scope{scope(s1), scope(s2)},
map[pathType]mockCategorizer{
unknownPathType: rootCatStub,
map[path.CategoryType]mockCategorizer{
path.UnknownCategory: rootCatStub,
})
assert.Len(t, result, 1)
assert.Len(t, result[rootCatStub], 1)