feat: support restic check operation (#303)

This commit is contained in:
Gareth
2024-05-27 10:26:18 -07:00
committed by GitHub
parent 5a51ae7c20
commit ce42f68d0d
43 changed files with 1807 additions and 989 deletions

View File

@@ -1,6 +1,7 @@
package repo
import (
"bytes"
"context"
"os"
"slices"
@@ -189,3 +190,59 @@ func TestEnvVarPropagation(t *testing.T) {
t.Fatal("expected snapshot id")
}
}
func TestCheck(t *testing.T) {
t.Parallel()
tcs := []struct {
name string
repo *v1.Repo
}{
{
name: "check structure",
repo: &v1.Repo{
Id: "test",
Uri: t.TempDir(),
Password: "test",
CheckPolicy: &v1.CheckPolicy{
Mode: nil,
},
},
},
{
name: "read data percent",
repo: &v1.Repo{
Id: "test",
Uri: t.TempDir(),
Password: "test",
CheckPolicy: &v1.CheckPolicy{
Mode: &v1.CheckPolicy_ReadDataSubsetPercent{
ReadDataSubsetPercent: 50,
},
},
},
},
}
for _, tc := range tcs {
t.Run(tc.name, func(t *testing.T) {
orchestrator, err := NewRepoOrchestrator(configForTest, tc.repo, helpers.ResticBinary(t))
if err != nil {
t.Fatalf("failed to create repo orchestrator: %v", err)
}
buf := bytes.NewBuffer(nil)
err = orchestrator.Init(context.Background())
if err != nil {
t.Fatalf("init error: %v", err)
}
err = orchestrator.Check(context.Background(), buf)
if err != nil {
t.Errorf("check error: %v", err)
}
t.Logf("check output: %s", buf.String())
})
}
}