MCPcopy
hub / github.com/helm/helm / TestStorageRemoveLeastRecent

Function TestStorageRemoveLeastRecent

pkg/storage/storage_test.go:352–409  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

350}
351
352func TestStorageRemoveLeastRecent(t *testing.T) {
353 storage := Init(driver.NewMemory())
354
355 // Make sure that specifying this at the outset doesn't cause any bugs.
356 storage.MaxHistory = 10
357
358 const name = "angry-bird"
359
360 // setup storage with test releases
361 setup := func() {
362 // release records
363 rls0 := ReleaseTestData{Name: name, Version: 1, Status: common.StatusSuperseded}.ToRelease()
364 rls1 := ReleaseTestData{Name: name, Version: 2, Status: common.StatusSuperseded}.ToRelease()
365 rls2 := ReleaseTestData{Name: name, Version: 3, Status: common.StatusSuperseded}.ToRelease()
366 rls3 := ReleaseTestData{Name: name, Version: 4, Status: common.StatusDeployed}.ToRelease()
367
368 // create the release records in the storage
369 assertErrNil(t.Fatal, storage.Create(rls0), "Storing release 'angry-bird' (v1)")
370 assertErrNil(t.Fatal, storage.Create(rls1), "Storing release 'angry-bird' (v2)")
371 assertErrNil(t.Fatal, storage.Create(rls2), "Storing release 'angry-bird' (v3)")
372 assertErrNil(t.Fatal, storage.Create(rls3), "Storing release 'angry-bird' (v4)")
373 }
374 setup()
375
376 // Because we have not set a limit, we expect 4.
377 expect := 4
378 if hist, err := storage.History(name); err != nil {
379 t.Fatal(err)
380 } else if len(hist) != expect {
381 t.Fatalf("expected %d items in history, got %d", expect, len(hist))
382 }
383
384 storage.MaxHistory = 3
385 rls5 := ReleaseTestData{Name: name, Version: 5, Status: common.StatusDeployed}.ToRelease()
386 assertErrNil(t.Fatal, storage.Create(rls5), "Storing release 'angry-bird' (v5)")
387
388 // On inserting the 5th record, we expect two records to be pruned from history.
389 hist, err := storage.History(name)
390 assert.NoError(t, err)
391 rhist, err := releaseListToV1List(hist)
392 assert.NoError(t, err)
393 if err != nil {
394 t.Fatal(err)
395 } else if len(rhist) != storage.MaxHistory {
396 for _, item := range rhist {
397 t.Logf("%s %v", item.Name, item.Version)
398 }
399 t.Fatalf("expected %d items in history, got %d", storage.MaxHistory, len(rhist))
400 }
401
402 // We expect the existing records to be 3, 4, and 5.
403 for i, item := range rhist {
404 v := item.Version
405 if expect := i + 3; v != expect {
406 t.Errorf("Expected release %d, got %d", expect, v)
407 }
408 }
409}

Callers

nothing calls this directly

Calls 10

NewMemoryFunction · 0.92
InitFunction · 0.85
assertErrNilFunction · 0.85
setupFunction · 0.85
ToReleaseMethod · 0.80
HistoryMethod · 0.80
FatalMethod · 0.80
FatalfMethod · 0.80
releaseListToV1ListFunction · 0.70
CreateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…