chore: add elementary e2e api coverage for all repo and plan operation types
Some checks failed
Release Please / release-please (push) Has been cancelled
Release Preview / call-reusable-release (push) Has been cancelled
Test / test-nix (push) Has been cancelled
Test / test-win (push) Has been cancelled
Update Restic / update-restic-version (push) Has been cancelled

This commit is contained in:
Gareth
2025-09-07 22:41:06 -07:00
parent 77e062353e
commit 166aed7f74

View File

@@ -12,6 +12,7 @@ import (
"time"
"connectrpc.com/connect"
"github.com/garethgeorge/backrest/gen/go/types"
v1 "github.com/garethgeorge/backrest/gen/go/v1"
"github.com/garethgeorge/backrest/gen/go/v1/v1connect"
"github.com/garethgeorge/backrest/internal/testutil"
@@ -26,6 +27,11 @@ func TestFirstRun(t *testing.T) {
}
defer os.RemoveAll(tmpDir)
tmpDataToBackup := filepath.Join(tmpDir, "data-to-backup")
if err := os.Mkdir(tmpDataToBackup, 0755); err != nil {
t.Fatalf("failed to create temp data to backup dir: %v", err)
}
binPath := filepath.Join(tmpDir, "backrest")
if runtime.GOOS == "windows" {
binPath += ".exe"
@@ -120,22 +126,83 @@ func TestFirstRun(t *testing.T) {
}
})
t.Run("trigger check", func(t *testing.T) {
t.Run("add plan", func(t *testing.T) {
// flow is fetch config, add plan to plans field of config, update config
client := v1connect.NewBackrestClient(
http.DefaultClient,
fmt.Sprintf("http://%s", addr),
)
req := connect.NewRequest(&v1.DoRepoTaskRequest{
RepoId: "test-repo",
Task: v1.DoRepoTaskRequest_TASK_CHECK,
})
_, err := client.DoRepoTask(context.Background(), req)
resp, err := client.GetConfig(context.Background(), connect.NewRequest(&emptypb.Empty{}))
if err != nil {
t.Fatalf("DoRepoTask failed: %v", err)
t.Fatalf("GetConfig failed: %v", err)
}
resp.Msg.Plans = append(resp.Msg.Plans, &v1.Plan{
Id: "test-plan",
Repo: "test-repo",
Paths: []string{
tmpDataToBackup,
},
})
_, err = client.SetConfig(context.Background(), connect.NewRequest(resp.Msg))
if err != nil {
t.Fatalf("SetConfig failed: %v", err)
}
})
t.Run("run backup operation", func(t *testing.T) {
client := v1connect.NewBackrestClient(
http.DefaultClient,
fmt.Sprintf("http://%s", addr),
)
_, err := client.Backup(context.Background(), connect.NewRequest(&types.StringValue{
Value: "test-plan",
}))
if err != nil {
t.Fatalf("Backup failed: %v", err)
}
})
for _, tc := range []struct {
name string
task v1.DoRepoTaskRequest_Task
}{
{
name: "check",
task: v1.DoRepoTaskRequest_TASK_CHECK,
},
{
name: "prune",
task: v1.DoRepoTaskRequest_TASK_PRUNE,
},
{
name: "stats",
task: v1.DoRepoTaskRequest_TASK_STATS,
},
{
name: "index snapshots",
task: v1.DoRepoTaskRequest_TASK_INDEX_SNAPSHOTS,
},
} {
t.Run(fmt.Sprintf("trigger %s", tc.name), func(t *testing.T) {
client := v1connect.NewBackrestClient(
http.DefaultClient,
fmt.Sprintf("http://%s", addr),
)
req := connect.NewRequest(&v1.DoRepoTaskRequest{
RepoId: "test-repo",
Task: tc.task,
})
_, err := client.DoRepoTask(context.Background(), req)
if err != nil {
t.Fatalf("DoRepoTask failed: %v", err)
}
})
}
t.Run("get operations", func(t *testing.T) {
client := v1connect.NewBackrestClient(
http.DefaultClient,