Smoke test: cobra flag parsing through the full sync pipeline.
(t *testing.T)
| 285 | |
| 286 | // Smoke test: cobra flag parsing through the full sync pipeline. |
| 287 | func TestRun_Sync_AllRefsSmokeTest(t *testing.T) { |
| 288 | sourceRepo, sourceFS := newSourceRepo(t) |
| 289 | makeCommits(t, sourceRepo, sourceFS, 2) |
| 290 | |
| 291 | notesRef := plumbing.ReferenceName("refs/notes/commits") |
| 292 | head := syncertest.SetRefAtBranch(t, sourceRepo, notesRef, testBranch) |
| 293 | |
| 294 | targetRepo, err := git.Init(memory.NewStorage()) |
| 295 | if err != nil { |
| 296 | t.Fatalf("init target repo: %v", err) |
| 297 | } |
| 298 | |
| 299 | sourceServer := newSmartHTTPRepoServer(t, sourceRepo) |
| 300 | targetServer := newSmartHTTPRepoServer(t, targetRepo) |
| 301 | defer sourceServer.Close() |
| 302 | defer targetServer.Close() |
| 303 | |
| 304 | output, err := captureStdout(func() error { |
| 305 | return run(context.Background(), []string{ |
| 306 | "sync", |
| 307 | "--all-refs", |
| 308 | "--json", |
| 309 | sourceServer.RepoURL(), |
| 310 | targetServer.RepoURL(), |
| 311 | }) |
| 312 | }) |
| 313 | if err != nil { |
| 314 | t.Fatalf("run sync --all-refs: %v\noutput=%s", err, output) |
| 315 | } |
| 316 | |
| 317 | var result map[string]any |
| 318 | if err := json.Unmarshal([]byte(output), &result); err != nil { |
| 319 | t.Fatalf("decode sync json: %v\noutput=%s", err, output) |
| 320 | } |
| 321 | |
| 322 | plans, ok := result["plans"].([]any) |
| 323 | if !ok || len(plans) < 2 { |
| 324 | t.Fatalf("expected at least 2 plans (branch + notes), got %#v", result["plans"]) |
| 325 | } |
| 326 | var foundNotesRef bool |
| 327 | for _, raw := range plans { |
| 328 | plan, ok := raw.(map[string]any) |
| 329 | if !ok { |
| 330 | continue |
| 331 | } |
| 332 | if plan["targetRef"] == "refs/notes/commits" { |
| 333 | if plan["kind"] != "other" { |
| 334 | t.Errorf("expected notes ref kind=other, got %#v", plan["kind"]) |
| 335 | } |
| 336 | if plan["action"] != "create" { |
| 337 | t.Errorf("expected notes ref action=create, got %#v", plan["action"]) |
| 338 | } |
| 339 | foundNotesRef = true |
| 340 | } |
| 341 | } |
| 342 | if !foundNotesRef { |
| 343 | t.Fatalf("refs/notes/commits not in plans output: %s", output) |
| 344 | } |
nothing calls this directly
no test coverage detected