fix tests, missing producer

This commit is contained in:
ryanfkeepers 2023-03-29 15:34:52 -06:00
parent 3da8bf86a4
commit 945e4ecbd0
6 changed files with 19 additions and 18 deletions

View File

@ -224,7 +224,7 @@ func (gc *GraphConnector) UnionSiteIDsAndWebURLs(
} }
// AwaitStatus waits for all gc tasks to complete and then returns status // AwaitStatus waits for all gc tasks to complete and then returns status
func (gc *GraphConnector) Wait() data.CollectionStats { func (gc *GraphConnector) Wait() *data.CollectionStats {
defer func() { defer func() {
if gc.region != nil { if gc.region != nil {
gc.region.End() gc.region.End()
@ -245,7 +245,7 @@ func (gc *GraphConnector) Wait() data.CollectionStats {
gc.wg = &sync.WaitGroup{} gc.wg = &sync.WaitGroup{}
gc.status = support.ConnectorOperationStatus{} gc.status = support.ConnectorOperationStatus{}
return dcs return &dcs
} }
// UpdateStatus is used by gc initiated tasks to indicate completion // UpdateStatus is used by gc initiated tasks to indicate completion

View File

@ -37,8 +37,8 @@ func (gc GraphConnector) ProduceBackupCollections(
return gc.Collections, gc.Exclude, gc.Err return gc.Collections, gc.Exclude, gc.Err
} }
func (gc GraphConnector) Wait() data.CollectionStats { func (gc GraphConnector) Wait() *data.CollectionStats {
return gc.Stats return &gc.Stats
} }
func (gc GraphConnector) ConsumeRestoreCollections( func (gc GraphConnector) ConsumeRestoreCollections(

View File

@ -73,6 +73,7 @@ func NewBackupOperation(
Version: "v0", Version: "v0",
account: acct, account: acct,
incremental: useIncrementalBackup(selector, opts), incremental: useIncrementalBackup(selector, opts),
bp: bp,
} }
if len(ownerName) == 0 { if len(ownerName) == 0 {
@ -104,7 +105,7 @@ func (op BackupOperation) validate() error {
// get populated asynchronously. // get populated asynchronously.
type backupStats struct { type backupStats struct {
k *kopia.BackupStats k *kopia.BackupStats
gc data.CollectionStats gc *data.CollectionStats
resourceCount int resourceCount int
} }
@ -331,7 +332,7 @@ type BackupProducer interface {
) ([]data.BackupCollection, map[string]map[string]struct{}, error) ) ([]data.BackupCollection, map[string]map[string]struct{}, error)
// TODO: ConnectorOperationStatus should be replaced with something // TODO: ConnectorOperationStatus should be replaced with something
// more generic. // more generic.
Wait() data.CollectionStats Wait() *data.CollectionStats
} }
// calls the producer to generate collections of data to backup // calls the producer to generate collections of data to backup
@ -684,12 +685,12 @@ func (op *BackupOperation) persistResults(
op.Results.ItemsWritten = opStats.k.TotalFileCount op.Results.ItemsWritten = opStats.k.TotalFileCount
op.Results.ResourceOwners = opStats.resourceCount op.Results.ResourceOwners = opStats.resourceCount
if opStats.gc.IsZero() { if opStats.gc == nil {
op.Status = Failed op.Status = Failed
return clues.New("backup population never completed") return clues.New("backup population never completed")
} }
if op.Status != Failed && opStats.gc.Successes == 0 { if op.Status != Failed && opStats.gc.IsZero() {
op.Status = NoData op.Status = NoData
} }

View File

@ -380,7 +380,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_PersistResults() {
TotalHashedBytes: 1, TotalHashedBytes: 1,
TotalUploadedBytes: 1, TotalUploadedBytes: 1,
}, },
gc: data.CollectionStats{Successes: 1}, gc: &data.CollectionStats{Successes: 1},
}, },
}, },
{ {
@ -389,7 +389,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_PersistResults() {
fail: assert.AnError, fail: assert.AnError,
stats: backupStats{ stats: backupStats{
k: &kopia.BackupStats{}, k: &kopia.BackupStats{},
gc: data.CollectionStats{}, gc: &data.CollectionStats{},
}, },
}, },
{ {
@ -397,7 +397,7 @@ func (suite *BackupOpUnitSuite) TestBackupOperation_PersistResults() {
expectErr: assert.NoError, expectErr: assert.NoError,
stats: backupStats{ stats: backupStats{
k: &kopia.BackupStats{}, k: &kopia.BackupStats{},
gc: data.CollectionStats{}, gc: &data.CollectionStats{},
}, },
}, },
} }

View File

@ -93,7 +93,7 @@ func (op RestoreOperation) validate() error {
// get populated asynchronously. // get populated asynchronously.
type restoreStats struct { type restoreStats struct {
cs []data.RestoreCollection cs []data.RestoreCollection
gc data.CollectionStats gc *data.CollectionStats
bytesRead *stats.ByteCounter bytesRead *stats.ByteCounter
resourceCount int resourceCount int
@ -280,12 +280,12 @@ func (op *RestoreOperation) persistResults(
op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count op.Results.ItemsRead = len(opStats.cs) // TODO: file count, not collection count
op.Results.ResourceOwners = opStats.resourceCount op.Results.ResourceOwners = opStats.resourceCount
if opStats.gc.IsZero() { if opStats.gc == nil {
op.Status = Failed op.Status = Failed
return clues.New("restoration never completed") return clues.New("restoration never completed")
} }
if op.Status != Failed && opStats.gc.Successes == 0 { if op.Status != Failed && opStats.gc.IsZero() {
op.Status = NoData op.Status = NoData
} }
@ -329,7 +329,7 @@ type RestoreConsumer interface {
) (*details.Details, error) ) (*details.Details, error)
// TODO: ConnectorOperationStatus should be replaced with something // TODO: ConnectorOperationStatus should be replaced with something
// more generic. // more generic.
Wait() data.CollectionStats Wait() *data.CollectionStats
} }
func consumeRestoreCollections( func consumeRestoreCollections(

View File

@ -74,7 +74,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
Collection: &mockconnector.MockExchangeDataCollection{}, Collection: &mockconnector.MockExchangeDataCollection{},
}, },
}, },
gc: data.CollectionStats{ gc: &data.CollectionStats{
Objects: 1, Objects: 1,
Successes: 1, Successes: 1,
}, },
@ -86,7 +86,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
fail: assert.AnError, fail: assert.AnError,
stats: restoreStats{ stats: restoreStats{
bytesRead: &stats.ByteCounter{}, bytesRead: &stats.ByteCounter{},
gc: data.CollectionStats{}, gc: &data.CollectionStats{},
}, },
}, },
{ {
@ -95,7 +95,7 @@ func (suite *RestoreOpSuite) TestRestoreOperation_PersistResults() {
stats: restoreStats{ stats: restoreStats{
bytesRead: &stats.ByteCounter{}, bytesRead: &stats.ByteCounter{},
cs: []data.RestoreCollection{}, cs: []data.RestoreCollection{},
gc: data.CollectionStats{}, gc: &data.CollectionStats{},
}, },
}, },
} }