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)
| 509 | // - Subsequently add more snapshots and GetPrecedingSnapshot the immediately |
| 510 | // preceding with no error. |
| 511 | func 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; |
nothing calls this directly
no test coverage detected