rename scope to selector (#257)

* rename scope to selector

per design changes, source is being renamed to selector
for better readability and clarity.
This commit is contained in:
Keepers 2022-06-30 09:50:24 -06:00 committed by GitHub
parent ce52cc5f41
commit ae778df5ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 48 deletions

View File

@ -1,35 +1,35 @@
package source package selectors
import ( import (
"strconv" "strconv"
) )
// ExchangeSource provides an api for scoping // Exchange provides an api for scoping
// data in the Exchange service. // data in the Exchange service.
type ExchangeSource struct { type Exchange struct {
Source Selector
} }
// ToExchange transforms the generic source into an ExchangeSource. // ToExchange transforms the generic selector into an Exchange.
// Errors if the service defined by the source is not ServiceExchange. // Errors if the service defined by the selector is not ServiceExchange.
func (s Source) ToExchange() (*ExchangeSource, error) { func (s Selector) ToExchange() (*Exchange, error) {
if s.service != ServiceExchange { if s.service != ServiceExchange {
return nil, badCastErr(ServiceExchange, s.service) return nil, badCastErr(ServiceExchange, s.service)
} }
src := ExchangeSource{s} src := Exchange{s}
return &src, nil return &src, nil
} }
// NewExchange produces a new Source with the service set to ServiceExchange. // NewExchange produces a new Selector with the service set to ServiceExchange.
func NewExchange(tenantID string) *ExchangeSource { func NewExchange(tenantID string) *Exchange {
src := ExchangeSource{ src := Exchange{
newSource(tenantID, ServiceExchange), newSelector(tenantID, ServiceExchange),
} }
return &src return &src
} }
// Scopes retrieves the list of exchangeScopes in the source. // Scopes retrieves the list of exchangeScopes in the selector.
func (s *ExchangeSource) Scopes() []exchangeScope { func (s *Exchange) Scopes() []exchangeScope {
scopes := []exchangeScope{} scopes := []exchangeScope{}
for _, v := range s.scopes { for _, v := range s.scopes {
scopes = append(scopes, exchangeScope(v)) scopes = append(scopes, exchangeScope(v))
@ -38,31 +38,31 @@ func (s *ExchangeSource) Scopes() []exchangeScope {
} }
// the following are called by the client to specify the constraints // the following are called by the client to specify the constraints
// each call appends one or more scopes to the source. // each call appends one or more scopes to the selector.
// Users selects the specified users. All of their data is included. // Users selects the specified users. All of their data is included.
func (s *ExchangeSource) Users(us ...string) { func (s *Exchange) Users(us ...string) {
// todo // todo
} }
// Contacts selects the specified contacts owned by the user. // Contacts selects the specified contacts owned by the user.
func (s *ExchangeSource) Contacts(u string, vs ...string) { func (s *Exchange) Contacts(u string, vs ...string) {
// todo // todo
} }
// Events selects the specified events owned by the user. // Events selects the specified events owned by the user.
func (s *ExchangeSource) Events(u string, vs ...string) { func (s *Exchange) Events(u string, vs ...string) {
// todo // todo
} }
// MailFolders selects the specified mail folders owned by the user. // MailFolders selects the specified mail folders owned by the user.
func (s *ExchangeSource) MailFolders(u string, vs ...string) { func (s *Exchange) MailFolders(u string, vs ...string) {
// todo // todo
} }
// MailMessages selects the specified mail messages within the given folder, // MailMessages selects the specified mail messages within the given folder,
// owned by the user. // owned by the user.
func (s *ExchangeSource) MailMessages(u, f string, vs ...string) { func (s *Exchange) MailMessages(u, f string, vs ...string) {
// todo // todo
} }

View File

@ -1,4 +1,4 @@
package source_test package selectors_test
import ( import (
"testing" "testing"
@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/alcionai/corso/pkg/source" "github.com/alcionai/corso/pkg/selectors"
) )
type ExchangeSourceSuite struct { type ExchangeSourceSuite struct {
@ -19,8 +19,8 @@ func TestExchangeSourceSuite(t *testing.T) {
func (suite *ExchangeSourceSuite) TestNewExchangeSource() { func (suite *ExchangeSourceSuite) TestNewExchangeSource() {
t := suite.T() t := suite.T()
es := source.NewExchange("tid") es := selectors.NewExchange("tid")
assert.Equal(t, es.TenantID, "tid") assert.Equal(t, es.TenantID, "tid")
assert.Equal(t, es.Service(), source.ServiceExchange) assert.Equal(t, es.Service(), selectors.ServiceExchange)
assert.NotZero(t, es.Scopes()) assert.NotZero(t, es.Scopes())
} }

View File

@ -1,4 +1,4 @@
package source package selectors
import ( import (
"strconv" "strconv"
@ -14,7 +14,7 @@ const (
ServiceExchange // Exchange ServiceExchange // Exchange
) )
var ErrorBadSourceCast = errors.New("wrong source service type") var ErrorBadSelectorCast = errors.New("wrong selector service type")
const ( const (
scopeKeyGranularity = "granularity" scopeKeyGranularity = "granularity"
@ -27,30 +27,30 @@ const (
All = "*" All = "*"
) )
// The core source. Has no api for setting or retrieving data. // The core selector. Has no api for setting or retrieving data.
// Is only used to pass along more specific source instances. // Is only used to pass along more specific selector instances.
type Source struct { type Selector struct {
TenantID string // The tenant making the request. TenantID string // The tenant making the request.
service service // The service scope of the data. Exchange, Teams, Sharepoint, etc. service service // The service scope of the data. Exchange, Teams, Sharepoint, etc.
scopes []map[string]string // A slice of scopes. Expected to get cast to fooScope within each service handler. scopes []map[string]string // A slice of scopes. Expected to get cast to fooScope within each service handler.
} }
// helper for specific source instance constructors. // helper for specific selector instance constructors.
func newSource(tenantID string, s service) Source { func newSelector(tenantID string, s service) Selector {
return Source{ return Selector{
TenantID: tenantID, TenantID: tenantID,
service: s, service: s,
scopes: []map[string]string{}, scopes: []map[string]string{},
} }
} }
// Service return the service enum for the source. // Service return the service enum for the selector.
func (s Source) Service() service { func (s Selector) Service() service {
return s.service return s.service
} }
func badCastErr(cast, is service) error { func badCastErr(cast, is service) error {
return errors.Wrapf(ErrorBadSourceCast, "%s service is not %s", cast, is) return errors.Wrapf(ErrorBadSelectorCast, "%s service is not %s", cast, is)
} }
type scopeGranularity int type scopeGranularity int
@ -68,8 +68,8 @@ func (g scopeGranularity) String() string {
return strconv.Itoa(int(g)) return strconv.Itoa(int(g))
} }
func granularityOf(source map[string]string) scopeGranularity { func granularityOf(selector map[string]string) scopeGranularity {
return scopeGranularity(getIota(source, scopeKeyGranularity)) return scopeGranularity(getIota(selector, scopeKeyGranularity))
} }
// retrieves the iota, stored as a string, and transforms it to // retrieves the iota, stored as a string, and transforms it to

View File

@ -1,4 +1,4 @@
package source package selectors
import ( import (
"fmt" "fmt"
@ -8,37 +8,37 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
type SourceSuite struct { type SelectorSuite struct {
suite.Suite suite.Suite
} }
func TestSourceSuite(t *testing.T) { func TestSelectorSuite(t *testing.T) {
suite.Run(t, new(SourceSuite)) suite.Run(t, new(SelectorSuite))
} }
func (suite *SourceSuite) TestNewSource() { func (suite *SelectorSuite) TestNewSelector() {
t := suite.T() t := suite.T()
s := newSource("tid", ServiceUnknown) s := newSelector("tid", ServiceUnknown)
assert.NotNil(t, s) assert.NotNil(t, s)
assert.Equal(t, s.TenantID, "tid") assert.Equal(t, s.TenantID, "tid")
assert.Equal(t, s.service, ServiceUnknown) assert.Equal(t, s.service, ServiceUnknown)
assert.NotNil(t, s.scopes) assert.NotNil(t, s.scopes)
} }
func (suite *SourceSuite) TestSource_Service() { func (suite *SelectorSuite) TestSelector_Service() {
table := []service{ table := []service{
ServiceUnknown, ServiceUnknown,
ServiceExchange, ServiceExchange,
} }
for _, test := range table { for _, test := range table {
suite.T().Run(fmt.Sprintf("testing %d", test), func(t *testing.T) { suite.T().Run(fmt.Sprintf("testing %d", test), func(t *testing.T) {
s := newSource("tid", test) s := newSelector("tid", test)
assert.Equal(t, s.Service(), test) assert.Equal(t, s.Service(), test)
}) })
} }
} }
func (suite *SourceSuite) TestGetIota() { func (suite *SelectorSuite) TestGetIota() {
table := []struct { table := []struct {
name string name string
val string val string
@ -59,7 +59,7 @@ func (suite *SourceSuite) TestGetIota() {
} }
} }
func (suite *SourceSuite) TestBadCastErr() { func (suite *SelectorSuite) TestBadCastErr() {
err := badCastErr(ServiceUnknown, ServiceExchange) err := badCastErr(ServiceUnknown, ServiceExchange)
assert.Error(suite.T(), err) assert.Error(suite.T(), err)
} }

View File

@ -1,6 +1,6 @@
// Code generated by "stringer -type=service -linecomment"; DO NOT EDIT. // Code generated by "stringer -type=service -linecomment"; DO NOT EDIT.
package source package selectors
import "strconv" import "strconv"