corso/src/pkg/store/backup_test.go
ashmrtn 893598d8ba
Fix circular dependency for store interface (#4014)
Remove references to the kopia package from
`pkg/store` package so that kopia can import
that package itself. Do this by using
interfaces where needed in `pkg/store`
instead of concrete struct types

These changes will make cleaning up
incomplete backups a little neater since
that code will need to lookup both
manifests and backup models

This PR is just minor renaming and fixups,
no logic changes

---

#### 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
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #3217

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
2023-08-11 16:04:05 +00:00

153 lines
3.2 KiB
Go

package store_test
import (
"testing"
"time"
"github.com/alcionai/clues"
"github.com/google/uuid"
"github.com/kopia/kopia/repo/manifest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/alcionai/corso/src/internal/model"
"github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/pkg/backup"
"github.com/alcionai/corso/src/pkg/store"
"github.com/alcionai/corso/src/pkg/store/mock"
)
// ------------------------------------------------------------
// unit tests
// ------------------------------------------------------------
var (
detailsID = uuid.NewString()
bu = backup.Backup{
BaseModel: model.BaseModel{
ID: model.StableID(uuid.NewString()),
ModelStoreID: manifest.ID(uuid.NewString()),
},
CreationTime: time.Now(),
SnapshotID: uuid.NewString(),
DetailsID: detailsID,
}
)
type StoreBackupUnitSuite struct {
tester.Suite
}
func TestStoreBackupUnitSuite(t *testing.T) {
suite.Run(t, &StoreBackupUnitSuite{Suite: tester.NewUnitSuite(t)})
}
func (suite *StoreBackupUnitSuite) TestGetBackup() {
table := []struct {
name string
mock *mock.ModelStore
expect assert.ErrorAssertionFunc
}{
{
name: "gets backup",
mock: mock.NewModelStoreMock(&bu, nil),
expect: assert.NoError,
},
{
name: "errors",
mock: mock.NewModelStoreMock(&bu, assert.AnError),
expect: assert.Error,
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
sm := store.NewWrapper(test.mock)
result, err := sm.GetBackup(ctx, model.StableID(uuid.NewString()))
test.expect(t, err, clues.ToCore(err))
if err != nil {
return
}
assert.Equal(t, bu.ID, result.ID)
})
}
}
func (suite *StoreBackupUnitSuite) TestGetBackups() {
table := []struct {
name string
mock *mock.ModelStore
expect assert.ErrorAssertionFunc
}{
{
name: "gets backups",
mock: mock.NewModelStoreMock(&bu, nil),
expect: assert.NoError,
},
{
name: "errors",
mock: mock.NewModelStoreMock(&bu, assert.AnError),
expect: assert.Error,
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
sm := store.NewWrapper(test.mock)
result, err := sm.GetBackups(ctx)
test.expect(t, err, clues.ToCore(err))
if err != nil {
return
}
assert.Equal(t, 1, len(result))
assert.Equal(t, bu.ID, result[0].ID)
})
}
}
func (suite *StoreBackupUnitSuite) TestDeleteBackup() {
table := []struct {
name string
mock *mock.ModelStore
expect assert.ErrorAssertionFunc
}{
{
name: "deletes backup",
mock: mock.NewModelStoreMock(&bu, nil),
expect: assert.NoError,
},
{
name: "errors",
mock: mock.NewModelStoreMock(&bu, assert.AnError),
expect: assert.Error,
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
sm := store.NewWrapper(test.mock)
err := sm.DeleteBackup(ctx, model.StableID(uuid.NewString()))
test.expect(t, err, clues.ToCore(err))
})
}
}