(t *testing.T)
| 221 | } |
| 222 | |
| 223 | func 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 | |
| 277 | func TestUpdateRetentionNegativeValue(t *testing.T) { |
| 278 | ctx := testlogging.Context(t) |
nothing calls this directly
no test coverage detected