@@ -45,3 +45,53 @@ func TestDatabaseEnsuresBeginsBeforeExpires(t *testing.T) {
4545 })
4646 require .Error (t , err )
4747}
48+
49+ func TestCheckpointRestoreISA (t * testing.T ) {
50+ ctx := context .Background ()
51+ repo := setUpStore (t )
52+
53+ _ , err := repo .InsertISA (ctx , serviceArea )
54+ require .NoError (t , err )
55+
56+ cp := repo .Checkpoint ()
57+
58+ // Mutate after the checkpoint.
59+ isa , err := repo .GetISA (ctx , serviceArea .ID , false )
60+ require .NoError (t , err )
61+ _ , err = repo .DeleteISA (ctx , isa )
62+ require .NoError (t , err )
63+ gone , err := repo .GetISA (ctx , serviceArea .ID , false )
64+ require .NoError (t , err )
65+ require .Nil (t , gone )
66+
67+ // Restore brings it back.
68+ require .NoError (t , repo .Restore (cp ))
69+ back , err := repo .GetISA (ctx , serviceArea .ID , false )
70+ require .NoError (t , err )
71+ require .NotNil (t , back )
72+ }
73+
74+ func TestCheckpointIsolatesNotificationIndex (t * testing.T ) {
75+ ctx := context .Background ()
76+ repo := setUpStore (t )
77+
78+ sub , err := repo .InsertSubscription (ctx , subscriptionsPool [0 ].input )
79+ require .NoError (t , err )
80+
81+ cp := repo .Checkpoint ()
82+
83+ // In-place notification-index bump must not leak into the checkpoint.
84+ updated , err := repo .UpdateNotificationIdxsInCells (ctx , sub .Cells )
85+ require .NoError (t , err )
86+ require .Len (t , updated , 1 )
87+ require .Equal (t , sub .NotificationIndex + 1 , updated [0 ].NotificationIndex )
88+
89+ require .NoError (t , repo .Restore (cp ))
90+ restored , err := repo .GetSubscription (ctx , sub .ID )
91+ require .NoError (t , err )
92+ require .Equal (t , sub .NotificationIndex , restored .NotificationIndex )
93+ }
94+
95+ func TestRestoreInvalidType (t * testing.T ) {
96+ require .Error (t , setUpStore (t ).Restore ("not a checkpoint" ))
97+ }
0 commit comments