MCPcopy
hub / github.com/kopia/kopia / TestObjectWritesWithRetention

Function TestObjectWritesWithRetention

repo/repository_test.go:557–602  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

555}
556
557func TestObjectWritesWithRetention(t *testing.T) {
558 ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant, repotesting.Options{
559 NewRepositoryOptions: func(n *repo.NewRepositoryOptions) {
560 n.RetentionMode = blob.Governance
561 n.RetentionPeriod = time.Hour * 24
562 },
563 })
564
565 writer := env.RepositoryWriter.NewObjectWriter(ctx, object.WriterOptions{MetadataCompressor: "zstd-fastest"})
566 _, err := writer.Write([]byte("the quick brown fox jumps over the lazy dog"))
567 require.NoError(t, err)
568
569 _, err = writer.Result()
570 require.NoError(t, err)
571
572 env.RepositoryWriter.ContentManager().Flush(ctx)
573
574 var prefixesWithRetention []string
575
576 versionedMap := testutil.EnsureType[cache.Storage](t, env.RootStorage())
577
578 for _, prefix := range content.PackBlobIDPrefixes {
579 prefixesWithRetention = append(prefixesWithRetention, string(prefix))
580 }
581
582 prefixesWithRetention = append(prefixesWithRetention, indexblob.V0IndexBlobPrefix, epoch.EpochManagerIndexUberPrefix,
583 format.KopiaRepositoryBlobID, format.KopiaBlobCfgBlobID)
584
585 // make sure that we cannot set mtime on the kopia objects created due to the
586 // retention time constraint
587 require.NoError(t, versionedMap.ListBlobs(ctx, "", func(it blob.Metadata) error {
588 for _, prefix := range prefixesWithRetention {
589 if strings.HasPrefix(string(it.BlobID), prefix) {
590 _, err = versionedMap.TouchBlob(ctx, it.BlobID, 0)
591 require.Error(t, err, "expected error while touching blob %s", it.BlobID)
592
593 return nil
594 }
595 }
596
597 _, err = versionedMap.TouchBlob(ctx, it.BlobID, 0)
598 require.NoError(t, err, "unexpected error while touching blob %s", it.BlobID)
599
600 return nil
601 }))
602}
603
604func TestWriteSessionFlushOnSuccess(t *testing.T) {
605 var beforeFlushCount, afterFlushCount atomic.Int32

Callers

nothing calls this directly

Calls 12

NewEnvironmentFunction · 0.92
EnsureTypeFunction · 0.92
RootStorageMethod · 0.80
HasPrefixMethod · 0.80
NewObjectWriterMethod · 0.65
ResultMethod · 0.65
FlushMethod · 0.65
ContentManagerMethod · 0.65
ListBlobsMethod · 0.65
TouchBlobMethod · 0.65
ErrorMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected