Remove duplicate string->path.CategoryType helper function (#2260)

## Description

Tackles a few things:
* normalize case when going from string->path.Service or path.Category
* removes duplicate helper function for string->path.Category in favor of path package one

## 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

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

## Issue(s)

* closes #2259

## Test Plan

- [x] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-01-25 12:13:50 -08:00 committed by GitHub
parent a4f2f0a437
commit bb73d142c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 29 deletions

View File

@ -19,7 +19,6 @@ import (
"github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/connector"
"github.com/alcionai/corso/src/internal/connector/exchange/api"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/pkg/account"
"github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/credentials"
@ -96,7 +95,7 @@ func runDisplayM365JSON(
var (
bs []byte
err error
cat = graph.StringToPathCategory(category)
cat = path.ToCategoryType(category)
sw = kw.NewJsonSerializationWriter()
)

View File

@ -4,7 +4,6 @@ import (
"net/http"
"net/http/httputil"
"os"
"strings"
"time"
az "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
@ -15,7 +14,6 @@ import (
"github.com/pkg/errors"
"github.com/alcionai/corso/src/pkg/logger"
"github.com/alcionai/corso/src/pkg/path"
)
const (
@ -104,26 +102,3 @@ func (handler *LoggingMiddleware) Intercept(
return resp, err
}
// ---------------------------------------------------------------------------
// Other Helpers
// ---------------------------------------------------------------------------
func StringToPathCategory(input string) path.CategoryType {
param := strings.ToLower(input)
switch param {
case "email":
return path.EmailCategory
case "contacts":
return path.ContactsCategory
case "events":
return path.EventsCategory
case "files":
return path.FilesCategory
case "libraries":
return path.LibrariesCategory
default:
return path.UnknownCategory
}
}

View File

@ -1,6 +1,8 @@
package path
import (
"strings"
"github.com/pkg/errors"
)
@ -30,7 +32,9 @@ const (
)
func toServiceType(service string) ServiceType {
switch service {
s := strings.ToLower(service)
switch s {
case ExchangeService.String():
return ExchangeService
case OneDriveService.String():
@ -70,7 +74,9 @@ const (
)
func ToCategoryType(category string) CategoryType {
switch category {
cat := strings.ToLower(category)
switch cat {
case EmailCategory.String():
return EmailCategory
case ContactsCategory.String():

View File

@ -1,6 +1,7 @@
package path
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
@ -73,6 +74,14 @@ func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategory() {
category: "foo",
check: assert.Error,
},
{
name: "DifferentCases",
service: strings.ToUpper(ExchangeService.String()),
category: strings.ToUpper(EmailCategory.String()),
expectedService: ExchangeService,
expectedCategory: EmailCategory,
check: assert.NoError,
},
{
name: "ExchangeEmail",
service: ExchangeService.String(),