MCPcopy
hub / github.com/kopia/kopia / TestGetPrecedingSnapshot

Function TestGetPrecedingSnapshot

internal/diff/diff_test.go:511–531  ·  view source on GitHub ↗

Tests GetPrecedingSnapshot function - GetPrecedingSnapshot with an invalid snapshot id and expect an error; - Add a snapshot, expect an error from GetPrecedingSnapshot since there is only a single snapshot in the repo; - Subsequently add more snapshots and GetPrecedingSnapshot the immediately preced

(t *testing.T)

Source from the content-addressed store, hash-verified

509// - Subsequently add more snapshots and GetPrecedingSnapshot the immediately
510// preceding with no error.
511func TestGetPrecedingSnapshot(t *testing.T) {
512 ctx, env := repotesting.NewEnvironment(t, repotesting.FormatNotImportant)
513 manifests := getManifests(t)
514
515 _, err := diff.GetPrecedingSnapshot(ctx, env.RepositoryWriter, "non_existent_snapshot_ID")
516 require.Error(t, err, "expect error when calling GetPrecedingSnapshot with a wrong snapshotID")
517
518 initialSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["initial_snapshot"])
519 _, err = diff.GetPrecedingSnapshot(ctx, env.RepositoryWriter, string(initialSnapshotManifestID))
520 require.Error(t, err, "expect error when there is a single snapshot in the repo")
521
522 intermediateSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["intermediate_snapshot"])
523 gotManID, err := diff.GetPrecedingSnapshot(ctx, env.RepositoryWriter, string(intermediateSnapshotManifestID))
524 require.NoError(t, err)
525 require.Equal(t, initialSnapshotManifestID, gotManID.ID)
526
527 latestSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["latest_snapshot"])
528 gotManID2, err := diff.GetPrecedingSnapshot(ctx, env.RepositoryWriter, string(latestSnapshotManifestID))
529 require.NoError(t, err)
530 require.Equal(t, intermediateSnapshotManifestID, gotManID2.ID)
531}
532
533// First call GetTwoLatestSnapshots with insufficient snapshots in the repo and
534// expect an error;

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected