From ae778df5ae47ccbd751bd75790ea26801164bb2b Mon Sep 17 00:00:00 2001 From: Keepers <104464746+ryanfkeepers@users.noreply.github.com> Date: Thu, 30 Jun 2022 09:50:24 -0600 Subject: [PATCH] rename scope to selector (#257) * rename scope to selector per design changes, source is being renamed to selector for better readability and clarity. --- src/pkg/{source => selectors}/exchange.go | 40 +++++++++---------- .../{source => selectors}/exchange_test.go | 8 ++-- .../source.go => selectors/selectors.go} | 26 ++++++------ .../selectors_test.go} | 20 +++++----- .../{source => selectors}/service_string.go | 2 +- 5 files changed, 48 insertions(+), 48 deletions(-) rename src/pkg/{source => selectors}/exchange.go (70%) rename src/pkg/{source => selectors}/exchange_test.go (70%) rename src/pkg/{source/source.go => selectors/selectors.go} (69%) rename src/pkg/{source/source_test.go => selectors/selectors_test.go} (71%) rename src/pkg/{source => selectors}/service_string.go (97%) diff --git a/src/pkg/source/exchange.go b/src/pkg/selectors/exchange.go similarity index 70% rename from src/pkg/source/exchange.go rename to src/pkg/selectors/exchange.go index a9079f704..3610dba78 100644 --- a/src/pkg/source/exchange.go +++ b/src/pkg/selectors/exchange.go @@ -1,35 +1,35 @@ -package source +package selectors import ( "strconv" ) -// ExchangeSource provides an api for scoping +// Exchange provides an api for scoping // data in the Exchange service. -type ExchangeSource struct { - Source +type Exchange struct { + Selector } -// ToExchange transforms the generic source into an ExchangeSource. -// Errors if the service defined by the source is not ServiceExchange. -func (s Source) ToExchange() (*ExchangeSource, error) { +// ToExchange transforms the generic selector into an Exchange. +// Errors if the service defined by the selector is not ServiceExchange. +func (s Selector) ToExchange() (*Exchange, error) { if s.service != ServiceExchange { return nil, badCastErr(ServiceExchange, s.service) } - src := ExchangeSource{s} + src := Exchange{s} return &src, nil } -// NewExchange produces a new Source with the service set to ServiceExchange. -func NewExchange(tenantID string) *ExchangeSource { - src := ExchangeSource{ - newSource(tenantID, ServiceExchange), +// NewExchange produces a new Selector with the service set to ServiceExchange. +func NewExchange(tenantID string) *Exchange { + src := Exchange{ + newSelector(tenantID, ServiceExchange), } return &src } -// Scopes retrieves the list of exchangeScopes in the source. -func (s *ExchangeSource) Scopes() []exchangeScope { +// Scopes retrieves the list of exchangeScopes in the selector. +func (s *Exchange) Scopes() []exchangeScope { scopes := []exchangeScope{} for _, v := range s.scopes { 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 -// 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. -func (s *ExchangeSource) Users(us ...string) { +func (s *Exchange) Users(us ...string) { // todo } // 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 } // 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 } // 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 } // MailMessages selects the specified mail messages within the given folder, // owned by the user. -func (s *ExchangeSource) MailMessages(u, f string, vs ...string) { +func (s *Exchange) MailMessages(u, f string, vs ...string) { // todo } diff --git a/src/pkg/source/exchange_test.go b/src/pkg/selectors/exchange_test.go similarity index 70% rename from src/pkg/source/exchange_test.go rename to src/pkg/selectors/exchange_test.go index 70422b28e..1da78b728 100644 --- a/src/pkg/source/exchange_test.go +++ b/src/pkg/selectors/exchange_test.go @@ -1,4 +1,4 @@ -package source_test +package selectors_test import ( "testing" @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" - "github.com/alcionai/corso/pkg/source" + "github.com/alcionai/corso/pkg/selectors" ) type ExchangeSourceSuite struct { @@ -19,8 +19,8 @@ func TestExchangeSourceSuite(t *testing.T) { func (suite *ExchangeSourceSuite) TestNewExchangeSource() { t := suite.T() - es := source.NewExchange("tid") + es := selectors.NewExchange("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()) } diff --git a/src/pkg/source/source.go b/src/pkg/selectors/selectors.go similarity index 69% rename from src/pkg/source/source.go rename to src/pkg/selectors/selectors.go index 8a7fa27f6..0ec1f7b80 100644 --- a/src/pkg/source/source.go +++ b/src/pkg/selectors/selectors.go @@ -1,4 +1,4 @@ -package source +package selectors import ( "strconv" @@ -14,7 +14,7 @@ const ( ServiceExchange // Exchange ) -var ErrorBadSourceCast = errors.New("wrong source service type") +var ErrorBadSelectorCast = errors.New("wrong selector service type") const ( scopeKeyGranularity = "granularity" @@ -27,30 +27,30 @@ const ( All = "*" ) -// The core source. Has no api for setting or retrieving data. -// Is only used to pass along more specific source instances. -type Source struct { +// The core selector. Has no api for setting or retrieving data. +// Is only used to pass along more specific selector instances. +type Selector struct { TenantID string // The tenant making the request. 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. } -// helper for specific source instance constructors. -func newSource(tenantID string, s service) Source { - return Source{ +// helper for specific selector instance constructors. +func newSelector(tenantID string, s service) Selector { + return Selector{ TenantID: tenantID, service: s, scopes: []map[string]string{}, } } -// Service return the service enum for the source. -func (s Source) Service() service { +// Service return the service enum for the selector. +func (s Selector) Service() service { return s.service } 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 @@ -68,8 +68,8 @@ func (g scopeGranularity) String() string { return strconv.Itoa(int(g)) } -func granularityOf(source map[string]string) scopeGranularity { - return scopeGranularity(getIota(source, scopeKeyGranularity)) +func granularityOf(selector map[string]string) scopeGranularity { + return scopeGranularity(getIota(selector, scopeKeyGranularity)) } // retrieves the iota, stored as a string, and transforms it to diff --git a/src/pkg/source/source_test.go b/src/pkg/selectors/selectors_test.go similarity index 71% rename from src/pkg/source/source_test.go rename to src/pkg/selectors/selectors_test.go index 3f6f725ac..0b333d890 100644 --- a/src/pkg/source/source_test.go +++ b/src/pkg/selectors/selectors_test.go @@ -1,4 +1,4 @@ -package source +package selectors import ( "fmt" @@ -8,37 +8,37 @@ import ( "github.com/stretchr/testify/suite" ) -type SourceSuite struct { +type SelectorSuite struct { suite.Suite } -func TestSourceSuite(t *testing.T) { - suite.Run(t, new(SourceSuite)) +func TestSelectorSuite(t *testing.T) { + suite.Run(t, new(SelectorSuite)) } -func (suite *SourceSuite) TestNewSource() { +func (suite *SelectorSuite) TestNewSelector() { t := suite.T() - s := newSource("tid", ServiceUnknown) + s := newSelector("tid", ServiceUnknown) assert.NotNil(t, s) assert.Equal(t, s.TenantID, "tid") assert.Equal(t, s.service, ServiceUnknown) assert.NotNil(t, s.scopes) } -func (suite *SourceSuite) TestSource_Service() { +func (suite *SelectorSuite) TestSelector_Service() { table := []service{ ServiceUnknown, ServiceExchange, } for _, test := range table { 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) }) } } -func (suite *SourceSuite) TestGetIota() { +func (suite *SelectorSuite) TestGetIota() { table := []struct { name string val string @@ -59,7 +59,7 @@ func (suite *SourceSuite) TestGetIota() { } } -func (suite *SourceSuite) TestBadCastErr() { +func (suite *SelectorSuite) TestBadCastErr() { err := badCastErr(ServiceUnknown, ServiceExchange) assert.Error(suite.T(), err) } diff --git a/src/pkg/source/service_string.go b/src/pkg/selectors/service_string.go similarity index 97% rename from src/pkg/source/service_string.go rename to src/pkg/selectors/service_string.go index c70010951..ded67b54d 100644 --- a/src/pkg/source/service_string.go +++ b/src/pkg/selectors/service_string.go @@ -1,6 +1,6 @@ // Code generated by "stringer -type=service -linecomment"; DO NOT EDIT. -package source +package selectors import "strconv"