From 166aed7f74cd7236b11a2c06704604947edfc668 Mon Sep 17 00:00:00 2001 From: Gareth Date: Sun, 7 Sep 2025 22:41:06 -0700 Subject: [PATCH] chore: add elementary e2e api coverage for all repo and plan operation types --- test/e2e/first_run_test.go | 81 ++++++++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/test/e2e/first_run_test.go b/test/e2e/first_run_test.go index c8fbdd0..92fdcae 100644 --- a/test/e2e/first_run_test.go +++ b/test/e2e/first_run_test.go @@ -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,