From cb6c56783ba3944b55160acb3d285aa245266a56 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:28:13 -0700 Subject: [PATCH] Builder pattern for BackupBase struct (#4470) Will be useful for later testing that needs BackupBase --- #### 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 #### Issue(s) * #3943 #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/mock_backup_base.go | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/internal/kopia/mock_backup_base.go b/src/internal/kopia/mock_backup_base.go index 90a31ecf4..c77120fc1 100644 --- a/src/internal/kopia/mock_backup_base.go +++ b/src/internal/kopia/mock_backup_base.go @@ -1,6 +1,7 @@ package kopia import ( + "fmt" "testing" "github.com/kopia/kopia/repo/manifest" @@ -9,6 +10,8 @@ import ( "github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/pkg/backup" + "github.com/alcionai/corso/src/pkg/backup/identity" + "github.com/alcionai/corso/src/pkg/path" ) // TODO(ashmrtn): Temp function until all PRs in the series merge. @@ -197,3 +200,67 @@ func (bb *MockBackupBases) MockDisableMergeBases() *MockBackupBases { bb.DisableMergeBases() return bb } + +// ----------------------------------------------------------------------------- +// Functions for BackupBase creation +// ----------------------------------------------------------------------------- + +func NewBackupBaseBuilder(idPrefix string, id int) *BackupBaseBuilder { + bIDKey, _ := makeTagKV(TagBackupID) + baseID := fmt.Sprintf("%sID%d", idPrefix, id) + + return &BackupBaseBuilder{ + b: &BackupBase{ + Backup: &backup.Backup{ + BaseModel: model.BaseModel{ + ID: model.StableID(baseID + "-backup"), + }, + SnapshotID: baseID + "-item-data", + StreamStoreID: baseID + "-stream-store", + }, + ItemDataSnapshot: &snapshot.Manifest{ + ID: manifest.ID(baseID + "-item-data"), + Tags: map[string]string{bIDKey: baseID + "-backup"}, + }, + Reasons: []identity.Reasoner{ + identity.NewReason( + "tenant", + "protected_resource", + path.ExchangeService, + path.EmailCategory), + }, + }, + } +} + +type BackupBaseBuilder struct { + b *BackupBase +} + +func (builder *BackupBaseBuilder) Build() BackupBase { + return *builder.b +} + +func (builder *BackupBaseBuilder) MarkAssistBase() *BackupBaseBuilder { + if builder.b.Backup.Tags == nil { + builder.b.Backup.Tags = map[string]string{} + } + + builder.b.Backup.Tags[model.BackupTypeTag] = model.AssistBackup + + return builder +} + +func (builder *BackupBaseBuilder) WithReasons( + reasons ...identity.Reasoner, +) *BackupBaseBuilder { + builder.b.Reasons = reasons + return builder +} + +func (builder *BackupBaseBuilder) AppendReasons( + reasons ...identity.Reasoner, +) *BackupBaseBuilder { + builder.b.Reasons = append(builder.b.Reasons, reasons...) + return builder +}