add humanstring to path category type (#4282)
#### Does this PR need a docs update or release note? - [x] ⛔ No #### Type of change - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #3988 #### Test Plan - [x] 💪 Manual - [x] ⚡ Unit test
This commit is contained in:
parent
1bacad72aa
commit
8f7070ffac
@ -73,7 +73,7 @@ func generateAndRestoreItems(
|
||||
nowLegacy = dttm.FormatToLegacy(time.Now())
|
||||
id = uuid.NewString()
|
||||
subject = "automated " + now[:16] + " - " + id[:8]
|
||||
body = "automated " + cat.String() + " generation for " + userID + " at " + now + " - " + id
|
||||
body = "automated " + cat.HumanString() + " generation for " + userID + " at " + now + " - " + id
|
||||
)
|
||||
|
||||
items = append(items, item{
|
||||
|
||||
@ -243,7 +243,9 @@ func (c *Collections) Get(
|
||||
driveTombstones[driveID] = struct{}{}
|
||||
}
|
||||
|
||||
progressBar := observe.MessageWithCompletion(ctx, observe.Bulletf("files"))
|
||||
progressBar := observe.MessageWithCompletion(
|
||||
ctx,
|
||||
observe.Bulletf(path.FilesCategory.HumanString()))
|
||||
defer close(progressBar)
|
||||
|
||||
// Enumerate drives for the specified resourceOwner
|
||||
|
||||
@ -53,7 +53,7 @@ func CreateCollections(
|
||||
|
||||
foldersComplete := observe.MessageWithCompletion(
|
||||
ctx,
|
||||
observe.Bulletf("%s", qp.Category))
|
||||
observe.Bulletf("%s", qp.Category.HumanString()))
|
||||
defer close(foldersComplete)
|
||||
|
||||
rootFolder, cc := handler.NewContainerCache(bpc.ProtectedResource.ID())
|
||||
|
||||
@ -164,7 +164,7 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
|
||||
if len(col.added)+len(col.removed) > 0 {
|
||||
colProgress = observe.CollectionProgress(
|
||||
ctx,
|
||||
col.FullPath().Category().String(),
|
||||
col.FullPath().Category().HumanString(),
|
||||
col.LocationPath().Elements())
|
||||
defer close(colProgress)
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func RestoreCollection(
|
||||
|
||||
colProgress := observe.CollectionProgress(
|
||||
ctx,
|
||||
category.String(),
|
||||
category.HumanString(),
|
||||
fullPath.Folder(false))
|
||||
defer close(colProgress)
|
||||
|
||||
|
||||
@ -209,7 +209,7 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
|
||||
if len(col.added)+len(col.removed) > 0 {
|
||||
colProgress = observe.CollectionProgress(
|
||||
ctx,
|
||||
col.FullPath().Category().String(),
|
||||
col.FullPath().Category().HumanString(),
|
||||
col.LocationPath().Elements())
|
||||
defer close(colProgress)
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ func (sc *Collection) runPopulate(
|
||||
// TODO: Insert correct ID for CollectionProgress
|
||||
colProgress := observe.CollectionProgress(
|
||||
ctx,
|
||||
sc.fullPath.Category().String(),
|
||||
sc.fullPath.Category().HumanString(),
|
||||
sc.fullPath.Folders())
|
||||
defer close(colProgress)
|
||||
|
||||
|
||||
@ -67,14 +67,9 @@ func ProduceBackupCollections(
|
||||
break
|
||||
}
|
||||
|
||||
catStr := scope.Category().PathType().String()
|
||||
if scope.Category().PathType() == path.ChannelMessagesCategory {
|
||||
catStr = "messages"
|
||||
}
|
||||
|
||||
progressBar := observe.MessageWithCompletion(
|
||||
ctx,
|
||||
observe.Bulletf("%s", catStr))
|
||||
observe.Bulletf("%s", scope.Category().PathType().HumanString()))
|
||||
defer close(progressBar)
|
||||
|
||||
var dbcs []data.BackupCollection
|
||||
|
||||
@ -52,7 +52,7 @@ func ProduceBackupCollections(
|
||||
|
||||
progressBar := observe.MessageWithCompletion(
|
||||
ctx,
|
||||
observe.Bulletf("%s", scope.Category().PathType()))
|
||||
observe.Bulletf("%s", scope.Category().PathType().HumanString()))
|
||||
defer close(progressBar)
|
||||
|
||||
var spcs []data.BackupCollection
|
||||
|
||||
@ -29,31 +29,47 @@ const (
|
||||
ChannelMessagesCategory CategoryType = 9 // channelMessages
|
||||
)
|
||||
|
||||
func ToCategoryType(category string) CategoryType {
|
||||
cat := strings.ToLower(category)
|
||||
var strToCat = map[string]CategoryType{
|
||||
strings.ToLower(EmailCategory.String()): EmailCategory,
|
||||
strings.ToLower(ContactsCategory.String()): ContactsCategory,
|
||||
strings.ToLower(EventsCategory.String()): EventsCategory,
|
||||
strings.ToLower(FilesCategory.String()): FilesCategory,
|
||||
strings.ToLower(LibrariesCategory.String()): LibrariesCategory,
|
||||
strings.ToLower(ListsCategory.String()): ListsCategory,
|
||||
strings.ToLower(PagesCategory.String()): PagesCategory,
|
||||
strings.ToLower(DetailsCategory.String()): DetailsCategory,
|
||||
strings.ToLower(ChannelMessagesCategory.String()): ChannelMessagesCategory,
|
||||
}
|
||||
|
||||
switch cat {
|
||||
case strings.ToLower(EmailCategory.String()):
|
||||
return EmailCategory
|
||||
case strings.ToLower(ContactsCategory.String()):
|
||||
return ContactsCategory
|
||||
case strings.ToLower(EventsCategory.String()):
|
||||
return EventsCategory
|
||||
case strings.ToLower(FilesCategory.String()):
|
||||
return FilesCategory
|
||||
case strings.ToLower(LibrariesCategory.String()):
|
||||
return LibrariesCategory
|
||||
case strings.ToLower(ListsCategory.String()):
|
||||
return ListsCategory
|
||||
case strings.ToLower(PagesCategory.String()):
|
||||
return PagesCategory
|
||||
case strings.ToLower(DetailsCategory.String()):
|
||||
return DetailsCategory
|
||||
case strings.ToLower(ChannelMessagesCategory.String()):
|
||||
return ChannelMessagesCategory
|
||||
default:
|
||||
return UnknownCategory
|
||||
func ToCategoryType(s string) CategoryType {
|
||||
cat, ok := strToCat[strings.ToLower(s)]
|
||||
if ok {
|
||||
return cat
|
||||
}
|
||||
|
||||
return UnknownCategory
|
||||
}
|
||||
|
||||
var catToHuman = map[CategoryType]string{
|
||||
EmailCategory: "Emails",
|
||||
ContactsCategory: "Contacts",
|
||||
EventsCategory: "Events",
|
||||
FilesCategory: "Files",
|
||||
LibrariesCategory: "Libraries",
|
||||
ListsCategory: "Lists",
|
||||
PagesCategory: "Pages",
|
||||
DetailsCategory: "Details",
|
||||
ChannelMessagesCategory: "Messages",
|
||||
}
|
||||
|
||||
// HumanString produces a more human-readable string version of the category.
|
||||
func (cat CategoryType) HumanString() string {
|
||||
hs, ok := catToHuman[cat]
|
||||
if ok {
|
||||
return hs
|
||||
}
|
||||
|
||||
return "Unknown Category"
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
72
src/pkg/path/category_type_test.go
Normal file
72
src/pkg/path/category_type_test.go
Normal file
@ -0,0 +1,72 @@
|
||||
package path
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
)
|
||||
|
||||
type CategoryTypeUnitSuite struct {
|
||||
tester.Suite
|
||||
}
|
||||
|
||||
func TestCategoryTypeUnitSuite(t *testing.T) {
|
||||
suite.Run(t, &CategoryTypeUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||
}
|
||||
|
||||
func (suite *CategoryTypeUnitSuite) TestToCategoryType() {
|
||||
table := []struct {
|
||||
input string
|
||||
expect CategoryType
|
||||
}{
|
||||
{input: "unknown", expect: 0},
|
||||
{input: "EMAIL", expect: 1},
|
||||
{input: "Email", expect: 1},
|
||||
{input: "email", expect: 1},
|
||||
{input: "contacts", expect: 2},
|
||||
{input: "events", expect: 3},
|
||||
{input: "files", expect: 4},
|
||||
{input: "lists", expect: 5},
|
||||
{input: "libraries", expect: 6},
|
||||
{input: "pages", expect: 7},
|
||||
{input: "details", expect: 8},
|
||||
{input: "channelmessages", expect: 9},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.Run(test.input, func() {
|
||||
assert.Equal(
|
||||
suite.T(),
|
||||
test.expect,
|
||||
ToCategoryType(test.input))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *CategoryTypeUnitSuite) TestHumanString() {
|
||||
table := []struct {
|
||||
input CategoryType
|
||||
expect string
|
||||
}{
|
||||
{input: 0, expect: "Unknown Category"},
|
||||
{input: 1, expect: "Emails"},
|
||||
{input: 2, expect: "Contacts"},
|
||||
{input: 3, expect: "Events"},
|
||||
{input: 4, expect: "Files"},
|
||||
{input: 5, expect: "Lists"},
|
||||
{input: 6, expect: "Libraries"},
|
||||
{input: 7, expect: "Pages"},
|
||||
{input: 8, expect: "Details"},
|
||||
{input: 9, expect: "Messages"},
|
||||
}
|
||||
for _, test := range table {
|
||||
suite.Run(test.input.String(), func() {
|
||||
assert.Equal(
|
||||
suite.T(),
|
||||
test.expect,
|
||||
test.input.HumanString())
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user