(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func TestRun_Plan_JSONDoesNotPush(t *testing.T) { |
| 112 | sourceRepo, sourceFS := newSourceRepo(t) |
| 113 | makeCommits(t, sourceRepo, sourceFS, 3) |
| 114 | |
| 115 | targetRepo, err := git.Init(memory.NewStorage()) |
| 116 | if err != nil { |
| 117 | t.Fatalf("init target repo: %v", err) |
| 118 | } |
| 119 | |
| 120 | sourceServer := newSmartHTTPRepoServer(t, sourceRepo) |
| 121 | targetServer := newSmartHTTPRepoServer(t, targetRepo) |
| 122 | defer sourceServer.Close() |
| 123 | defer targetServer.Close() |
| 124 | |
| 125 | output, err := captureStdout(func() error { |
| 126 | return run(context.Background(), []string{ |
| 127 | "plan", |
| 128 | "--json", |
| 129 | "--stats", |
| 130 | sourceServer.RepoURL(), |
| 131 | targetServer.RepoURL(), |
| 132 | }) |
| 133 | }) |
| 134 | if err != nil { |
| 135 | t.Fatalf("run plan: %v", err) |
| 136 | } |
| 137 | |
| 138 | var result map[string]any |
| 139 | if err := json.Unmarshal([]byte(output), &result); err != nil { |
| 140 | t.Fatalf("decode plan json: %v\noutput=%s", err, output) |
| 141 | } |
| 142 | if result["dryRun"] != true { |
| 143 | t.Fatalf("expected dryRun=true, got %#v", result["dryRun"]) |
| 144 | } |
| 145 | if result["operationMode"] != "sync" { |
| 146 | t.Fatalf("expected operationMode=sync, got %#v", result["operationMode"]) |
| 147 | } |
| 148 | if result["bootstrapSuggested"] != true { |
| 149 | t.Fatalf("expected bootstrapSuggested=true, got %#v", result["bootstrapSuggested"]) |
| 150 | } |
| 151 | if result["relayReason"] != "empty-target-managed-refs" { |
| 152 | t.Fatalf("expected relayReason for bootstrap suggestion, got %#v", result["relayReason"]) |
| 153 | } |
| 154 | plans, ok := result["plans"].([]any) |
| 155 | if !ok || len(plans) == 0 { |
| 156 | t.Fatalf("expected plan entries, got %#v", result["plans"]) |
| 157 | } |
| 158 | plan0, ok := plans[0].(map[string]any) |
| 159 | if !ok { |
| 160 | t.Fatalf("unexpected first plan entry: %#v", plans[0]) |
| 161 | } |
| 162 | if plan0["sourceHash"] == nil || plan0["targetHash"] == nil { |
| 163 | t.Fatalf("expected string hash fields in plan entry, got %#v", plan0) |
| 164 | } |
| 165 | if _, ok := plan0["sourceHash"].(string); !ok { |
| 166 | t.Fatalf("expected sourceHash string, got %#v", plan0["sourceHash"]) |
| 167 | } |
| 168 | if _, ok := plan0["targetHash"].(string); !ok { |
nothing calls this directly
no test coverage detected