@@ -11,10 +11,13 @@ import (
1111)
1212
1313var (
14+ testTime1 = time .Unix (32100 , 0 )
15+ testTime2 = time .Unix (12300 , 0 )
16+
1417 sessionID1 = intToSessionID (1 )
1518 sessionID2 = intToSessionID (2 )
1619
17- action1 = & Action {
20+ action1Req = & AddActionReq {
1821 SessionID : sessionID1 ,
1922 ActorName : "Autopilot" ,
2023 FeatureName : "auto-fees" ,
@@ -23,29 +26,37 @@ var (
2326 StructuredJsonData : "{\" something\" :\" nothing\" }" ,
2427 RPCMethod : "UpdateChanPolicy" ,
2528 RPCParamsJson : []byte ("new fee" ),
26- AttemptedAt : time .Unix (32100 , 0 ),
27- State : ActionStateDone ,
2829 }
2930
30- action2 = & Action {
31+ action1 = & Action {
32+ AddActionReq : * action1Req ,
33+ AttemptedAt : testTime1 ,
34+ State : ActionStateDone ,
35+ }
36+
37+ action2Req = & AddActionReq {
3138 SessionID : sessionID2 ,
3239 ActorName : "Autopilot" ,
3340 FeatureName : "rebalancer" ,
3441 Trigger : "channels not balanced" ,
3542 Intent : "balance" ,
3643 RPCMethod : "SendToRoute" ,
3744 RPCParamsJson : []byte ("hops, amount" ),
38- AttemptedAt : time .Unix (12300 , 0 ),
39- State : ActionStateInit ,
45+ }
46+
47+ action2 = & Action {
48+ AddActionReq : * action2Req ,
49+ AttemptedAt : testTime2 ,
50+ State : ActionStateInit ,
4051 }
4152)
4253
4354// TestActionStorage tests that the ActionsListDB CRUD logic.
4455func TestActionStorage (t * testing.T ) {
45- tmpDir := t .TempDir ()
4656 ctx := context .Background ()
57+ clock := clock .NewTestClock (testTime1 )
4758
48- db , err := NewBoltDB (tmpDir , "test.db" , nil , clock . NewDefaultClock () )
59+ db , err := NewBoltDB (t . TempDir () , "test.db" , nil , clock )
4960 require .NoError (t , err )
5061 t .Cleanup (func () {
5162 _ = db .Close ()
@@ -67,10 +78,14 @@ func TestActionStorage(t *testing.T) {
6778 require .NoError (t , err )
6879 require .Len (t , actions , 0 )
6980
70- _ , err = db .AddAction (ctx , action1 )
81+ locator1 , err : = db .AddAction (ctx , action1Req )
7182 require .NoError (t , err )
83+ err = db .SetActionState (ctx , locator1 , ActionStateDone , "" )
84+ require .NoError (t , err )
85+
86+ clock .SetTime (testTime2 )
7287
73- locator2 , err := db .AddAction (ctx , action2 )
88+ locator2 , err := db .AddAction (ctx , action2Req )
7489 require .NoError (t , err )
7590
7691 actions , _ , _ , err = db .ListActions (
@@ -103,7 +118,7 @@ func TestActionStorage(t *testing.T) {
103118 action2 .State = ActionStateDone
104119 assertEqualActions (t , action2 , actions [0 ])
105120
106- _ , err = db .AddAction (ctx , action1 )
121+ _ , err = db .AddAction (ctx , action1Req )
107122 require .NoError (t , err )
108123
109124 // Check that providing no session id and no filter function returns
@@ -154,7 +169,8 @@ func TestListActions(t *testing.T) {
154169 actionIds := 0
155170 addAction := func (sessionID [4 ]byte ) {
156171 actionIds ++
157- action := & Action {
172+
173+ actionReq := & AddActionReq {
158174 SessionID : sessionID ,
159175 ActorName : "Autopilot" ,
160176 FeatureName : fmt .Sprintf ("%d" , actionIds ),
@@ -163,11 +179,9 @@ func TestListActions(t *testing.T) {
163179 StructuredJsonData : "{\" something\" :\" nothing\" }" ,
164180 RPCMethod : "UpdateChanPolicy" ,
165181 RPCParamsJson : []byte ("new fee" ),
166- AttemptedAt : time .Unix (32100 , 0 ),
167- State : ActionStateDone ,
168182 }
169183
170- _ , err := db .AddAction (ctx , action )
184+ _ , err := db .AddAction (ctx , actionReq )
171185 require .NoError (t , err )
172186 }
173187
@@ -358,7 +372,7 @@ func TestListGroupActions(t *testing.T) {
358372 require .Empty (t , al )
359373
360374 // Add an action under session 1.
361- _ , err = db .AddAction (ctx , action1 )
375+ _ , err = db .AddAction (ctx , action1Req )
362376 require .NoError (t , err )
363377
364378 // There should now be one action in the group.
@@ -368,7 +382,7 @@ func TestListGroupActions(t *testing.T) {
368382 require .Equal (t , sessionID1 , al [0 ].SessionID )
369383
370384 // Add an action under session 2.
371- _ , err = db .AddAction (ctx , action2 )
385+ _ , err = db .AddAction (ctx , action2Req )
372386 require .NoError (t , err )
373387
374388 // There should now be actions in the group.
0 commit comments