Update tests for GetRestoreResource
This commit is contained in:
parent
04d3e9019b
commit
064c1206a3
@ -69,7 +69,8 @@ func AddGroupsCategories(sel *selectors.GroupsBackup, cats []string) *selectors.
|
|||||||
|
|
||||||
func MakeGroupsOpts(cmd *cobra.Command) GroupsOpts {
|
func MakeGroupsOpts(cmd *cobra.Command) GroupsOpts {
|
||||||
restoreCfg := makeBaseRestoreCfgOpts(cmd)
|
restoreCfg := makeBaseRestoreCfgOpts(cmd)
|
||||||
restoreCfg.SubServiceType = path.SharePointService // this is the only possibility as of now
|
restoreCfg.SubServiceType = path.SharePointService // this is the only possibility as of now
|
||||||
|
|
||||||
restoreCfg.SubService = append(flags.SiteIDFV, flags.WebURLFV...)[0] // we should always have just one
|
restoreCfg.SubService = append(flags.SiteIDFV, flags.WebURLFV...)[0] // we should always have just one
|
||||||
|
|
||||||
return GroupsOpts{
|
return GroupsOpts{
|
||||||
|
|||||||
@ -50,6 +50,15 @@ func (ctrl Controller) ProduceBackupCollections(
|
|||||||
return ctrl.Collections, ctrl.Exclude, ctrl.Err == nil, ctrl.Err
|
return ctrl.Collections, ctrl.Exclude, ctrl.Err == nil, ctrl.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctrl Controller) GetRestoreResource(
|
||||||
|
ctx context.Context,
|
||||||
|
service path.ServiceType,
|
||||||
|
rc control.RestoreConfig,
|
||||||
|
orig idname.Provider,
|
||||||
|
) (path.ServiceType, idname.Provider, error) {
|
||||||
|
return service, orig, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ctrl *Controller) GetMetadataPaths(
|
func (ctrl *Controller) GetMetadataPaths(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
r kinject.RestoreProducer,
|
r kinject.RestoreProducer,
|
||||||
|
|||||||
@ -53,6 +53,7 @@ func (ctrl *Controller) GetRestoreResource(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctrl.IDNameLookup = idname.NewCache(map[string]string{pr.ID(): pr.Name()})
|
ctrl.IDNameLookup = idname.NewCache(map[string]string{pr.ID(): pr.Name()})
|
||||||
|
|
||||||
return svc, pr, nil
|
return svc, pr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
84
src/internal/m365/service/exchange/restore_test.go
Normal file
84
src/internal/m365/service/exchange/restore_test.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package exchange
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/idname"
|
||||||
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ExchangeRestoreUnitSuite struct {
|
||||||
|
tester.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExchangeRestoreUnitSuite(t *testing.T) {
|
||||||
|
suite.Run(t, &ExchangeRestoreUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *ExchangeRestoreUnitSuite) TestGetRestoreResource() {
|
||||||
|
var (
|
||||||
|
id = "id"
|
||||||
|
name = "name"
|
||||||
|
cfgWithPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
||||||
|
)
|
||||||
|
|
||||||
|
cfgWithPR.ProtectedResource = id
|
||||||
|
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
cfg control.RestoreConfig
|
||||||
|
orig idname.Provider
|
||||||
|
cache map[string]string
|
||||||
|
expectErr assert.ErrorAssertionFunc
|
||||||
|
expectProvider assert.ValueAssertionFunc
|
||||||
|
expectID string
|
||||||
|
expectName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "use original",
|
||||||
|
cfg: control.DefaultRestoreConfig(dttm.HumanReadable),
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: "oid",
|
||||||
|
expectName: "oname",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "use new",
|
||||||
|
cfg: cfgWithPR,
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
cache: map[string]string{id: name},
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: id,
|
||||||
|
expectName: name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(test.name, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
svc, result, err := GetRestoreResource(
|
||||||
|
ctx,
|
||||||
|
api.Client{},
|
||||||
|
test.cfg,
|
||||||
|
idname.NewCache(test.cache),
|
||||||
|
test.orig)
|
||||||
|
test.expectErr(t, err, clues.ToCore(err))
|
||||||
|
require.NotNil(t, result)
|
||||||
|
assert.Equal(t, path.ExchangeService, svc)
|
||||||
|
assert.Equal(t, test.expectID, result.ID())
|
||||||
|
assert.Equal(t, test.expectName, result.Name())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||||
"github.com/alcionai/corso/src/internal/common/idname"
|
"github.com/alcionai/corso/src/internal/common/idname"
|
||||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
@ -65,6 +66,73 @@ func (suite *GroupsUnitSuite) TestConsumeRestoreCollections_noErrorOnGroups() {
|
|||||||
assert.NoError(t, err, "Groups Channels restore")
|
assert.NoError(t, err, "Groups Channels restore")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *GroupsUnitSuite) TestGetRestoreResource() {
|
||||||
|
var (
|
||||||
|
sid = "site-id"
|
||||||
|
sname = "site-name"
|
||||||
|
nsid = "new-site-id"
|
||||||
|
nsname = "new-site-name"
|
||||||
|
cfgWithoutPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
||||||
|
cfgWithPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
||||||
|
)
|
||||||
|
|
||||||
|
cfgWithoutPR.SubService.Type = path.SharePointService
|
||||||
|
cfgWithoutPR.SubService.ID = sid
|
||||||
|
cfgWithPR.ProtectedResource = nsid
|
||||||
|
cfgWithPR.SubService.Type = path.SharePointService
|
||||||
|
cfgWithPR.SubService.ID = sid
|
||||||
|
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
cfg control.RestoreConfig
|
||||||
|
orig idname.Provider
|
||||||
|
cache map[string]string
|
||||||
|
expectErr assert.ErrorAssertionFunc
|
||||||
|
expectProvider assert.ValueAssertionFunc
|
||||||
|
expectID string
|
||||||
|
expectName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "use original",
|
||||||
|
cfg: cfgWithoutPR,
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
cache: map[string]string{sid: sname},
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: sid,
|
||||||
|
expectName: sname,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "use new",
|
||||||
|
cfg: cfgWithPR,
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
cache: map[string]string{nsid: nsname},
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: nsid,
|
||||||
|
expectName: nsname,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(test.name, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
svc, result, err := GetRestoreResource(
|
||||||
|
ctx,
|
||||||
|
api.Client{},
|
||||||
|
test.cfg,
|
||||||
|
idname.NewCache(test.cache),
|
||||||
|
test.orig)
|
||||||
|
test.expectErr(t, err, clues.ToCore(err))
|
||||||
|
require.NotNil(t, result)
|
||||||
|
assert.Equal(t, path.SharePointService, svc)
|
||||||
|
assert.Equal(t, test.expectID, result.ID())
|
||||||
|
assert.Equal(t, test.expectName, result.Name())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type groupsIntegrationSuite struct {
|
type groupsIntegrationSuite struct {
|
||||||
tester.Suite
|
tester.Suite
|
||||||
resource string
|
resource string
|
||||||
|
|||||||
@ -8,9 +8,13 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/idname"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/internal/version"
|
"github.com/alcionai/corso/src/internal/version"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RestoreUnitSuite struct {
|
type RestoreUnitSuite struct {
|
||||||
@ -315,3 +319,62 @@ func (suite *RestoreUnitSuite) TestAugmentRestorePaths_DifferentRestorePath() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *RestoreUnitSuite) TestGetRestoreResource() {
|
||||||
|
var (
|
||||||
|
id = "id"
|
||||||
|
name = "name"
|
||||||
|
cfgWithPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
||||||
|
)
|
||||||
|
|
||||||
|
cfgWithPR.ProtectedResource = id
|
||||||
|
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
cfg control.RestoreConfig
|
||||||
|
orig idname.Provider
|
||||||
|
cache map[string]string
|
||||||
|
expectErr assert.ErrorAssertionFunc
|
||||||
|
expectProvider assert.ValueAssertionFunc
|
||||||
|
expectID string
|
||||||
|
expectName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "use original",
|
||||||
|
cfg: control.DefaultRestoreConfig(dttm.HumanReadable),
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: "oid",
|
||||||
|
expectName: "oname",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "use new",
|
||||||
|
cfg: cfgWithPR,
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
cache: map[string]string{id: name},
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: id,
|
||||||
|
expectName: name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(test.name, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
svc, result, err := GetRestoreResource(
|
||||||
|
ctx,
|
||||||
|
api.Client{},
|
||||||
|
test.cfg,
|
||||||
|
idname.NewCache(test.cache),
|
||||||
|
test.orig)
|
||||||
|
test.expectErr(t, err, clues.ToCore(err))
|
||||||
|
require.NotNil(t, result)
|
||||||
|
assert.Equal(t, path.OneDriveService, svc)
|
||||||
|
assert.Equal(t, test.expectID, result.ID())
|
||||||
|
assert.Equal(t, test.expectName, result.Name())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
84
src/internal/m365/service/sharepoint/restore_test.go
Normal file
84
src/internal/m365/service/sharepoint/restore_test.go
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package sharepoint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/alcionai/clues"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/alcionai/corso/src/internal/common/dttm"
|
||||||
|
"github.com/alcionai/corso/src/internal/common/idname"
|
||||||
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SharepointRestoreUnitSuite struct {
|
||||||
|
tester.Suite
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSharepointRestoreUnitSuite(t *testing.T) {
|
||||||
|
suite.Run(t, &SharepointRestoreUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *SharepointRestoreUnitSuite) TestGetRestoreResource() {
|
||||||
|
var (
|
||||||
|
id = "id"
|
||||||
|
name = "name"
|
||||||
|
cfgWithPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
||||||
|
)
|
||||||
|
|
||||||
|
cfgWithPR.ProtectedResource = id
|
||||||
|
|
||||||
|
table := []struct {
|
||||||
|
name string
|
||||||
|
cfg control.RestoreConfig
|
||||||
|
orig idname.Provider
|
||||||
|
cache map[string]string
|
||||||
|
expectErr assert.ErrorAssertionFunc
|
||||||
|
expectProvider assert.ValueAssertionFunc
|
||||||
|
expectID string
|
||||||
|
expectName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "use original",
|
||||||
|
cfg: control.DefaultRestoreConfig(dttm.HumanReadable),
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: "oid",
|
||||||
|
expectName: "oname",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "use new",
|
||||||
|
cfg: cfgWithPR,
|
||||||
|
orig: idname.NewProvider("oid", "oname"),
|
||||||
|
cache: map[string]string{id: name},
|
||||||
|
expectErr: assert.NoError,
|
||||||
|
expectID: id,
|
||||||
|
expectName: name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(test.name, func() {
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext(t)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
svc, result, err := GetRestoreResource(
|
||||||
|
ctx,
|
||||||
|
api.Client{},
|
||||||
|
test.cfg,
|
||||||
|
idname.NewCache(test.cache),
|
||||||
|
test.orig)
|
||||||
|
test.expectErr(t, err, clues.ToCore(err))
|
||||||
|
require.NotNil(t, result)
|
||||||
|
assert.Equal(t, path.SharePointService, svc)
|
||||||
|
assert.Equal(t, test.expectID, result.ID())
|
||||||
|
assert.Equal(t, test.expectName, result.Name())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -10,8 +10,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common/dttm"
|
|
||||||
"github.com/alcionai/corso/src/internal/common/idname"
|
|
||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/internal/events"
|
"github.com/alcionai/corso/src/internal/events"
|
||||||
evmock "github.com/alcionai/corso/src/internal/events/mock"
|
evmock "github.com/alcionai/corso/src/internal/events/mock"
|
||||||
@ -136,75 +134,6 @@ func (suite *RestoreOpUnitSuite) TestRestoreOperation_PersistResults() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpUnitSuite) TestChooseRestoreResource() {
|
|
||||||
var (
|
|
||||||
id = "id"
|
|
||||||
name = "name"
|
|
||||||
cfgWithPR = control.DefaultRestoreConfig(dttm.HumanReadable)
|
|
||||||
)
|
|
||||||
|
|
||||||
cfgWithPR.ProtectedResource = "cfgid"
|
|
||||||
|
|
||||||
table := []struct {
|
|
||||||
name string
|
|
||||||
cfg control.RestoreConfig
|
|
||||||
ctrl *mock.Controller
|
|
||||||
orig idname.Provider
|
|
||||||
expectErr assert.ErrorAssertionFunc
|
|
||||||
expectProvider assert.ValueAssertionFunc
|
|
||||||
expectID string
|
|
||||||
expectName string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "use original",
|
|
||||||
cfg: control.DefaultRestoreConfig(dttm.HumanReadable),
|
|
||||||
ctrl: &mock.Controller{
|
|
||||||
ProtectedResourceID: id,
|
|
||||||
ProtectedResourceName: name,
|
|
||||||
},
|
|
||||||
orig: idname.NewProvider("oid", "oname"),
|
|
||||||
expectErr: assert.NoError,
|
|
||||||
expectID: "oid",
|
|
||||||
expectName: "oname",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "look up resource with iface",
|
|
||||||
cfg: cfgWithPR,
|
|
||||||
ctrl: &mock.Controller{
|
|
||||||
ProtectedResourceID: id,
|
|
||||||
ProtectedResourceName: name,
|
|
||||||
},
|
|
||||||
orig: idname.NewProvider("oid", "oname"),
|
|
||||||
expectErr: assert.NoError,
|
|
||||||
expectID: id,
|
|
||||||
expectName: name,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "error looking up protected resource",
|
|
||||||
cfg: cfgWithPR,
|
|
||||||
ctrl: &mock.Controller{
|
|
||||||
ProtectedResourceErr: assert.AnError,
|
|
||||||
},
|
|
||||||
orig: idname.NewProvider("oid", "oname"),
|
|
||||||
expectErr: assert.Error,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, test := range table {
|
|
||||||
suite.Run(test.name, func() {
|
|
||||||
t := suite.T()
|
|
||||||
|
|
||||||
ctx, flush := tester.NewContext(t)
|
|
||||||
defer flush()
|
|
||||||
|
|
||||||
svc, result, err := chooseRestoreResource(ctx, test.ctrl, test.cfg, test.orig)
|
|
||||||
test.expectErr(t, err, clues.ToCore(err))
|
|
||||||
require.NotNil(t, result)
|
|
||||||
assert.Equal(t, test.expectID, result.ID())
|
|
||||||
assert.Equal(t, test.expectName, result.Name())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// integration
|
// integration
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user