| 1 | package git |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "os" |
| 6 | "path/filepath" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | // TestExecClientImplementsClient verifies ExecClient satisfies the Client |
| 11 | // interface by running a representative subset of operations against a real |
| 12 | // git repo. |
| 13 | func TestExecClientImplementsClient(t *testing.T) { |
| 14 | repo := initTestRepo(t) |
| 15 | ctx := context.Background() |
| 16 | |
| 17 | var c Client = NewExecClient() |
| 18 | |
| 19 | // FetchAll — no remote configured in the test repo, so we expect an error |
| 20 | // but the method must exist and be callable. |
| 21 | _ = c.FetchAll(ctx, repo) |
| 22 | |
| 23 | // WorktreeAdd / WorktreeRemove |
| 24 | wtPath := filepath.Join(t.TempDir(), "client-wt") |
| 25 | if err := c.WorktreeAdd(ctx, repo, wtPath, "client-branch", "main"); err != nil { |
| 26 | t.Fatalf("WorktreeAdd via Client: %v", err) |
| 27 | } |
| 28 | if _, err := os.Stat(filepath.Join(wtPath, "README.md")); err != nil { |
| 29 | t.Errorf("worktree should contain README.md: %v", err) |
| 30 | } |
| 31 | |
| 32 | if err := c.WorktreeRemove(ctx, repo, wtPath); err != nil { |
| 33 | t.Fatalf("WorktreeRemove via Client: %v", err) |
| 34 | } |
| 35 | if _, err := os.Stat(wtPath); !os.IsNotExist(err) { |
| 36 | t.Error("worktree directory should be removed") |
| 37 | } |
| 38 | |
| 39 | // BranchDelete |
| 40 | if err := c.BranchDelete(ctx, repo, "client-branch"); err != nil { |
| 41 | t.Fatalf("BranchDelete via Client: %v", err) |
| 42 | } |
| 43 | |
| 44 | // EnsureDataRef |
| 45 | ref := "refs/klaus/client-test" |
| 46 | if err := c.EnsureDataRef(ctx, repo, ref); err != nil { |
| 47 | t.Fatalf("EnsureDataRef via Client: %v", err) |
| 48 | } |
| 49 | |
| 50 | // SyncToDataRef |
| 51 | tmpFile := filepath.Join(t.TempDir(), "data.json") |
| 52 | if err := os.WriteFile(tmpFile, []byte(`{"test":true}`), 0o644); err != nil { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | files := map[string]string{"test/data.json": tmpFile} |
| 56 | if _, err := c.SyncToDataRef(ctx, repo, ref, "test sync", files); err != nil { |
| 57 | t.Fatalf("SyncToDataRef via Client: %v", err) |
| 58 | } |
| 59 | |
| 60 | // WorktreePrune — should succeed even with nothing to prune |
| 61 | if err := c.WorktreePrune(ctx, repo); err != nil { |
| 62 | t.Fatalf("WorktreePrune via Client: %v", err) |
| 63 | } |
| 64 | } |