From d077fc83c97b7fbdbeda9702828c8780182b2616 Mon Sep 17 00:00:00 2001 From: Gareth George Date: Sat, 25 Nov 2023 17:33:57 -0800 Subject: [PATCH] fix: repo orchestrator tests --- internal/orchestrator/repo.go | 5 +++++ internal/orchestrator/repo_test.go | 36 +++++++++++++++--------------- pkg/restic/restic.go | 1 - 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/internal/orchestrator/repo.go b/internal/orchestrator/repo.go index cb62f7a06..77d7e2bfc 100644 --- a/internal/orchestrator/repo.go +++ b/internal/orchestrator/repo.go @@ -48,6 +48,11 @@ func (r *RepoOrchestrator) SnapshotsForPlan(ctx context.Context, plan *v1.Plan) func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCallback func(event *restic.BackupProgressEntry)) (*restic.BackupProgressEntry, error) { zap.L().Debug("repo orchestrator starting backup", zap.String("repo", r.repoConfig.Id)) + + if err := r.repo.Init(ctx); err != nil { + return nil, fmt.Errorf("failed to init repo: %w", err) + } + snapshots, err := r.SnapshotsForPlan(ctx, plan) if err != nil { return nil, fmt.Errorf("failed to get snapshots for plan: %w", err) diff --git a/internal/orchestrator/repo_test.go b/internal/orchestrator/repo_test.go index b348191e2..6994beeaa 100644 --- a/internal/orchestrator/repo_test.go +++ b/internal/orchestrator/repo_test.go @@ -18,15 +18,15 @@ func TestBackup(t *testing.T) { // create a new repo with cache disabled for testing r := &v1.Repo{ - Id: "test", - Uri: repo, + Id: "test", + Uri: repo, Password: "test", - Flags: []string{"--no-cache"}, + Flags: []string{"--no-cache"}, } - + plan := &v1.Plan{ - Id: "test", - Repo: "test", + Id: "test", + Repo: "test", Paths: []string{testData}, } @@ -48,34 +48,34 @@ func TestBackup(t *testing.T) { func TestSnapshotParenting(t *testing.T) { t.Parallel() - + repo := t.TempDir() testData := test.CreateTestData(t) // create a new repo with cache disabled for testing r := &v1.Repo{ - Id: "test", - Uri: repo, + Id: "test", + Uri: repo, Password: "test", - Flags: []string{"--no-cache"}, + Flags: []string{"--no-cache"}, } plans := []*v1.Plan{ { - Id: "test", - Repo: "test", + Id: "test", + Repo: "test", Paths: []string{testData}, }, { - Id: "test2", - Repo: "test", + Id: "test2", + Repo: "test", Paths: []string{testData}, }, } orchestrator := newRepoOrchestrator(r, restic.NewRepo(r, restic.WithFlags("--no-cache"))) - for i := 0; i < 4; i ++{ + for i := 0; i < 4; i++ { for _, plan := range plans { summary, err := orchestrator.Backup(context.Background(), plan, nil) if err != nil { @@ -92,7 +92,7 @@ func TestSnapshotParenting(t *testing.T) { } } } - + for _, plan := range plans { snapshots, err := orchestrator.SnapshotsForPlan(context.Background(), plan) if err != nil { @@ -105,7 +105,7 @@ func TestSnapshotParenting(t *testing.T) { } for i := 1; i < len(snapshots); i++ { - prev := snapshots[i - 1] + prev := snapshots[i-1] curr := snapshots[i] if prev.ToProto().UnixTimeMs >= curr.ToProto().UnixTimeMs { @@ -129,4 +129,4 @@ func TestSnapshotParenting(t *testing.T) { if len(snapshots) != 8 { t.Errorf("expected 8 snapshots, got %d", len(snapshots)) } -} \ No newline at end of file +} diff --git a/pkg/restic/restic.go b/pkg/restic/restic.go index 9978fa9d2..5b73e7cbf 100644 --- a/pkg/restic/restic.go +++ b/pkg/restic/restic.go @@ -77,7 +77,6 @@ func (r *Repo) init(ctx context.Context) error { func (r *Repo) Init(ctx context.Context) error { r.mu.Lock() defer r.mu.Unlock() - r.initialized = false return r.init(ctx) }