Skip to content

Commit 4f6c4b0

Browse files
committed
plumbing: transport, correct tests for update-requests capabilities and
add missing packfile in tests
1 parent 21bdba9 commit 4f6c4b0

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

internal/transport/test/receive_pack.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,6 @@ func (s *ReceivePackSuite) TestSendPackOnNonEmptyWithReportStatusWithError() {
211211
req.Commands = []*packp.Command{
212212
{Name: "refs/heads/master", Old: plumbing.ZeroHash, New: plumbing.NewHash(fixture.Head)},
213213
}
214-
// req.Capabilities.Set(capability.ReportStatus)
215-
216-
// report, err := s.receivePackNoCheck(endpoint, req, fixture, full)
217214
err := s.receivePackNoCheck(endpoint, req, fixture, full)
218215
// XXX: Recent git versions return "failed to update ref", while older
219216
// (>=1.9) return "failed to lock".

plumbing/transport/build_update_requests_test.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func TestBuildUpdateRequestsWithProgress(t *testing.T) {
7575

7676
upreq := buildUpdateRequests(caps, req)
7777

78-
// Verify Sideband64k capability is set
79-
assert.True(t, upreq.Capabilities.Supports(capability.Sideband64k))
78+
// Verify Sideband64k capability is not set
79+
assert.False(t, upreq.Capabilities.Supports(capability.Sideband64k))
8080
assert.False(t, upreq.Capabilities.Supports(capability.Sideband))
8181
assert.False(t, upreq.Capabilities.Supports(capability.NoProgress))
8282
}
@@ -99,9 +99,9 @@ func TestBuildUpdateRequestsWithProgressFallback(t *testing.T) {
9999

100100
upreq := buildUpdateRequests(caps, req)
101101

102-
// Verify Sideband capability is set but not Sideband64k
102+
// Verify Sideband capability is not set but not Sideband64k
103103
assert.False(t, upreq.Capabilities.Supports(capability.Sideband64k))
104-
assert.True(t, upreq.Capabilities.Supports(capability.Sideband))
104+
assert.False(t, upreq.Capabilities.Supports(capability.Sideband))
105105
assert.False(t, upreq.Capabilities.Supports(capability.NoProgress))
106106
}
107107

@@ -122,8 +122,8 @@ func TestBuildUpdateRequestsWithNoProgress(t *testing.T) {
122122

123123
upreq := buildUpdateRequests(caps, req)
124124

125-
// Verify NoProgress capability is set
126-
assert.True(t, upreq.Capabilities.Supports(capability.NoProgress))
125+
// Verify NoProgress capability is not set
126+
assert.False(t, upreq.Capabilities.Supports(capability.NoProgress))
127127
}
128128

129129
func TestBuildUpdateRequestsWithAtomic(t *testing.T) {
@@ -184,12 +184,8 @@ func TestBuildUpdateRequestsWithAgent(t *testing.T) {
184184

185185
upreq := buildUpdateRequests(caps, req)
186186

187-
// Verify Agent capability is set
188-
assert.True(t, upreq.Capabilities.Supports(capability.Agent))
189-
190-
// Verify agent value is set to default agent
191-
val := upreq.Capabilities.Get(capability.Agent)
192-
assert.Equal(t, []string{capability.DefaultAgent()}, val)
187+
// Verify Agent capability is not set
188+
assert.False(t, upreq.Capabilities.Supports(capability.Agent))
193189
}
194190

195191
// mockWriter is a simple io.Writer implementation for testing

plumbing/transport/send_pack_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (rw *mockReadWriteCloser) Close() error {
8989
// TestSendPackWithReportStatus tests the SendPack function with ReportStatus capability
9090
func TestSendPackWithReportStatus(t *testing.T) {
9191
caps := capability.NewList()
92-
caps.Add(capability.ReportStatus)
92+
caps.Add(capability.ReportStatus) //nolint:errcheck
9393
conn := &mockConnection{caps: caps}
9494

9595
// Create a mock reader with a valid report status response
@@ -101,6 +101,7 @@ func TestSendPackWithReportStatus(t *testing.T) {
101101
reader := newMockRWC([]byte(reportStatusResponse))
102102
writer := newMockRWC(nil)
103103

104+
var buf bytes.Buffer
104105
req := &PushRequest{
105106
Commands: []*packp.Command{
106107
{
@@ -109,6 +110,7 @@ func TestSendPackWithReportStatus(t *testing.T) {
109110
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
110111
},
111112
},
113+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
112114
}
113115

114116
storer := memory.NewStorage()
@@ -135,6 +137,7 @@ func TestSendPackWithReportStatusError(t *testing.T) {
135137
reader := newMockRWC([]byte(reportStatusResponse))
136138
writer := newMockRWC(nil)
137139

140+
var buf bytes.Buffer
138141
req := &PushRequest{
139142
Commands: []*packp.Command{
140143
{
@@ -143,6 +146,7 @@ func TestSendPackWithReportStatusError(t *testing.T) {
143146
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
144147
},
145148
},
149+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
146150
}
147151

148152
// Call SendPack
@@ -167,6 +171,7 @@ func TestSendPackWithoutReportStatus(t *testing.T) {
167171
reader := newMockRWC(nil)
168172
writer := newMockRWC(nil)
169173

174+
var buf bytes.Buffer
170175
req := &PushRequest{
171176
Commands: []*packp.Command{
172177
{
@@ -175,6 +180,7 @@ func TestSendPackWithoutReportStatus(t *testing.T) {
175180
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
176181
},
177182
},
183+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
178184
}
179185

180186
storer := memory.NewStorage()
@@ -216,6 +222,7 @@ func TestSendPackWithProgress(t *testing.T) {
216222
// Create a progress buffer to capture progress messages
217223
progressBuf := &bytes.Buffer{}
218224

225+
var buf bytes.Buffer
219226
req := &PushRequest{
220227
Commands: []*packp.Command{
221228
{
@@ -224,6 +231,7 @@ func TestSendPackWithProgress(t *testing.T) {
224231
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
225232
},
226233
},
234+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
227235
Progress: progressBuf,
228236
}
229237

@@ -289,6 +297,7 @@ func TestSendPackErrors(t *testing.T) {
289297
writer.writeErr = errors.New("encode error")
290298
reader := newMockRWC(nil)
291299

300+
var buf bytes.Buffer
292301
req := &PushRequest{
293302
Commands: []*packp.Command{
294303
{
@@ -297,6 +306,7 @@ func TestSendPackErrors(t *testing.T) {
297306
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
298307
},
299308
},
309+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
300310
}
301311

302312
storer := memory.NewStorage()
@@ -336,6 +346,7 @@ func TestSendPackErrors(t *testing.T) {
336346
writer.closeErr = errors.New("writer close error")
337347
reader := newMockRWC(nil)
338348

349+
var buf bytes.Buffer
339350
req := &PushRequest{
340351
Commands: []*packp.Command{
341352
{
@@ -344,6 +355,7 @@ func TestSendPackErrors(t *testing.T) {
344355
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
345356
},
346357
},
358+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
347359
}
348360

349361
storer := memory.NewStorage()
@@ -361,6 +373,7 @@ func TestSendPackErrors(t *testing.T) {
361373
reader := newMockRWC([]byte(invalidResponse))
362374
writer := newMockRWC(nil)
363375

376+
var buf bytes.Buffer
364377
req := &PushRequest{
365378
Commands: []*packp.Command{
366379
{
@@ -369,6 +382,7 @@ func TestSendPackErrors(t *testing.T) {
369382
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
370383
},
371384
},
385+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
372386
}
373387

374388
storer := memory.NewStorage()
@@ -388,6 +402,7 @@ func TestSendPackErrors(t *testing.T) {
388402
reader.closeErr = errors.New("reader close error")
389403
writer := newMockRWC(nil)
390404

405+
var buf bytes.Buffer
391406
req := &PushRequest{
392407
Commands: []*packp.Command{
393408
{
@@ -396,6 +411,7 @@ func TestSendPackErrors(t *testing.T) {
396411
New: plumbing.NewHash("0123456789012345678901234567890123456789"),
397412
},
398413
},
414+
Packfile: io.NopCloser(&buf), // Use a buffer to simulate packfile
399415
}
400416

401417
storer := memory.NewStorage()

0 commit comments

Comments
 (0)