attach logger to test ctx, use flusher (#1083)
## Description Replace all cases of context.Background() and context.TODO() with the testing ctx, which seeds a logging instance into the context. The seed is less important than the flush action, since errant log.Ctx(ctx) calls will automatically use the log singleton. But in order for the logs to show up within the test, they need to get flushed. See my comments for focus on non-chaff changes. ## Type of change - [x] 🤖 Test ## Issue(s) * #902 ## Test Plan - [x] 💪 Manual - [x] ⚡ Unit test
This commit is contained in:
parent
211c248f35
commit
0b65b20200
@ -61,6 +61,10 @@ func TestBackupExchangeIntegrationSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *BackupExchangeIntegrationSuite) SetupSuite() {
|
func (suite *BackupExchangeIntegrationSuite) SetupSuite() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := tester.GetRequiredEnvSls(
|
_, err := tester.GetRequiredEnvSls(
|
||||||
tester.AWSStorageCredEnvs,
|
tester.AWSStorageCredEnvs,
|
||||||
tester.M365AcctCredEnvs)
|
tester.M365AcctCredEnvs)
|
||||||
@ -82,7 +86,7 @@ func (suite *BackupExchangeIntegrationSuite) SetupSuite() {
|
|||||||
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
suite.m365UserID = tester.M365UserID(t)
|
suite.m365UserID = tester.M365UserID(t)
|
||||||
|
|
||||||
// init the repo first
|
// init the repo first
|
||||||
@ -97,7 +101,9 @@ func (suite *BackupExchangeIntegrationSuite) TestExchangeBackupCmd() {
|
|||||||
recorder.Reset()
|
recorder.Reset()
|
||||||
|
|
||||||
suite.T().Run(set.String(), func(t *testing.T) {
|
suite.T().Run(set.String(), func(t *testing.T) {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
cmd := tester.StubRootCmd(
|
cmd := tester.StubRootCmd(
|
||||||
"backup", "create", "exchange",
|
"backup", "create", "exchange",
|
||||||
@ -171,7 +177,11 @@ func (suite *PreparedBackupExchangeIntegrationSuite) SetupSuite() {
|
|||||||
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
suite.m365UserID = tester.M365UserID(t)
|
suite.m365UserID = tester.M365UserID(t)
|
||||||
|
|
||||||
// init the repo first
|
// init the repo first
|
||||||
@ -220,7 +230,9 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeListCmd() {
|
|||||||
recorder.Reset()
|
recorder.Reset()
|
||||||
|
|
||||||
suite.T().Run(set.String(), func(t *testing.T) {
|
suite.T().Run(set.String(), func(t *testing.T) {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
cmd := tester.StubRootCmd(
|
cmd := tester.StubRootCmd(
|
||||||
"backup", "list", "exchange",
|
"backup", "list", "exchange",
|
||||||
@ -248,7 +260,10 @@ func (suite *PreparedBackupExchangeIntegrationSuite) TestExchangeDetailsCmd() {
|
|||||||
recorder.Reset()
|
recorder.Reset()
|
||||||
|
|
||||||
suite.T().Run(set.String(), func(t *testing.T) {
|
suite.T().Run(set.String(), func(t *testing.T) {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
defer flush()
|
||||||
|
|
||||||
bID := suite.backupOps[set].Results.BackupID
|
bID := suite.backupOps[set].Results.BackupID
|
||||||
|
|
||||||
// fetch the details from the repo first
|
// fetch the details from the repo first
|
||||||
@ -342,7 +357,10 @@ func (suite *BackupDeleteExchangeIntegrationSuite) SetupSuite() {
|
|||||||
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
// init the repo first
|
// init the repo first
|
||||||
suite.repo, err = repository.Initialize(ctx, suite.acct, suite.st, control.Options{})
|
suite.repo, err = repository.Initialize(ctx, suite.acct, suite.st, control.Options{})
|
||||||
@ -360,8 +378,11 @@ func (suite *BackupDeleteExchangeIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *BackupDeleteExchangeIntegrationSuite) TestExchangeBackupDeleteCmd() {
|
func (suite *BackupDeleteExchangeIntegrationSuite) TestExchangeBackupDeleteCmd() {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
cmd := tester.StubRootCmd(
|
cmd := tester.StubRootCmd(
|
||||||
"backup", "delete", "exchange",
|
"backup", "delete", "exchange",
|
||||||
@ -383,8 +404,11 @@ func (suite *BackupDeleteExchangeIntegrationSuite) TestExchangeBackupDeleteCmd()
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *BackupDeleteExchangeIntegrationSuite) TestExchangeBackupDeleteCmd_UnknownID() {
|
func (suite *BackupDeleteExchangeIntegrationSuite) TestExchangeBackupDeleteCmd_UnknownID() {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
cmd := tester.StubRootCmd(
|
cmd := tester.StubRootCmd(
|
||||||
"backup", "delete", "exchange",
|
"backup", "delete", "exchange",
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package backup
|
package backup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -215,7 +214,8 @@ func (suite *ExchangeSuite) TestExchangeBackupCreateSelectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectors() {
|
func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectors() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
for _, test := range testdata.ExchangeOptionDetailLookups {
|
for _, test := range testdata.ExchangeOptionDetailLookups {
|
||||||
suite.T().Run(test.Name, func(t *testing.T) {
|
suite.T().Run(test.Name, func(t *testing.T) {
|
||||||
@ -234,9 +234,11 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectors() {
|
|||||||
|
|
||||||
func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadBackupID() {
|
func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadBackupID() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
backupGetter := &testdata.MockBackupGetter{}
|
backupGetter := &testdata.MockBackupGetter{}
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
output, err := runDetailsExchangeCmd(
|
output, err := runDetailsExchangeCmd(
|
||||||
ctx,
|
ctx,
|
||||||
backupGetter,
|
backupGetter,
|
||||||
@ -250,7 +252,8 @@ func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadBackupID() {
|
|||||||
|
|
||||||
// TODO(ashmrtn): Uncomment these when the CLI validates flag input values.
|
// TODO(ashmrtn): Uncomment these when the CLI validates flag input values.
|
||||||
//func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadFormats() {
|
//func (suite *ExchangeSuite) TestExchangeBackupDetailsSelectorsBadFormats() {
|
||||||
// ctx := context.Background()
|
// ctx, flush := tester.NewContext()
|
||||||
|
// defer flush()
|
||||||
//
|
//
|
||||||
// for _, test := range testdata.BadExchangeOptionsFormats {
|
// for _, test := range testdata.BadExchangeOptionsFormats {
|
||||||
// suite.T().Run(test.Name, func(t *testing.T) {
|
// suite.T().Run(test.Name, func(t *testing.T) {
|
||||||
|
|||||||
@ -10,10 +10,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/cli"
|
"github.com/alcionai/corso/src/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CliSuite struct {
|
|
||||||
suite.Suite
|
|
||||||
}
|
|
||||||
|
|
||||||
type CLISuite struct {
|
type CLISuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,13 +2,12 @@ package print
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PrintUnitSuite struct {
|
type PrintUnitSuite struct {
|
||||||
@ -20,10 +19,10 @@ func TestPrintUnitSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PrintUnitSuite) TestOnly() {
|
func (suite *PrintUnitSuite) TestOnly() {
|
||||||
ctx := tester.NewContext()
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
c := &cobra.Command{}
|
c := &cobra.Command{}
|
||||||
ctx = SetRootCmd(ctx, c)
|
// cannot use tester.NewContext() here: circular imports
|
||||||
|
ctx := SetRootCmd(context.Background(), c)
|
||||||
assert.NoError(t, Only(ctx, nil))
|
assert.NoError(t, Only(ctx, nil))
|
||||||
assert.True(t, c.SilenceUsage)
|
assert.True(t, c.SilenceUsage)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,8 @@ func (suite *S3IntegrationSuite) TestInitS3Cmd() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
@ -80,8 +81,10 @@ func (suite *S3IntegrationSuite) TestInitS3Cmd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *S3IntegrationSuite) TestInitMultipleTimes() {
|
func (suite *S3IntegrationSuite) TestInitMultipleTimes() {
|
||||||
ctx := tester.NewContext()
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
@ -108,8 +111,10 @@ func (suite *S3IntegrationSuite) TestInitMultipleTimes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *S3IntegrationSuite) TestInitS3Cmd_missingBucket() {
|
func (suite *S3IntegrationSuite) TestInitS3Cmd_missingBucket() {
|
||||||
ctx := tester.NewContext()
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
@ -147,7 +152,9 @@ func (suite *S3IntegrationSuite) TestConnectS3Cmd() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -182,8 +189,10 @@ func (suite *S3IntegrationSuite) TestConnectS3Cmd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *S3IntegrationSuite) TestConnectS3Cmd_BadBucket() {
|
func (suite *S3IntegrationSuite) TestConnectS3Cmd_BadBucket() {
|
||||||
ctx := tester.NewContext()
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
@ -206,8 +215,10 @@ func (suite *S3IntegrationSuite) TestConnectS3Cmd_BadBucket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *S3IntegrationSuite) TestConnectS3Cmd_BadPrefix() {
|
func (suite *S3IntegrationSuite) TestConnectS3Cmd_BadPrefix() {
|
||||||
ctx := tester.NewContext()
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
cfg, err := st.S3Config()
|
cfg, err := st.S3Config()
|
||||||
|
|||||||
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/control"
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
"github.com/alcionai/corso/src/pkg/repository"
|
"github.com/alcionai/corso/src/pkg/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
@ -59,6 +58,10 @@ func TestRestoreExchangeIntegrationSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := tester.GetRequiredEnvSls(
|
_, err := tester.GetRequiredEnvSls(
|
||||||
tester.AWSStorageCredEnvs,
|
tester.AWSStorageCredEnvs,
|
||||||
tester.M365AcctCredEnvs,
|
tester.M365AcctCredEnvs,
|
||||||
@ -80,7 +83,6 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
|||||||
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
suite.vpr, suite.cfgFP, err = tester.MakeTempTestConfigClone(t, force)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
|
||||||
suite.m365UserID = tester.M365UserID(t)
|
suite.m365UserID = tester.M365UserID(t)
|
||||||
|
|
||||||
// init the repo first
|
// init the repo first
|
||||||
@ -125,9 +127,10 @@ func (suite *RestoreExchangeIntegrationSuite) SetupSuite() {
|
|||||||
func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd() {
|
func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd() {
|
||||||
for _, set := range backupDataSets {
|
for _, set := range backupDataSets {
|
||||||
suite.T().Run(set.String(), func(t *testing.T) {
|
suite.T().Run(set.String(), func(t *testing.T) {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
ctx, _ = logger.SeedLevel(ctx, logger.Development)
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
defer logger.Flush(ctx)
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
cmd := tester.StubRootCmd(
|
cmd := tester.StubRootCmd(
|
||||||
"restore", "exchange",
|
"restore", "exchange",
|
||||||
@ -148,9 +151,10 @@ func (suite *RestoreExchangeIntegrationSuite) TestExchangeRestoreCmd_badTimeFlag
|
|||||||
}
|
}
|
||||||
|
|
||||||
suite.T().Run(set.String(), func(t *testing.T) {
|
suite.T().Run(set.String(), func(t *testing.T) {
|
||||||
ctx := config.SetViper(tester.NewContext(), suite.vpr)
|
ctx, flush := tester.NewContext()
|
||||||
ctx, _ = logger.SeedLevel(ctx, logger.Development)
|
ctx = config.SetViper(ctx, suite.vpr)
|
||||||
defer logger.Flush(ctx)
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var timeFilter string
|
var timeFilter string
|
||||||
switch set {
|
switch set {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package common_test
|
package common_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -12,7 +11,6 @@ import (
|
|||||||
|
|
||||||
type CommonBucketsSuite struct {
|
type CommonBucketsSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ctx context.Context
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCommonBucketsSuite(t *testing.T) {
|
func TestCommonBucketsSuite(t *testing.T) {
|
||||||
|
|||||||
@ -260,7 +260,9 @@ func (suite *ExchangeServiceSuite) TestSetupExchangeCollection() {
|
|||||||
// TestGraphQueryFunctions verifies if Query functions APIs
|
// TestGraphQueryFunctions verifies if Query functions APIs
|
||||||
// through Microsoft Graph are functional
|
// through Microsoft Graph are functional
|
||||||
func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() {
|
func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
userID := tester.M365UserID(suite.T())
|
userID := tester.M365UserID(suite.T())
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -309,7 +311,10 @@ func (suite *ExchangeServiceSuite) TestGraphQueryFunctions() {
|
|||||||
// at the top level of the file tree
|
// at the top level of the file tree
|
||||||
func (suite *ExchangeServiceSuite) TestGetContainerID() {
|
func (suite *ExchangeServiceSuite) TestGetContainerID() {
|
||||||
userID := tester.M365UserID(suite.T())
|
userID := tester.M365UserID(suite.T())
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
containerName string
|
containerName string
|
||||||
@ -370,14 +375,16 @@ func (suite *ExchangeServiceSuite) TestGetContainerID() {
|
|||||||
|
|
||||||
//==========================
|
//==========================
|
||||||
// Restore Functions
|
// Restore Functions
|
||||||
//======================
|
//==========================
|
||||||
|
|
||||||
// TestRestoreContact ensures contact object can be created, placed into
|
// TestRestoreContact ensures contact object can be created, placed into
|
||||||
// the Corso Folder. The function handles test clean-up.
|
// the Corso Folder. The function handles test clean-up.
|
||||||
func (suite *ExchangeServiceSuite) TestRestoreContact() {
|
func (suite *ExchangeServiceSuite) TestRestoreContact() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t = suite.T()
|
t = suite.T()
|
||||||
ctx = context.Background()
|
|
||||||
userID = tester.M365UserID(t)
|
userID = tester.M365UserID(t)
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
folderName = "TestRestoreContact: " + common.FormatSimpleDateTime(now)
|
folderName = "TestRestoreContact: " + common.FormatSimpleDateTime(now)
|
||||||
@ -394,7 +401,7 @@ func (suite *ExchangeServiceSuite) TestRestoreContact() {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
info, err := RestoreExchangeContact(context.Background(),
|
info, err := RestoreExchangeContact(ctx,
|
||||||
mockconnector.GetMockContactBytes("Corso TestContact"),
|
mockconnector.GetMockContactBytes("Corso TestContact"),
|
||||||
suite.es,
|
suite.es,
|
||||||
control.Copy,
|
control.Copy,
|
||||||
@ -407,9 +414,11 @@ func (suite *ExchangeServiceSuite) TestRestoreContact() {
|
|||||||
// TestRestoreEvent verifies that event object is able to created
|
// TestRestoreEvent verifies that event object is able to created
|
||||||
// and sent into the test account of the Corso user in the newly created Corso Calendar
|
// and sent into the test account of the Corso user in the newly created Corso Calendar
|
||||||
func (suite *ExchangeServiceSuite) TestRestoreEvent() {
|
func (suite *ExchangeServiceSuite) TestRestoreEvent() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t = suite.T()
|
t = suite.T()
|
||||||
ctx = context.Background()
|
|
||||||
userID = tester.M365UserID(t)
|
userID = tester.M365UserID(t)
|
||||||
name = "TestRestoreEvent: " + common.FormatSimpleDateTime(time.Now())
|
name = "TestRestoreEvent: " + common.FormatSimpleDateTime(time.Now())
|
||||||
)
|
)
|
||||||
@ -425,7 +434,7 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
info, err := RestoreExchangeEvent(context.Background(),
|
info, err := RestoreExchangeEvent(ctx,
|
||||||
mockconnector.GetMockEventWithAttendeesBytes(name),
|
mockconnector.GetMockEventWithAttendeesBytes(name),
|
||||||
suite.es,
|
suite.es,
|
||||||
control.Copy,
|
control.Copy,
|
||||||
@ -438,7 +447,9 @@ func (suite *ExchangeServiceSuite) TestRestoreEvent() {
|
|||||||
// TestGetRestoreContainer checks the ability to Create a "container" for the
|
// TestGetRestoreContainer checks the ability to Create a "container" for the
|
||||||
// GraphConnector's Restore Workflow based on OptionIdentifier.
|
// GraphConnector's Restore Workflow based on OptionIdentifier.
|
||||||
func (suite *ExchangeServiceSuite) TestGetRestoreContainer() {
|
func (suite *ExchangeServiceSuite) TestGetRestoreContainer() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
dest := tester.DefaultTestRestoreDestination()
|
dest := tester.DefaultTestRestoreDestination()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -498,7 +509,9 @@ func (suite *ExchangeServiceSuite) TestGetRestoreContainer() {
|
|||||||
|
|
||||||
// TestRestoreExchangeObject verifies path.Category usage for restored objects
|
// TestRestoreExchangeObject verifies path.Category usage for restored objects
|
||||||
func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
func (suite *ExchangeServiceSuite) TestRestoreExchangeObject() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
userID := tester.M365UserID(t)
|
userID := tester.M365UserID(t)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package exchange
|
package exchange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
||||||
@ -71,8 +70,10 @@ func loadService(t *testing.T) *exchangeService {
|
|||||||
// TestIterativeFunctions verifies that GraphQuery to Iterate
|
// TestIterativeFunctions verifies that GraphQuery to Iterate
|
||||||
// functions are valid for current versioning of msgraph-go-sdk
|
// functions are valid for current versioning of msgraph-go-sdk
|
||||||
func (suite *ExchangeIteratorSuite) TestIterativeFunctions() {
|
func (suite *ExchangeIteratorSuite) TestIterativeFunctions() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
|
||||||
t = suite.T()
|
t = suite.T()
|
||||||
mailScope, contactScope, eventScope []selectors.ExchangeScope
|
mailScope, contactScope, eventScope []selectors.ExchangeScope
|
||||||
userID = tester.M365UserID(t)
|
userID = tester.M365UserID(t)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package exchange
|
package exchange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
stdpath "path"
|
stdpath "path"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -220,7 +219,8 @@ func TestConfiguredMailFolderCacheUnitSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderNoPathsCached() {
|
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderNoPathsCached() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
for _, c := range suite.allContainers {
|
for _, c := range suite.allContainers {
|
||||||
suite.T().Run(*c.GetDisplayName(), func(t *testing.T) {
|
suite.T().Run(*c.GetDisplayName(), func(t *testing.T) {
|
||||||
@ -233,8 +233,10 @@ func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderNoPathsCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderCachesPaths() {
|
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderCachesPaths() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
c := suite.allContainers[len(suite.allContainers)-1]
|
c := suite.allContainers[len(suite.allContainers)-1]
|
||||||
|
|
||||||
p, err := suite.mc.IDToPath(ctx, c.id)
|
p, err := suite.mc.IDToPath(ctx, c.id)
|
||||||
@ -251,8 +253,10 @@ func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderCachesPat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderErrorsParentNotFound() {
|
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderErrorsParentNotFound() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
last := suite.allContainers[len(suite.allContainers)-1]
|
last := suite.allContainers[len(suite.allContainers)-1]
|
||||||
almostLast := suite.allContainers[len(suite.allContainers)-2]
|
almostLast := suite.allContainers[len(suite.allContainers)-2]
|
||||||
|
|
||||||
@ -263,8 +267,10 @@ func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderErrorsPar
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderErrorsNotFound() {
|
func (suite *ConfiguredMailFolderCacheUnitSuite) TestLookupCachedFolderErrorsNotFound() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
_, err := suite.mc.IDToPath(ctx, "foo")
|
_, err := suite.mc.IDToPath(ctx, "foo")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
@ -305,6 +311,9 @@ func TestMailFolderCacheIntegrationSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MailFolderCacheIntegrationSuite) TestDeltaFetch() {
|
func (suite *MailFolderCacheIntegrationSuite) TestDeltaFetch() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
root string
|
root string
|
||||||
@ -318,7 +327,6 @@ func (suite *MailFolderCacheIntegrationSuite) TestDeltaFetch() {
|
|||||||
root: topFolderID,
|
root: topFolderID,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
|
||||||
userID := tester.M365UserID(suite.T())
|
userID := tester.M365UserID(suite.T())
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package exchange
|
package exchange
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -34,8 +33,10 @@ func (suite *ServiceFunctionsIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllCalendars() {
|
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllCalendars() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
gs := loadService(suite.T())
|
gs := loadService(suite.T())
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name, contains, user string
|
name, contains, user string
|
||||||
@ -79,9 +80,11 @@ func (suite *ServiceFunctionsIntegrationSuite) TestGetAllCalendars() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllContactFolders() {
|
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllContactFolders() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
gs := loadService(suite.T())
|
gs := loadService(suite.T())
|
||||||
user := tester.M365UserID(suite.T())
|
user := tester.M365UserID(suite.T())
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name, contains, user string
|
name, contains, user string
|
||||||
@ -125,8 +128,10 @@ func (suite *ServiceFunctionsIntegrationSuite) TestGetAllContactFolders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllMailFolders() {
|
func (suite *ServiceFunctionsIntegrationSuite) TestGetAllMailFolders() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
gs := loadService(suite.T())
|
gs := loadService(suite.T())
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name, contains, user string
|
name, contains, user string
|
||||||
@ -170,7 +175,9 @@ func (suite *ServiceFunctionsIntegrationSuite) TestGetAllMailFolders() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ServiceFunctionsIntegrationSuite) TestCollectContainers() {
|
func (suite *ServiceFunctionsIntegrationSuite) TestCollectContainers() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
failFast := false
|
failFast := false
|
||||||
containerCount := 1
|
containerCount := 1
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package connector
|
package connector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -30,7 +29,9 @@ func TestDisconnectedGraphSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DisconnectedGraphConnectorSuite) TestBadConnection() {
|
func (suite *DisconnectedGraphConnectorSuite) TestBadConnection() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
acct func(t *testing.T) account.Account
|
acct func(t *testing.T) account.Account
|
||||||
@ -88,8 +89,11 @@ func (suite *DisconnectedGraphConnectorSuite) TestBuild() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func statusTestTask(gc *GraphConnector, objects, success, folder int) {
|
func statusTestTask(gc *GraphConnector, objects, success, folder int) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
status := support.CreateStatus(
|
status := support.CreateStatus(
|
||||||
context.Background(),
|
ctx,
|
||||||
support.Restore, folder,
|
support.Restore, folder,
|
||||||
support.CollectionMetrics{
|
support.CollectionMetrics{
|
||||||
Objects: objects,
|
Objects: objects,
|
||||||
@ -181,7 +185,10 @@ func (suite *DisconnectedGraphConnectorSuite) TestGraphConnector_ErrorChecking()
|
|||||||
|
|
||||||
func (suite *DisconnectedGraphConnectorSuite) TestRestoreFailsBadService() {
|
func (suite *DisconnectedGraphConnectorSuite) TestRestoreFailsBadService() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
gc := GraphConnector{wg: &sync.WaitGroup{}}
|
gc := GraphConnector{wg: &sync.WaitGroup{}}
|
||||||
sel := selectors.Selector{
|
sel := selectors.Selector{
|
||||||
Service: selectors.ServiceUnknown,
|
Service: selectors.ServiceUnknown,
|
||||||
|
|||||||
@ -45,7 +45,9 @@ func TestGraphConnectorIntegrationSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *GraphConnectorIntegrationSuite) SetupSuite() {
|
func (suite *GraphConnectorIntegrationSuite) SetupSuite() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
suite.connector = loadConnector(ctx, suite.T())
|
suite.connector = loadConnector(ctx, suite.T())
|
||||||
@ -61,7 +63,10 @@ func (suite *GraphConnectorIntegrationSuite) TestSetTenantUsers() {
|
|||||||
Users: make(map[string]string, 0),
|
Users: make(map[string]string, 0),
|
||||||
credentials: suite.connector.credentials,
|
credentials: suite.connector.credentials,
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
service, err := newConnector.createService(false)
|
service, err := newConnector.createService(false)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
@ -80,7 +85,9 @@ func (suite *GraphConnectorIntegrationSuite) TestSetTenantUsers() {
|
|||||||
// - contacts
|
// - contacts
|
||||||
// - events
|
// - events
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestExchangeDataCollection() {
|
func (suite *GraphConnectorIntegrationSuite) TestExchangeDataCollection() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
connector := loadConnector(ctx, suite.T())
|
connector := loadConnector(ctx, suite.T())
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -137,12 +144,14 @@ func (suite *GraphConnectorIntegrationSuite) TestExchangeDataCollection() {
|
|||||||
// test account can be successfully downloaded into bytes and restored into
|
// test account can be successfully downloaded into bytes and restored into
|
||||||
// M365 mail objects
|
// M365 mail objects
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestMailSerializationRegression() {
|
func (suite *GraphConnectorIntegrationSuite) TestMailSerializationRegression() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
connector := loadConnector(ctx, t)
|
connector := loadConnector(ctx, t)
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.MailFolders([]string{suite.user}, []string{exchange.DefaultMailFolder}))
|
sel.Include(sel.MailFolders([]string{suite.user}, []string{exchange.DefaultMailFolder}))
|
||||||
collection, err := connector.createCollections(context.Background(), sel.Scopes()[0])
|
collection, err := connector.createCollections(ctx, sel.Scopes()[0])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for _, edc := range collection {
|
for _, edc := range collection {
|
||||||
@ -170,7 +179,10 @@ func (suite *GraphConnectorIntegrationSuite) TestMailSerializationRegression() {
|
|||||||
// and to store contact within Collection. Downloaded contacts are run through
|
// and to store contact within Collection. Downloaded contacts are run through
|
||||||
// a regression test to ensure that downloaded items can be uploaded.
|
// a regression test to ensure that downloaded items can be uploaded.
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestContactSerializationRegression() {
|
func (suite *GraphConnectorIntegrationSuite) TestContactSerializationRegression() {
|
||||||
connector := loadConnector(context.Background(), suite.T())
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
connector := loadConnector(ctx, suite.T())
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -181,7 +193,7 @@ func (suite *GraphConnectorIntegrationSuite) TestContactSerializationRegression(
|
|||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []*exchange.Collection {
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.ContactFolders([]string{suite.user}, []string{exchange.DefaultContactFolder}))
|
sel.Include(sel.ContactFolders([]string{suite.user}, []string{exchange.DefaultContactFolder}))
|
||||||
collections, err := connector.createCollections(context.Background(), sel.Scopes()[0])
|
collections, err := connector.createCollections(ctx, sel.Scopes()[0])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return collections
|
return collections
|
||||||
@ -219,7 +231,10 @@ func (suite *GraphConnectorIntegrationSuite) TestContactSerializationRegression(
|
|||||||
// TestEventsSerializationRegression ensures functionality of createCollections
|
// TestEventsSerializationRegression ensures functionality of createCollections
|
||||||
// to be able to successfully query, download and restore event objects
|
// to be able to successfully query, download and restore event objects
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression() {
|
func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression() {
|
||||||
connector := loadConnector(context.Background(), suite.T())
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
|
connector := loadConnector(ctx, suite.T())
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name, expected string
|
name, expected string
|
||||||
@ -231,7 +246,7 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression()
|
|||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []*exchange.Collection {
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.EventCalendars([]string{suite.user}, []string{exchange.DefaultCalendar}))
|
sel.Include(sel.EventCalendars([]string{suite.user}, []string{exchange.DefaultCalendar}))
|
||||||
collections, err := connector.createCollections(context.Background(), sel.Scopes()[0])
|
collections, err := connector.createCollections(ctx, sel.Scopes()[0])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return collections
|
return collections
|
||||||
@ -243,7 +258,7 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression()
|
|||||||
getCollection: func(t *testing.T) []*exchange.Collection {
|
getCollection: func(t *testing.T) []*exchange.Collection {
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
sel.Include(sel.EventCalendars([]string{suite.user}, []string{"Birthdays"}))
|
sel.Include(sel.EventCalendars([]string{suite.user}, []string{"Birthdays"}))
|
||||||
collections, err := connector.createCollections(context.Background(), sel.Scopes()[0])
|
collections, err := connector.createCollections(ctx, sel.Scopes()[0])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
return collections
|
return collections
|
||||||
@ -283,7 +298,9 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression()
|
|||||||
// The final test insures that more than a 75% of the user collections are
|
// The final test insures that more than a 75% of the user collections are
|
||||||
// returned. If an error was experienced, the test will fail overall
|
// returned. If an error was experienced, the test will fail overall
|
||||||
func (suite *GraphConnectorIntegrationSuite) TestAccessOfInboxAllUsers() {
|
func (suite *GraphConnectorIntegrationSuite) TestAccessOfInboxAllUsers() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
connector := loadConnector(ctx, t)
|
connector := loadConnector(ctx, t)
|
||||||
sel := selectors.NewExchangeBackup()
|
sel := selectors.NewExchangeBackup()
|
||||||
@ -293,7 +310,7 @@ func (suite *GraphConnectorIntegrationSuite) TestAccessOfInboxAllUsers() {
|
|||||||
for _, scope := range scopes {
|
for _, scope := range scopes {
|
||||||
users := scope.Get(selectors.ExchangeUser)
|
users := scope.Get(selectors.ExchangeUser)
|
||||||
standard := (len(users) / 4) * 3
|
standard := (len(users) / 4) * 3
|
||||||
collections, err := connector.createCollections(context.Background(), scope)
|
collections, err := connector.createCollections(ctx, scope)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
suite.Greater(len(collections), standard)
|
suite.Greater(len(collections), standard)
|
||||||
}
|
}
|
||||||
@ -342,7 +359,8 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
deets, err := suite.connector.RestoreDataCollections(ctx, test.sel, dest, test.col)
|
deets, err := suite.connector.RestoreDataCollections(ctx, test.sel, dest, test.col)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -645,7 +663,9 @@ func (suite *GraphConnectorIntegrationSuite) TestRestoreAndBackup() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
// Get a dest per test so they're independent.
|
// Get a dest per test so they're independent.
|
||||||
dest := tester.DefaultTestRestoreDestination()
|
dest := tester.DefaultTestRestoreDestination()
|
||||||
|
|
||||||
@ -845,7 +865,9 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
restoreSel := getSelectorWith(test.service)
|
restoreSel := getSelectorWith(test.service)
|
||||||
dests := make([]control.RestoreDestination, 0, len(test.collections))
|
dests := make([]control.RestoreDestination, 0, len(test.collections))
|
||||||
allItems := 0
|
allItems := 0
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package onedrive
|
package onedrive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
|
||||||
@ -9,6 +8,8 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"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/tester"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string {
|
func expectedPathAsSlice(t *testing.T, tenant, user string, rest ...string) []string {
|
||||||
@ -126,8 +127,11 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.T().Run(tt.testCase, func(t *testing.T) {
|
suite.T().Run(tt.testCase, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
c := NewCollections(tenant, user, &MockGraphService{}, nil)
|
c := NewCollections(tenant, user, &MockGraphService{}, nil)
|
||||||
err := c.updateCollections(context.Background(), "driveID", tt.items)
|
err := c.updateCollections(ctx, "driveID", tt.items)
|
||||||
tt.expect(t, err)
|
tt.expect(t, err)
|
||||||
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.collectionMap))
|
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.collectionMap))
|
||||||
assert.Equal(t, tt.expectedItemCount, c.numItems)
|
assert.Equal(t, tt.expectedItemCount, c.numItems)
|
||||||
|
|||||||
@ -48,6 +48,9 @@ func TestItemIntegrationSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ItemIntegrationSuite) SetupSuite() {
|
func (suite *ItemIntegrationSuite) SetupSuite() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
@ -63,7 +66,7 @@ func (suite *ItemIntegrationSuite) SetupSuite() {
|
|||||||
|
|
||||||
suite.user = tester.M365UserID(suite.T())
|
suite.user = tester.M365UserID(suite.T())
|
||||||
|
|
||||||
drives, err := drives(context.TODO(), suite, suite.user)
|
drives, err := drives(ctx, suite, suite.user)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
// Test Requirement 1: Need a drive
|
// Test Requirement 1: Need a drive
|
||||||
require.Greaterf(suite.T(), len(drives), 0, "user %s does not have a drive", suite.user)
|
require.Greaterf(suite.T(), len(drives), 0, "user %s does not have a drive", suite.user)
|
||||||
@ -78,7 +81,8 @@ func (suite *ItemIntegrationSuite) SetupSuite() {
|
|||||||
// 2) It assumes the drive has a file it can use to test `driveItemReader`
|
// 2) It assumes the drive has a file it can use to test `driveItemReader`
|
||||||
// The test checks these in below
|
// The test checks these in below
|
||||||
func (suite *ItemIntegrationSuite) TestItemReader() {
|
func (suite *ItemIntegrationSuite) TestItemReader() {
|
||||||
ctx := context.TODO()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var driveItemID string
|
var driveItemID string
|
||||||
// This item collector tries to find "a" drive item that is a file to test the reader function
|
// This item collector tries to find "a" drive item that is a file to test the reader function
|
||||||
@ -122,7 +126,8 @@ func (suite *ItemIntegrationSuite) TestItemReader() {
|
|||||||
// It creates a new `testfolder_<timestamp` folder with a new
|
// It creates a new `testfolder_<timestamp` folder with a new
|
||||||
// testitem_<timestamp> item and writes data to it
|
// testitem_<timestamp> item and writes data to it
|
||||||
func (suite *ItemIntegrationSuite) TestItemWriter() {
|
func (suite *ItemIntegrationSuite) TestItemWriter() {
|
||||||
ctx := context.TODO()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
root, err := suite.Client().DrivesById(suite.driveID).Root().Get(ctx, nil)
|
root, err := suite.Client().DrivesById(suite.driveID).Root().Get(ctx, nil)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
@ -175,7 +180,8 @@ func mockDataReader(size int64) (io.Reader, int64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ItemIntegrationSuite) TestDriveGetFolder() {
|
func (suite *ItemIntegrationSuite) TestDriveGetFolder() {
|
||||||
ctx := context.TODO()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
root, err := suite.Client().DrivesById(suite.driveID).Root().Get(ctx, nil)
|
root, err := suite.Client().DrivesById(suite.driveID).Root().Get(ctx, nil)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
package support
|
package support
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"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/tester"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GCStatusTestSuite struct {
|
type GCStatusTestSuite struct {
|
||||||
@ -51,8 +52,11 @@ func (suite *GCStatusTestSuite) TestCreateStatus() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
result := CreateStatus(
|
result := CreateStatus(
|
||||||
context.Background(),
|
ctx,
|
||||||
test.params.operationType,
|
test.params.operationType,
|
||||||
test.params.folders,
|
test.params.folders,
|
||||||
CollectionMetrics{test.params.objects, test.params.success, 0},
|
CollectionMetrics{test.params.objects, test.params.success, 0},
|
||||||
@ -69,8 +73,11 @@ func (suite *GCStatusTestSuite) TestCreateStatus_InvalidStatus() {
|
|||||||
params := statusParams{Backup, 9, 3, 13, errors.New("invalidcl")}
|
params := statusParams{Backup, 9, 3, 13, errors.New("invalidcl")}
|
||||||
|
|
||||||
require.Panics(t, func() {
|
require.Panics(t, func() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
CreateStatus(
|
CreateStatus(
|
||||||
context.Background(),
|
ctx,
|
||||||
params.operationType,
|
params.operationType,
|
||||||
params.folders,
|
params.folders,
|
||||||
CollectionMetrics{
|
CollectionMetrics{
|
||||||
@ -85,7 +92,9 @@ func (suite *GCStatusTestSuite) TestCreateStatus_InvalidStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *GCStatusTestSuite) TestMergeStatus() {
|
func (suite *GCStatusTestSuite) TestMergeStatus() {
|
||||||
simpleContext := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
one ConnectorOperationStatus
|
one ConnectorOperationStatus
|
||||||
@ -95,7 +104,7 @@ func (suite *GCStatusTestSuite) TestMergeStatus() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Test: Status + unknown",
|
name: "Test: Status + unknown",
|
||||||
one: *CreateStatus(simpleContext, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
one: *CreateStatus(ctx, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
||||||
two: ConnectorOperationStatus{},
|
two: ConnectorOperationStatus{},
|
||||||
expected: statusParams{Backup, 1, 1, 1, nil},
|
expected: statusParams{Backup, 1, 1, 1, nil},
|
||||||
isIncomplete: assert.False,
|
isIncomplete: assert.False,
|
||||||
@ -103,22 +112,22 @@ func (suite *GCStatusTestSuite) TestMergeStatus() {
|
|||||||
{
|
{
|
||||||
name: "Test: unknown + Status",
|
name: "Test: unknown + Status",
|
||||||
one: ConnectorOperationStatus{},
|
one: ConnectorOperationStatus{},
|
||||||
two: *CreateStatus(simpleContext, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
two: *CreateStatus(ctx, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
||||||
expected: statusParams{Backup, 1, 1, 1, nil},
|
expected: statusParams{Backup, 1, 1, 1, nil},
|
||||||
isIncomplete: assert.False,
|
isIncomplete: assert.False,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test: Successful + Successful",
|
name: "Test: Successful + Successful",
|
||||||
one: *CreateStatus(simpleContext, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
one: *CreateStatus(ctx, Backup, 1, CollectionMetrics{1, 1, 0}, nil, ""),
|
||||||
two: *CreateStatus(simpleContext, Backup, 3, CollectionMetrics{3, 3, 0}, nil, ""),
|
two: *CreateStatus(ctx, Backup, 3, CollectionMetrics{3, 3, 0}, nil, ""),
|
||||||
expected: statusParams{Backup, 4, 4, 4, nil},
|
expected: statusParams{Backup, 4, 4, 4, nil},
|
||||||
isIncomplete: assert.False,
|
isIncomplete: assert.False,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Test: Successful + Unsuccessful",
|
name: "Test: Successful + Unsuccessful",
|
||||||
one: *CreateStatus(simpleContext, Backup, 13, CollectionMetrics{17, 17, 0}, nil, ""),
|
one: *CreateStatus(ctx, Backup, 13, CollectionMetrics{17, 17, 0}, nil, ""),
|
||||||
two: *CreateStatus(
|
two: *CreateStatus(
|
||||||
simpleContext,
|
ctx,
|
||||||
Backup,
|
Backup,
|
||||||
8,
|
8,
|
||||||
CollectionMetrics{
|
CollectionMetrics{
|
||||||
|
|||||||
@ -41,7 +41,9 @@ func TestWrapperUnitSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperUnitSuite) TestCloseWithoutOpenDoesNotCrash() {
|
func (suite *WrapperUnitSuite) TestCloseWithoutOpenDoesNotCrash() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
k := conn{}
|
k := conn{}
|
||||||
|
|
||||||
assert.NotPanics(suite.T(), func() {
|
assert.NotPanics(suite.T(), func() {
|
||||||
@ -73,8 +75,10 @@ func (suite *WrapperIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestRepoExistsError() {
|
func (suite *WrapperIntegrationSuite) TestRepoExistsError() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
k := NewConn(st)
|
k := NewConn(st)
|
||||||
@ -88,8 +92,10 @@ func (suite *WrapperIntegrationSuite) TestRepoExistsError() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestBadProviderErrors() {
|
func (suite *WrapperIntegrationSuite) TestBadProviderErrors() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
st.Provider = storage.ProviderUnknown
|
st.Provider = storage.ProviderUnknown
|
||||||
@ -99,8 +105,10 @@ func (suite *WrapperIntegrationSuite) TestBadProviderErrors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestConnectWithoutInitErrors() {
|
func (suite *WrapperIntegrationSuite) TestConnectWithoutInitErrors() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
k := NewConn(st)
|
k := NewConn(st)
|
||||||
@ -108,7 +116,9 @@ func (suite *WrapperIntegrationSuite) TestConnectWithoutInitErrors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestCloseTwiceDoesNotCrash() {
|
func (suite *WrapperIntegrationSuite) TestCloseTwiceDoesNotCrash() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
@ -119,7 +129,9 @@ func (suite *WrapperIntegrationSuite) TestCloseTwiceDoesNotCrash() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestCloseAfterWrap() {
|
func (suite *WrapperIntegrationSuite) TestCloseAfterWrap() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
@ -150,7 +162,9 @@ func (suite *WrapperIntegrationSuite) TestOpenAfterClose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestBadCompressorType() {
|
func (suite *WrapperIntegrationSuite) TestBadCompressorType() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
@ -164,7 +178,9 @@ func (suite *WrapperIntegrationSuite) TestBadCompressorType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestGetPolicyOrDefault_GetsDefault() {
|
func (suite *WrapperIntegrationSuite) TestGetPolicyOrDefault_GetsDefault() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
@ -187,7 +203,9 @@ func (suite *WrapperIntegrationSuite) TestGetPolicyOrDefault_GetsDefault() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestSetCompressor() {
|
func (suite *WrapperIntegrationSuite) TestSetCompressor() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
compressor := "pgzip"
|
compressor := "pgzip"
|
||||||
|
|
||||||
@ -280,7 +298,8 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -309,7 +328,9 @@ func (suite *WrapperIntegrationSuite) TestConfigDefaultsSetOnInitAndConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *WrapperIntegrationSuite) TestInitAndConnWithTempDirectory() {
|
func (suite *WrapperIntegrationSuite) TestInitAndConnWithTempDirectory() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
|
|||||||
@ -45,8 +45,11 @@ func TestModelStoreUnitSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *ModelStoreUnitSuite) TestCloseWithoutInitDoesNotPanic() {
|
func (suite *ModelStoreUnitSuite) TestCloseWithoutInitDoesNotPanic() {
|
||||||
assert.NotPanics(suite.T(), func() {
|
assert.NotPanics(suite.T(), func() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
m := &ModelStore{}
|
m := &ModelStore{}
|
||||||
m.Close(context.Background())
|
m.Close(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +58,9 @@ func (suite *ModelStoreUnitSuite) TestCloseWithoutInitDoesNotPanic() {
|
|||||||
// ---------------
|
// ---------------
|
||||||
type ModelStoreIntegrationSuite struct {
|
type ModelStoreIntegrationSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
m *ModelStore
|
m *ModelStore
|
||||||
|
flush func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestModelStoreIntegrationSuite(t *testing.T) {
|
func TestModelStoreIntegrationSuite(t *testing.T) {
|
||||||
@ -76,11 +80,12 @@ func (suite *ModelStoreIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ModelStoreIntegrationSuite) SetupTest() {
|
func (suite *ModelStoreIntegrationSuite) SetupTest() {
|
||||||
suite.ctx = context.Background()
|
suite.ctx, suite.flush = tester.NewContext()
|
||||||
suite.m = getModelStore(suite.T(), suite.ctx)
|
suite.m = getModelStore(suite.T(), suite.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ModelStoreIntegrationSuite) TearDownTest() {
|
func (suite *ModelStoreIntegrationSuite) TearDownTest() {
|
||||||
|
defer suite.flush()
|
||||||
assert.NoError(suite.T(), suite.m.Close(suite.ctx))
|
assert.NoError(suite.T(), suite.m.Close(suite.ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -584,7 +589,9 @@ func (suite *ModelStoreIntegrationSuite) TestPutUpdate() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
theModelType := model.BackupOpSchema
|
theModelType := model.BackupOpSchema
|
||||||
|
|
||||||
m := getModelStore(t, ctx)
|
m := getModelStore(t, ctx)
|
||||||
@ -657,7 +664,8 @@ func (suite *ModelStoreIntegrationSuite) TestPutUpdate_FailsNotMatchingPrev() {
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
m := getModelStore(t, ctx)
|
m := getModelStore(t, ctx)
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -726,7 +734,9 @@ func (suite *ModelStoreRegressionSuite) SetupSuite() {
|
|||||||
// Tests that if we get an error or crash while in the middle of an Update no
|
// Tests that if we get an error or crash while in the middle of an Update no
|
||||||
// results will be visible to higher layers.
|
// results will be visible to higher layers.
|
||||||
func (suite *ModelStoreRegressionSuite) TestFailDuringWriteSessionHasNoVisibleEffect() {
|
func (suite *ModelStoreRegressionSuite) TestFailDuringWriteSessionHasNoVisibleEffect() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
m := getModelStore(t, ctx)
|
m := getModelStore(t, ctx)
|
||||||
@ -823,7 +833,9 @@ func reconnectToModelStore(
|
|||||||
// Ensures there's no shared configuration state between different instances of
|
// Ensures there's no shared configuration state between different instances of
|
||||||
// the ModelStore (and consequently the underlying kopia instances).
|
// the ModelStore (and consequently the underlying kopia instances).
|
||||||
func (suite *ModelStoreRegressionSuite) TestMultipleConfigs() {
|
func (suite *ModelStoreRegressionSuite) TestMultipleConfigs() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
numEntries := 10
|
numEntries := 10
|
||||||
deets := details.DetailsModel{
|
deets := details.DetailsModel{
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -477,16 +478,21 @@ func TestKopiaUnitSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *KopiaUnitSuite) TestCloseWithoutInitDoesNotPanic() {
|
func (suite *KopiaUnitSuite) TestCloseWithoutInitDoesNotPanic() {
|
||||||
assert.NotPanics(suite.T(), func() {
|
assert.NotPanics(suite.T(), func() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
w := &Wrapper{}
|
w := &Wrapper{}
|
||||||
w.Close(context.Background())
|
w.Close(ctx)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KopiaUnitSuite) TestBuildDirectoryTree() {
|
func (suite *KopiaUnitSuite) TestBuildDirectoryTree() {
|
||||||
tester.LogTimeOfTest(suite.T())
|
tester.LogTimeOfTest(suite.T())
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
tenant := "a-tenant"
|
tenant := "a-tenant"
|
||||||
user1 := testUser
|
user1 := testUser
|
||||||
user1Encoded := encodeAsPath(user1)
|
user1Encoded := encodeAsPath(user1)
|
||||||
@ -569,7 +575,9 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KopiaUnitSuite) TestBuildDirectoryTree_MixedDirectory() {
|
func (suite *KopiaUnitSuite) TestBuildDirectoryTree_MixedDirectory() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
subdir := "subfolder"
|
subdir := "subfolder"
|
||||||
|
|
||||||
p2, err := suite.testPath.Append(subdir, false)
|
p2, err := suite.testPath.Append(subdir, false)
|
||||||
@ -714,7 +722,8 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree_Fails() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
_, err := inflateDirTree(ctx, test.layout, nil)
|
_, err := inflateDirTree(ctx, test.layout, nil)
|
||||||
@ -728,8 +737,9 @@ func (suite *KopiaUnitSuite) TestBuildDirectoryTree_Fails() {
|
|||||||
// ---------------
|
// ---------------
|
||||||
type KopiaIntegrationSuite struct {
|
type KopiaIntegrationSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
w *Wrapper
|
w *Wrapper
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
flush func()
|
||||||
|
|
||||||
testPath1 path.Path
|
testPath1 path.Path
|
||||||
testPath2 path.Path
|
testPath2 path.Path
|
||||||
@ -773,7 +783,7 @@ func (suite *KopiaIntegrationSuite) SetupSuite() {
|
|||||||
|
|
||||||
func (suite *KopiaIntegrationSuite) SetupTest() {
|
func (suite *KopiaIntegrationSuite) SetupTest() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
suite.ctx = context.Background()
|
suite.ctx, suite.flush = tester.NewContext()
|
||||||
|
|
||||||
c, err := openKopiaRepo(t, suite.ctx)
|
c, err := openKopiaRepo(t, suite.ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -782,6 +792,7 @@ func (suite *KopiaIntegrationSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *KopiaIntegrationSuite) TearDownTest() {
|
func (suite *KopiaIntegrationSuite) TearDownTest() {
|
||||||
|
defer suite.flush()
|
||||||
assert.NoError(suite.T(), suite.w.Close(suite.ctx))
|
assert.NoError(suite.T(), suite.w.Close(suite.ctx))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +823,9 @@ func (suite *KopiaIntegrationSuite) TestBackupCollections() {
|
|||||||
|
|
||||||
func (suite *KopiaIntegrationSuite) TestRestoreAfterCompressionChange() {
|
func (suite *KopiaIntegrationSuite) TestRestoreAfterCompressionChange() {
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
|
||||||
|
defer flush()
|
||||||
|
|
||||||
k, err := openKopiaRepo(t, ctx)
|
k, err := openKopiaRepo(t, ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -930,7 +943,8 @@ func (suite *KopiaIntegrationSuite) TestBackupCollectionsHandlesNoCollections()
|
|||||||
|
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
s, d, err := suite.w.BackupCollections(ctx, test.collections)
|
s, d, err := suite.w.BackupCollections(ctx, test.collections)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -1051,7 +1065,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) SetupTest() {
|
|||||||
t := suite.T()
|
t := suite.T()
|
||||||
expectedDirs := 6
|
expectedDirs := 6
|
||||||
expectedFiles := len(suite.filesByPath)
|
expectedFiles := len(suite.filesByPath)
|
||||||
suite.ctx = context.Background()
|
suite.ctx, _ = logger.SeedLevel(context.Background(), logger.Development)
|
||||||
c, err := openKopiaRepo(t, suite.ctx)
|
c, err := openKopiaRepo(t, suite.ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -1090,6 +1104,7 @@ func (suite *KopiaSimpleRepoIntegrationSuite) SetupTest() {
|
|||||||
|
|
||||||
func (suite *KopiaSimpleRepoIntegrationSuite) TearDownTest() {
|
func (suite *KopiaSimpleRepoIntegrationSuite) TearDownTest() {
|
||||||
assert.NoError(suite.T(), suite.w.Close(suite.ctx))
|
assert.NoError(suite.T(), suite.w.Close(suite.ctx))
|
||||||
|
logger.Flush(suite.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
type i64counter struct {
|
type i64counter struct {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package operations
|
package operations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -34,8 +33,10 @@ func TestBackupOpSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
|
func (suite *BackupOpSuite) TestBackupOperation_PersistResults() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
|
||||||
kw = &kopia.Wrapper{}
|
kw = &kopia.Wrapper{}
|
||||||
sw = &store.Wrapper{}
|
sw = &store.Wrapper{}
|
||||||
acct = account.Account{}
|
acct = account.Account{}
|
||||||
@ -155,8 +156,11 @@ func (suite *BackupOpIntegrationSuite) TestNewBackupOperation() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := NewBackupOperation(
|
_, err := NewBackupOperation(
|
||||||
context.Background(),
|
ctx,
|
||||||
test.opts,
|
test.opts,
|
||||||
test.kw,
|
test.kw,
|
||||||
test.sw,
|
test.sw,
|
||||||
@ -171,8 +175,10 @@ func (suite *BackupOpIntegrationSuite) TestNewBackupOperation() {
|
|||||||
// TestBackup_Run ensures that Integration Testing works
|
// TestBackup_Run ensures that Integration Testing works
|
||||||
// for the following scopes: Contacts, Events, and Mail
|
// for the following scopes: Contacts, Events, and Mail
|
||||||
func (suite *BackupOpIntegrationSuite) TestBackup_Run() {
|
func (suite *BackupOpIntegrationSuite) TestBackup_Run() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
m365UserID := tester.M365UserID(t)
|
m365UserID := tester.M365UserID(t)
|
||||||
acct := tester.NewM365Account(t)
|
acct := tester.NewM365Account(t)
|
||||||
@ -262,8 +268,10 @@ func (suite *BackupOpIntegrationSuite) TestBackup_Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *BackupOpIntegrationSuite) TestBackupOneDrive_Run() {
|
func (suite *BackupOpIntegrationSuite) TestBackupOneDrive_Run() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
m365UserID := tester.M365UserID(t)
|
m365UserID := tester.M365UserID(t)
|
||||||
acct := tester.NewM365Account(t)
|
acct := tester.NewM365Account(t)
|
||||||
|
|||||||
@ -37,8 +37,10 @@ func TestRestoreOpSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
|
func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
|
||||||
kw = &kopia.Wrapper{}
|
kw = &kopia.Wrapper{}
|
||||||
sw = &store.Wrapper{}
|
sw = &store.Wrapper{}
|
||||||
acct = account.Account{}
|
acct = account.Account{}
|
||||||
@ -142,11 +144,13 @@ func TestRestoreOpIntegrationSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpIntegrationSuite) SetupSuite() {
|
func (suite *RestoreOpIntegrationSuite) SetupSuite() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
_, err := tester.GetRequiredEnvVars(tester.M365AcctCredEnvs...)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
m365UserID := tester.M365UserID(t)
|
m365UserID := tester.M365UserID(t)
|
||||||
acct := tester.NewM365Account(t)
|
acct := tester.NewM365Account(t)
|
||||||
@ -194,7 +198,9 @@ func (suite *RestoreOpIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpIntegrationSuite) TearDownSuite() {
|
func (suite *RestoreOpIntegrationSuite) TearDownSuite() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
if suite.ms != nil {
|
if suite.ms != nil {
|
||||||
suite.ms.Close(ctx)
|
suite.ms.Close(ctx)
|
||||||
}
|
}
|
||||||
@ -229,8 +235,11 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
_, err := NewRestoreOperation(
|
_, err := NewRestoreOperation(
|
||||||
context.Background(),
|
ctx,
|
||||||
test.opts,
|
test.opts,
|
||||||
test.kw,
|
test.kw,
|
||||||
test.sw,
|
test.sw,
|
||||||
@ -245,8 +254,10 @@ func (suite *RestoreOpIntegrationSuite) TestNewRestoreOperation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
|
func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
rsel := selectors.NewExchangeRestore()
|
rsel := selectors.NewExchangeRestore()
|
||||||
rsel.Include(rsel.Users([]string{tester.M365UserID(t)}))
|
rsel.Include(rsel.Users([]string{tester.M365UserID(t)}))
|
||||||
@ -285,8 +296,10 @@ func (suite *RestoreOpIntegrationSuite) TestRestore_Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RestoreOpIntegrationSuite) TestRestore_Run_ErrorNoResults() {
|
func (suite *RestoreOpIntegrationSuite) TestRestore_Run_ErrorNoResults() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
rsel := selectors.NewExchangeRestore()
|
rsel := selectors.NewExchangeRestore()
|
||||||
rsel.Include(rsel.Users(selectors.None()))
|
rsel.Include(rsel.Users(selectors.None()))
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StubRootCmd builds a stub cobra command to be used as
|
// StubRootCmd builds a stub cobra command to be used as
|
||||||
@ -31,7 +32,12 @@ func StubRootCmd(args ...string) *cobra.Command {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContext() context.Context {
|
func NewContext() (context.Context, func()) {
|
||||||
type stub struct{}
|
ctx, _ := logger.SeedLevel(context.Background(), logger.Development)
|
||||||
return context.WithValue(context.Background(), stub{}, stub{})
|
return ctx, func() { logger.Flush(ctx) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithContext(ctx context.Context) (context.Context, func()) {
|
||||||
|
ctx, _ = logger.SeedLevel(ctx, logger.Development)
|
||||||
|
return ctx, func() { logger.Flush(ctx) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -153,10 +153,15 @@ func Seed(ctx context.Context) (ctxOut context.Context, zsl *zap.SugaredLogger)
|
|||||||
|
|
||||||
// SeedLevel embeds a logger into the context with the given log-level.
|
// SeedLevel embeds a logger into the context with the given log-level.
|
||||||
func SeedLevel(ctx context.Context, level logLevel) (context.Context, *zap.SugaredLogger) {
|
func SeedLevel(ctx context.Context, level logLevel) (context.Context, *zap.SugaredLogger) {
|
||||||
_, zsl := genLogger(level)
|
l := ctx.Value(ctxKey)
|
||||||
ctxWV := context.WithValue(ctx, ctxKey, zsl)
|
if l == nil {
|
||||||
|
zsl := singleton(level)
|
||||||
|
ctxWV := context.WithValue(ctx, ctxKey, zsl)
|
||||||
|
|
||||||
return ctxWV, zsl
|
return ctxWV, zsl
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx, l.(*zap.SugaredLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ctx retrieves the logger embedded in the context.
|
// Ctx retrieves the logger embedded in the context.
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/backup"
|
"github.com/alcionai/corso/src/pkg/backup"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/control"
|
"github.com/alcionai/corso/src/pkg/control"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
|
||||||
"github.com/alcionai/corso/src/pkg/repository"
|
"github.com/alcionai/corso/src/pkg/repository"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
"github.com/alcionai/corso/src/pkg/storage"
|
"github.com/alcionai/corso/src/pkg/storage"
|
||||||
@ -31,7 +30,9 @@ func initM365Repo(t *testing.T) (
|
|||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx := tester.NewContext()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
ac := tester.NewM365Account(t)
|
ac := tester.NewM365Account(t)
|
||||||
opts := control.Options{
|
opts := control.Options{
|
||||||
@ -217,18 +218,12 @@ func (suite *RepositoryLoadTestExchangeSuite) TeardownSuite() {
|
|||||||
suite.repo.Close(suite.ctx)
|
suite.repo.Close(suite.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestExchangeSuite) SetupTest() {
|
|
||||||
suite.ctx, _ = logger.SeedLevel(context.Background(), logger.Development)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestExchangeSuite) TeardownTest() {
|
|
||||||
logger.Flush(suite.ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestExchangeSuite) TestExchange() {
|
func (suite *RepositoryLoadTestExchangeSuite) TestExchange() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t = suite.T()
|
t = suite.T()
|
||||||
ctx = context.Background()
|
|
||||||
r = suite.repo
|
r = suite.repo
|
||||||
service = "exchange"
|
service = "exchange"
|
||||||
)
|
)
|
||||||
@ -291,18 +286,12 @@ func (suite *RepositoryLoadTestOneDriveSuite) TeardownSuite() {
|
|||||||
suite.repo.Close(suite.ctx)
|
suite.repo.Close(suite.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestOneDriveSuite) SetupTest() {
|
|
||||||
suite.ctx, _ = logger.SeedLevel(context.Background(), logger.Development)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestOneDriveSuite) TeardownTest() {
|
|
||||||
logger.Flush(suite.ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (suite *RepositoryLoadTestOneDriveSuite) TestOneDrive() {
|
func (suite *RepositoryLoadTestOneDriveSuite) TestOneDrive() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
t = suite.T()
|
t = suite.T()
|
||||||
ctx = context.Background()
|
|
||||||
r = suite.repo
|
r = suite.repo
|
||||||
service = "one_drive"
|
service = "one_drive"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package repository_test
|
package repository_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -46,9 +45,12 @@ func (suite *RepositorySuite) TestInitialize() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st, err := test.storage()
|
st, err := test.storage()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = repository.Initialize(context.Background(), test.account, st, control.Options{})
|
_, err = repository.Initialize(ctx, test.account, st, control.Options{})
|
||||||
test.errCheck(t, err, "")
|
test.errCheck(t, err, "")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -74,9 +76,12 @@ func (suite *RepositorySuite) TestConnect() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
st, err := test.storage()
|
st, err := test.storage()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = repository.Connect(context.Background(), test.account, st, control.Options{})
|
_, err = repository.Connect(ctx, test.account, st, control.Options{})
|
||||||
test.errCheck(t, err)
|
test.errCheck(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -110,7 +115,8 @@ func (suite *RepositoryIntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -140,8 +146,10 @@ func (suite *RepositoryIntegrationSuite) TestInitialize() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryIntegrationSuite) TestConnect() {
|
func (suite *RepositoryIntegrationSuite) TestConnect() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
// need to initialize the repository before we can test connecting to it.
|
// need to initialize the repository before we can test connecting to it.
|
||||||
st := tester.NewPrefixedS3Storage(t)
|
st := tester.NewPrefixedS3Storage(t)
|
||||||
@ -155,8 +163,10 @@ func (suite *RepositoryIntegrationSuite) TestConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryIntegrationSuite) TestNewBackup() {
|
func (suite *RepositoryIntegrationSuite) TestNewBackup() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
acct := tester.NewM365Account(t)
|
acct := tester.NewM365Account(t)
|
||||||
|
|
||||||
@ -172,8 +182,10 @@ func (suite *RepositoryIntegrationSuite) TestNewBackup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *RepositoryIntegrationSuite) TestNewRestore() {
|
func (suite *RepositoryIntegrationSuite) TestNewRestore() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
t := suite.T()
|
t := suite.T()
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
acct := tester.NewM365Account(t)
|
acct := tester.NewM365Account(t)
|
||||||
dest := tester.DefaultTestRestoreDestination()
|
dest := tester.DefaultTestRestoreDestination()
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package selectors
|
package selectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/filters"
|
"github.com/alcionai/corso/src/pkg/filters"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
@ -1129,8 +1129,11 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
sel := test.makeSelector()
|
sel := test.makeSelector()
|
||||||
results := sel.Reduce(context.Background(), test.deets)
|
results := sel.Reduce(ctx, test.deets)
|
||||||
paths := results.Paths()
|
paths := results.Paths()
|
||||||
assert.Equal(t, test.expect, paths)
|
assert.Equal(t, test.expect, paths)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package selectors
|
package selectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
@ -262,8 +262,11 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
|
|||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
sel := test.makeSelector()
|
sel := test.makeSelector()
|
||||||
results := sel.Reduce(context.Background(), test.deets)
|
results := sel.Reduce(ctx, test.deets)
|
||||||
paths := results.Paths()
|
paths := results.Paths()
|
||||||
assert.Equal(t, test.expect, paths)
|
assert.Equal(t, test.expect, paths)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
package selectors
|
package selectors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"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/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/filters"
|
"github.com/alcionai/corso/src/pkg/filters"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
@ -246,9 +246,12 @@ func (suite *SelectorScopesSuite) TestReduce() {
|
|||||||
|
|
||||||
for _, test := range reduceTestTable {
|
for _, test := range reduceTestTable {
|
||||||
suite.T().Run(test.name, func(t *testing.T) {
|
suite.T().Run(test.name, func(t *testing.T) {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
ds := deets()
|
ds := deets()
|
||||||
result := reduce[mockScope](
|
result := reduce[mockScope](
|
||||||
context.Background(),
|
ctx,
|
||||||
&ds,
|
&ds,
|
||||||
test.sel().Selector,
|
test.sel().Selector,
|
||||||
dataCats)
|
dataCats)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package selectors_test
|
package selectors_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -9,6 +8,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors/testdata"
|
"github.com/alcionai/corso/src/pkg/selectors/testdata"
|
||||||
@ -23,7 +23,9 @@ func TestSelectorReduceSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SelectorReduceSuite) TestReduce() {
|
func (suite *SelectorReduceSuite) TestReduce() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
allDetails := testdata.GetDetailsSet()
|
allDetails := testdata.GetDetailsSet()
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package m365
|
package m365
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -31,9 +30,12 @@ func (suite *M365IntegrationSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *M365IntegrationSuite) TestUsers() {
|
func (suite *M365IntegrationSuite) TestUsers() {
|
||||||
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
acct := tester.NewM365Account(suite.T())
|
acct := tester.NewM365Account(suite.T())
|
||||||
|
|
||||||
users, err := Users(context.Background(), acct)
|
users, err := Users(ctx, acct)
|
||||||
require.NoError(suite.T(), err)
|
require.NoError(suite.T(), err)
|
||||||
|
|
||||||
require.NotNil(suite.T(), users)
|
require.NotNil(suite.T(), users)
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package store_test
|
package store_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -11,6 +10,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/model"
|
"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/backup"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/store"
|
"github.com/alcionai/corso/src/pkg/store"
|
||||||
@ -51,7 +51,8 @@ func TestStoreBackupUnitSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreBackupUnitSuite) TestGetBackup() {
|
func (suite *StoreBackupUnitSuite) TestGetBackup() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -83,7 +84,8 @@ func (suite *StoreBackupUnitSuite) TestGetBackup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreBackupUnitSuite) TestGetBackups() {
|
func (suite *StoreBackupUnitSuite) TestGetBackups() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -116,7 +118,8 @@ func (suite *StoreBackupUnitSuite) TestGetBackups() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreBackupUnitSuite) TestDeleteBackup() {
|
func (suite *StoreBackupUnitSuite) TestDeleteBackup() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -144,7 +147,8 @@ func (suite *StoreBackupUnitSuite) TestDeleteBackup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreBackupUnitSuite) TestGetDetails() {
|
func (suite *StoreBackupUnitSuite) TestGetDetails() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
@ -176,7 +180,8 @@ func (suite *StoreBackupUnitSuite) TestGetDetails() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *StoreBackupUnitSuite) TestGetDetailsFromBackupID() {
|
func (suite *StoreBackupUnitSuite) TestGetDetailsFromBackupID() {
|
||||||
ctx := context.Background()
|
ctx, flush := tester.NewContext()
|
||||||
|
defer flush()
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user