mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-16 18:45:36 +00:00
fix: backrest should only initialize repos explicitly added through WebUI
This commit is contained in:
@@ -668,6 +668,17 @@ func createSystemUnderTest(t *testing.T, config config.ConfigStore) systemUnderT
|
|||||||
t.Fatalf("Failed to create orchestrator: %v", err)
|
t.Fatalf("Failed to create orchestrator: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, repo := range cfg.Repos {
|
||||||
|
rorch, err := orch.GetRepoOrchestrator(repo.Id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to get repo %s: %v", repo.Id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := rorch.Init(context.Background()); err != nil {
|
||||||
|
t.Fatalf("Failed to init repo %s: %v", repo.Id, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
h := NewBackrestHandler(config, orch, oplog, logStore)
|
h := NewBackrestHandler(config, orch, oplog, logStore)
|
||||||
|
|
||||||
return systemUnderTest{
|
return systemUnderTest{
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ type RepoOrchestrator struct {
|
|||||||
config *v1.Config
|
config *v1.Config
|
||||||
repoConfig *v1.Repo
|
repoConfig *v1.Repo
|
||||||
repo *restic.Repo
|
repo *restic.Repo
|
||||||
initialized bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRepoOrchestrator accepts a config and a repo that is configured with the properties of that config object.
|
// NewRepoOrchestrator accepts a config and a repo that is configured with the properties of that config object.
|
||||||
@@ -123,13 +122,6 @@ func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCa
|
|||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
if !r.initialized {
|
|
||||||
if err := r.repo.Init(ctx); err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to initialize repo: %w", err)
|
|
||||||
}
|
|
||||||
r.initialized = true
|
|
||||||
}
|
|
||||||
|
|
||||||
snapshots, err := r.SnapshotsForPlan(ctx, plan)
|
snapshots, err := r.SnapshotsForPlan(ctx, plan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get snapshots for plan: %w", err)
|
return nil, fmt.Errorf("failed to get snapshots for plan: %w", err)
|
||||||
|
|||||||
@@ -68,10 +68,7 @@ func TestBackup(t *testing.T) {
|
|||||||
t.Skip("skipping on windows")
|
t.Skip("skipping on windows")
|
||||||
}
|
}
|
||||||
|
|
||||||
orchestrator, err := NewRepoOrchestrator(configForTest, tc.repo, helpers.ResticBinary(t))
|
orchestrator := initRepoHelper(t, configForTest, tc.repo)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create repo orchestrator: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
summary, err := orchestrator.Backup(context.Background(), tc.plan, nil)
|
summary, err := orchestrator.Backup(context.Background(), tc.plan, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -116,10 +113,7 @@ func TestSnapshotParenting(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
orchestrator, err := NewRepoOrchestrator(configForTest, r, helpers.ResticBinary(t))
|
orchestrator := initRepoHelper(t, configForTest, r)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create repo orchestrator: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
for _, plan := range plans {
|
for _, plan := range plans {
|
||||||
@@ -181,7 +175,6 @@ func TestEnvVarPropagation(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
repo := t.TempDir()
|
repo := t.TempDir()
|
||||||
testData := test.CreateTestData(t)
|
|
||||||
|
|
||||||
// create a new repo with cache disabled for testing
|
// create a new repo with cache disabled for testing
|
||||||
r := &v1.Repo{
|
r := &v1.Repo{
|
||||||
@@ -191,18 +184,12 @@ func TestEnvVarPropagation(t *testing.T) {
|
|||||||
Env: []string{"RESTIC_PASSWORD=${MY_FOO}"},
|
Env: []string{"RESTIC_PASSWORD=${MY_FOO}"},
|
||||||
}
|
}
|
||||||
|
|
||||||
plan := &v1.Plan{
|
|
||||||
Id: "test",
|
|
||||||
Repo: "test",
|
|
||||||
Paths: []string{testData},
|
|
||||||
}
|
|
||||||
|
|
||||||
orchestrator, err := NewRepoOrchestrator(configForTest, r, helpers.ResticBinary(t))
|
orchestrator, err := NewRepoOrchestrator(configForTest, r, helpers.ResticBinary(t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create repo orchestrator: %v", err)
|
t.Fatalf("failed to create repo orchestrator: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = orchestrator.Backup(context.Background(), plan, nil)
|
err = orchestrator.Init(context.Background())
|
||||||
if err == nil || !strings.Contains(err.Error(), "password") {
|
if err == nil || !strings.Contains(err.Error(), "password") {
|
||||||
t.Fatalf("expected error about RESTIC_PASSWORD, got: %v", err)
|
t.Fatalf("expected error about RESTIC_PASSWORD, got: %v", err)
|
||||||
}
|
}
|
||||||
@@ -214,14 +201,10 @@ func TestEnvVarPropagation(t *testing.T) {
|
|||||||
t.Fatalf("failed to create repo orchestrator: %v", err)
|
t.Fatalf("failed to create repo orchestrator: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
summary, err := orchestrator.Backup(context.Background(), plan, nil)
|
err = orchestrator.Init(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("backup error: %v", err)
|
t.Fatalf("backup error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if summary.SnapshotId == "" {
|
|
||||||
t.Fatal("expected snapshot id")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheck(t *testing.T) {
|
func TestCheck(t *testing.T) {
|
||||||
@@ -259,14 +242,10 @@ func TestCheck(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range tcs {
|
for _, tc := range tcs {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
orchestrator, err := NewRepoOrchestrator(configForTest, tc.repo, helpers.ResticBinary(t))
|
orchestrator := initRepoHelper(t, configForTest, tc.repo)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create repo orchestrator: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
err = orchestrator.Init(context.Background())
|
err := orchestrator.Init(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("init error: %v", err)
|
t.Fatalf("init error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -279,3 +258,17 @@ func TestCheck(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initRepoHelper(t *testing.T, config *v1.Config, repo *v1.Repo) *RepoOrchestrator {
|
||||||
|
orchestrator, err := NewRepoOrchestrator(config, repo, helpers.ResticBinary(t))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create repo orchestrator: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = orchestrator.Init(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("init error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return orchestrator
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user