From 56287c42fa30d6ddbbc186d70096f7c5b4593333 Mon Sep 17 00:00:00 2001 From: ashmrtn Date: Mon, 3 Oct 2022 10:49:20 -0700 Subject: [PATCH] Skip kopia upload when no collections given (#846) ## Description Currently does not throw an error. Open to other suggestions on return values. ## Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [ ] :hamster: Trivial/Minor ## Issue(s) * closes #844 * #1000 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/kopia/wrapper.go | 4 ++++ src/internal/kopia/wrapper_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/internal/kopia/wrapper.go b/src/internal/kopia/wrapper.go index dd2aae9e9..5801917aa 100644 --- a/src/internal/kopia/wrapper.go +++ b/src/internal/kopia/wrapper.go @@ -390,6 +390,10 @@ func (w Wrapper) BackupCollections( defer trace.StartRegion(ctx, "kopia:backupCollections").End() + if len(collections) == 0 { + return &BackupStats{}, &details.Details{}, nil + } + progress := &corsoProgress{ pending: map[string]*itemDetails{}, deets: &details.Details{}, diff --git a/src/internal/kopia/wrapper_test.go b/src/internal/kopia/wrapper_test.go index 867672f73..7c960deb3 100644 --- a/src/internal/kopia/wrapper_test.go +++ b/src/internal/kopia/wrapper_test.go @@ -780,6 +780,34 @@ type backedupFile struct { data []byte } +func (suite *KopiaIntegrationSuite) TestBackupCollectionsHandlesNoCollections() { + table := []struct { + name string + collections []data.Collection + }{ + { + name: "NilCollections", + collections: nil, + }, + { + name: "EmptyCollections", + collections: []data.Collection{}, + }, + } + + for _, test := range table { + suite.T().Run(test.name, func(t *testing.T) { + ctx := context.Background() + + s, d, err := suite.w.BackupCollections(ctx, test.collections) + require.NoError(t, err) + + assert.Equal(t, BackupStats{}, *s) + assert.Empty(t, d.Entries) + }) + } +} + type KopiaSimpleRepoIntegrationSuite struct { suite.Suite w *Wrapper