MCPcopy Create free account
hub / github.com/go-git/go-git / TestPackWriterExistingReadOnly

Function TestPackWriterExistingReadOnly

storage/filesystem/dotgit/writers_test.go:184–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestPackWriterExistingReadOnly(t *testing.T) {
185 t.Parallel()
186
187 for _, tc := range []struct {
188 name string
189 fs billy.Filesystem
190 }{
191 {"BoundOS", osfs.New(t.TempDir(), osfs.WithBoundOS())},
192 {"ChrootOS", osfs.New(t.TempDir(), osfs.WithChrootOS())},
193 } {
194 t.Run(tc.name, func(t *testing.T) {
195 t.Parallel()
196
197 f := fixtures.Basic().One()
198
199 dot := New(tc.fs)
200 require.NoError(t, dot.Initialize())
201
202 pfPath := filepath.Join("objects", "pack", fmt.Sprintf("pack-%s.pack", f.PackfileHash))
203 idxPath := filepath.Join("objects", "pack", fmt.Sprintf("pack-%s.idx", f.PackfileHash))
204
205 writePack := func() {
206 t.Helper()
207 w, err := dot.NewObjectPack()
208 require.NoError(t, err)
209
210 _, err = io.Copy(w, f.Packfile())
211 require.NoError(t, err)
212 require.NoError(t, w.Close())
213 }
214
215 writePack()
216
217 ro, err := isReadOnly(tc.fs, pfPath)
218 require.NoError(t, err)
219 assert.True(t, ro, "file %q is not read-only", pfPath)
220
221 ro, err = isReadOnly(tc.fs, idxPath)
222 require.NoError(t, err)
223 assert.True(t, ro, "file %q is not read-only", idxPath)
224
225 writePack()
226
227 // Remove .idx only, keep .pack — the next write must
228 // recreate .idx without touching the existing .pack.
229 require.NoError(t, tc.fs.Remove(idxPath))
230 writePack()
231
232 _, err = tc.fs.Lstat(idxPath)
233 require.NoError(t, err, ".idx should have been recreated")
234
235 ro, err = isReadOnly(tc.fs, idxPath)
236 require.NoError(t, err)
237 assert.True(t, ro, "recreated %q is not read-only", idxPath)
238 })
239 }
240}
241

Callers

nothing calls this directly

Calls 8

InitializeMethod · 0.80
JoinMethod · 0.80
NewObjectPackMethod · 0.80
NewFunction · 0.70
isReadOnlyFunction · 0.70
CloseMethod · 0.65
RemoveMethod · 0.45
LstatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…