From c07b14c859345b864923e59767c20d93cfecec04 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Wed, 11 Oct 2023 15:04:16 -0700 Subject: [PATCH] Consolidate Reasoner implementations (#4469) Remove other implementation of Reasoner in the selector package since it's a duplicate of the one that's in the identity package --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [x] :green_heart: E2E --- src/pkg/selectors/reasons.go | 54 +++++------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/src/pkg/selectors/reasons.go b/src/pkg/selectors/reasons.go index a27d87f52..07970c761 100644 --- a/src/pkg/selectors/reasons.go +++ b/src/pkg/selectors/reasons.go @@ -8,45 +8,11 @@ import ( "github.com/alcionai/corso/src/pkg/path" ) -// --------------------------------------------------------------------------- -// reasoner interface compliance -// --------------------------------------------------------------------------- - -var _ identity.Reasoner = &backupReason{} - -type backupReason struct { - category path.CategoryType - resource string - service path.ServiceType - tenant string -} - -func (br backupReason) Tenant() string { - return br.tenant -} - -func (br backupReason) ProtectedResource() string { - return br.resource -} - -func (br backupReason) Service() path.ServiceType { - return br.service -} - -func (br backupReason) Category() path.CategoryType { - return br.category -} - -func (br backupReason) SubtreePath() (path.Path, error) { - return path.BuildPrefix( - br.tenant, - br.resource, - br.service, - br.category) -} - -func (br backupReason) key() string { - return br.category.String() + br.resource + br.service.String() + br.tenant +func key(br identity.Reasoner) string { + return br.Category().String() + + br.ProtectedResource() + + br.Service().String() + + br.Tenant() } // --------------------------------------------------------------------------- @@ -76,14 +42,8 @@ func reasonsFor( for _, sl := range [][]path.CategoryType{pc.Includes, pc.Filters} { for _, cat := range sl { - br := backupReason{ - category: cat, - resource: resource, - service: service, - tenant: tenantID, - } - - reasons[br.key()] = br + br := identity.NewReason(tenantID, resource, service, cat) + reasons[key(br)] = br } }