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?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

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

#### Issue(s)

* #3943

#### Test Plan

- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-10-25 09:28:13 -07:00 committed by GitHub
parent 82fa185085
commit cb6c56783b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package kopia package kopia
import ( import (
"fmt"
"testing" "testing"
"github.com/kopia/kopia/repo/manifest" "github.com/kopia/kopia/repo/manifest"
@ -9,6 +10,8 @@ import (
"github.com/alcionai/corso/src/internal/model" "github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/pkg/backup" "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. // TODO(ashmrtn): Temp function until all PRs in the series merge.
@ -197,3 +200,67 @@ func (bb *MockBackupBases) MockDisableMergeBases() *MockBackupBases {
bb.DisableMergeBases() bb.DisableMergeBases()
return bb 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
}