MCPcopy
hub / github.com/kopia/kopia / remoteRepositoryTest

Function remoteRepositoryTest

internal/server/server_test.go:169–267  ·  view source on GitHub ↗

nolint:thelper

(ctx context.Context, t *testing.T, rep repo.Repository)

Source from the content-addressed store, hash-verified

167
168//nolint:thelper
169func remoteRepositoryTest(ctx context.Context, t *testing.T, rep repo.Repository) {
170 mustListSnapshotCount(ctx, t, rep, 0)
171 mustGetObjectNotFound(ctx, t, rep, mustParseObjectID(t, "abcd"))
172 mustGetManifestNotFound(ctx, t, rep, "mnosuchmanifest")
173 mustPrefetchObjectsNotFound(ctx, t, rep, mustParseObjectID(t, "abcd"))
174
175 var (
176 result object.ID
177 manifestID, manifestID2 manifest.ID
178 written = make([]byte, 100000)
179 srcInfo = snapshot.SourceInfo{
180 Host: servertesting.TestHostname,
181 UserName: servertesting.TestUsername,
182 Path: testPathname,
183 }
184 )
185
186 var uploaded int64
187
188 require.NoError(t, repo.WriteSession(ctx, rep, repo.WriteSessionOptions{
189 Purpose: "write test",
190 OnUpload: func(i int64) {
191 uploaded += i
192 },
193 }, func(ctx context.Context, w repo.RepositoryWriter) error {
194 mustGetObjectNotFound(ctx, t, w, mustParseObjectID(t, "abcd"))
195 mustGetManifestNotFound(ctx, t, w, "mnosuchmanifest")
196 mustListSnapshotCount(ctx, t, w, 0)
197 mustPrefetchObjectsNotFound(ctx, t, rep, mustParseObjectID(t, "abcd"))
198
199 result = mustWriteObject(ctx, t, w, written)
200
201 require.NoError(t, w.Flush(ctx))
202
203 if uploaded == 0 {
204 return errors.New("did not report uploaded bytes")
205 }
206
207 uploaded = 0
208 result2 := mustWriteObject(ctx, t, w, written)
209 require.NoError(t, w.Flush(ctx))
210
211 if uploaded != 0 {
212 return errors.New("unexpected upload when writing duplicate object")
213 }
214
215 if result != result2 {
216 return errors.Errorf("two identical object with different IDs: %v vs %v", result, result2)
217 }
218
219 // verify data is read back the same.
220 mustPrefetchObjects(ctx, t, w, result)
221 mustReadObject(ctx, t, w, result, written)
222
223 ow := w.NewObjectWriter(ctx, object.WriterOptions{
224 Prefix: manifest.ContentPrefix,
225 })
226

Callers 1

TestServerFunction · 0.85

Calls 15

WriteSessionFunction · 0.92
SaveSnapshotFunction · 0.92
mustListSnapshotCountFunction · 0.85
mustGetObjectNotFoundFunction · 0.85
mustGetManifestNotFoundFunction · 0.85
mustPrefetchObjectsFunction · 0.85
mustReadObjectFunction · 0.85
mustReadManifestFunction · 0.85
ErrorfMethod · 0.80
mustParseObjectIDFunction · 0.70
mustWriteObjectFunction · 0.70

Tested by

no test coverage detected