MCPcopy
hub / github.com/kopia/kopia / TestUpdateRetention

Function TestUpdateRetention

repo/format/format_manager_test.go:223–275  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

221}
222
223func TestUpdateRetention(t *testing.T) {
224 ctx := testlogging.Context(t)
225
226 mode := blob.Governance
227 period := time.Hour * 48
228
229 ta := faketime.NewClockTimeWithOffset(0)
230 nowFunc := ta.NowFunc()
231 earliestExpiry := nowFunc().Add(period)
232
233 st := blobtesting.NewVersionedMapStorage(nowFunc)
234 blobCache := format.NewMemoryBlobCache(nowFunc)
235
236 // success
237 require.NoError(t, format.Initialize(ctx, st, &format.KopiaRepositoryJSON{}, rc, format.BlobStorageConfiguration{}, "some-password"))
238
239 mgr, err := format.NewManagerWithCache(ctx, st, cacheDuration, "some-password", nowFunc, blobCache)
240 require.NoError(t, err, "getting format manager")
241
242 mp := mustGetMutableParameters(t, mgr)
243 rf := mustGetRequiredFeatures(t, mgr)
244
245 err = mgr.SetParameters(
246 ctx,
247 mp,
248 format.BlobStorageConfiguration{
249 RetentionMode: mode,
250 RetentionPeriod: period,
251 },
252 rf,
253 )
254 require.NoError(t, err, "setting repo parameters")
255
256 // New retention parameters should be available from the format manager.
257 blobCfg := mustGetBlobStorageConfiguration(t, mgr)
258 assert.Equal(t, mode, blobCfg.RetentionMode)
259 assert.Equal(t, period, blobCfg.RetentionPeriod)
260
261 // Get the retention configuration that was added to the blob. Allow up to a
262 // minute difference between the expected and returned values since that
263 // should be large enough to avoid test flakes.
264 gotMode, expiry, err := st.GetRetention(ctx, format.KopiaRepositoryBlobID)
265 require.NoError(t, err, "getting repo blob retention info")
266
267 assert.Equal(t, mode, gotMode)
268 assert.WithinDuration(t, earliestExpiry, expiry, time.Minute)
269
270 gotMode, expiry, err = st.GetRetention(ctx, format.KopiaBlobCfgBlobID)
271 require.NoError(t, err, "getting storage blob config retention info")
272
273 assert.Equal(t, mode, gotMode)
274 assert.WithinDuration(t, earliestExpiry, expiry, time.Minute)
275}
276
277func TestUpdateRetentionNegativeValue(t *testing.T) {
278 ctx := testlogging.Context(t)

Callers

nothing calls this directly

Calls 14

NowFuncMethod · 0.95
ContextFunction · 0.92
NewClockTimeWithOffsetFunction · 0.92
NewVersionedMapStorageFunction · 0.92
NewMemoryBlobCacheFunction · 0.92
InitializeFunction · 0.92
NewManagerWithCacheFunction · 0.92
mustGetMutableParametersFunction · 0.85
mustGetRequiredFeaturesFunction · 0.85
SetParametersMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected