From 83815eee0edfe9b271edc09c4cd36ee0780d0d43 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Wed, 20 Sep 2023 09:07:34 -0700 Subject: [PATCH] Expand readonly mode test slightly (#4304) Must have forgotten to submit the suggestion for this in #4302 Maintenance is a quick way to check if readonly mode is working. It doesn't require pulling any data from graph but will still allow us to check for a sentinel error. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/pkg/repository/repository_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pkg/repository/repository_test.go b/src/pkg/repository/repository_test.go index d929cd615..a9d262a7f 100644 --- a/src/pkg/repository/repository_test.go +++ b/src/pkg/repository/repository_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/alcionai/clues" + "github.com/kopia/kopia/repo/blob/readonly" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -414,8 +415,13 @@ func (suite *RepositoryIntegrationSuite) TestConnect_ReadOnly() { r, err := Connect(ctx, account.Account{}, st, repo.GetID(), control.Options{Repo: ctrlRepo.Options{ReadOnly: true}}) assert.NoError(t, err) - // now we have repoID beforehand - assert.Equal(t, r.GetID(), r.GetID()) + // Maintenance attempts to write some blobs just to say it was running. Since + // we're in readonly mode it should fail with a sentinel error. + op, err := r.NewMaintenance(ctx, ctrlRepo.Maintenance{}) + require.NoError(t, err, clues.ToCore(err)) + + err = op.Run(ctx) + assert.ErrorIs(t, err, readonly.ErrReadonly) } // Test_Options tests that the options are passed through to the repository