MCPcopy Create free account
hub / github.com/entireio/git-sync / TestRun_Plan_JSONDoesNotPush

Function TestRun_Plan_JSONDoesNotPush

cmd/git-sync/main_test.go:111–183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

109}
110
111func 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 {

Callers

nothing calls this directly

Calls 8

captureStdoutFunction · 0.85
newSourceRepoFunction · 0.70
makeCommitsFunction · 0.70
newSmartHTTPRepoServerFunction · 0.70
runFunction · 0.70
CloseMethod · 0.65
RepoURLMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected