MCPcopy
hub / github.com/kopia/kopia / TestGetTwoLatestSnapshots

Function TestGetTwoLatestSnapshots

internal/diff/diff_test.go:537–576  ·  view source on GitHub ↗

First call GetTwoLatestSnapshots with insufficient snapshots in the repo and expect an error; As snapshots are added, GetTwoLatestSnapshots is expected to return the manifests for the two most recent snapshots for a the given source.

(t *testing.T)

Source from the content-addressed store, hash-verified

535// As snapshots are added, GetTwoLatestSnapshots is expected to return the
536// manifests for the two most recent snapshots for a the given source.
537func TestGetTwoLatestSnapshots(t *testing.T) {
538 ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant)
539
540 snapshotSrc := getSnapshotSource()
541 manifests := getManifests(t)
542
543 _, _, err := diff.GetTwoLatestSnapshotsForASource(ctx, env.RepositoryWriter, snapshotSrc)
544 require.Error(t, err, "expected error as there aren't enough snapshots to get the two most recent snapshots")
545
546 initialSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["initial_snapshot"])
547 _, _, err = diff.GetTwoLatestSnapshotsForASource(ctx, env.RepositoryWriter, snapshotSrc)
548 require.Error(t, err, "expected error as there aren't enough snapshots to get the two most recent snapshots")
549
550 intermediateSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["intermediate_snapshot"])
551
552 var expectedManifestIDs []manifest.ID
553
554 expectedManifestIDs = append(expectedManifestIDs, initialSnapshotManifestID, intermediateSnapshotManifestID)
555
556 secondLastSnapshot, lastSnapshot, err := diff.GetTwoLatestSnapshotsForASource(ctx, env.RepositoryWriter, snapshotSrc)
557
558 var gotManifestIDs []manifest.ID
559
560 gotManifestIDs = append(gotManifestIDs, secondLastSnapshot.ID, lastSnapshot.ID)
561
562 require.NoError(t, err)
563 require.Equal(t, expectedManifestIDs, gotManifestIDs)
564
565 latestSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["latest_snapshot"])
566
567 expectedManifestIDs = nil
568 expectedManifestIDs = append(expectedManifestIDs, intermediateSnapshotManifestID, latestSnapshotManifestID)
569
570 gotManifestIDs = nil
571 secondLastSnapshot, lastSnapshot, err = diff.GetTwoLatestSnapshotsForASource(ctx, env.RepositoryWriter, snapshotSrc)
572 gotManifestIDs = append(gotManifestIDs, secondLastSnapshot.ID, lastSnapshot.ID)
573
574 require.NoError(t, err)
575 require.Equal(t, expectedManifestIDs, gotManifestIDs)
576}
577
578func mustSaveSnapshot(t *testing.T, rep repo.RepositoryWriter, man *snapshot.Manifest) manifest.ID {
579 t.Helper()

Callers

nothing calls this directly

Calls 7

NewEnvironmentFunction · 0.92
getSnapshotSourceFunction · 0.85
getManifestsFunction · 0.85
EqualMethod · 0.80
mustSaveSnapshotFunction · 0.70
ErrorMethod · 0.65

Tested by

no test coverage detected