Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 58 additions & 18 deletions firewalldb/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,23 @@ import (
var (
testTime1 = time.Unix(32100, 0)
testTime2 = time.Unix(12300, 0)
)

// TestActionStorage tests that the ActionsListDB CRUD logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the nice diffs 👍

func TestActionStorage(t *testing.T) {
t.Parallel()

sessionID1 = intToSessionID(1)
sessionID2 = intToSessionID(2)
ctx := context.Background()
clock := clock.NewTestClock(testTime1)

action1Req = &AddActionReq{
db, err := NewBoltDB(t.TempDir(), "test.db", nil, clock)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
})

sessionID1 := intToSessionID(1)
action1Req := &AddActionReq{
SessionID: fn.Some(sessionID1),
MacaroonIdentifier: sessionID1,
ActorName: "Autopilot",
Expand All @@ -30,13 +42,14 @@ var (
RPCParamsJson: []byte("new fee"),
}

action1 = &Action{
action1 := &Action{
AddActionReq: *action1Req,
AttemptedAt: testTime1,
State: ActionStateDone,
}

action2Req = &AddActionReq{
sessionID2 := intToSessionID(2)
action2Req := &AddActionReq{
SessionID: fn.Some(sessionID2),
MacaroonIdentifier: sessionID2,
ActorName: "Autopilot",
Expand All @@ -47,23 +60,11 @@ var (
RPCParamsJson: []byte("hops, amount"),
}

action2 = &Action{
action2 := &Action{
AddActionReq: *action2Req,
AttemptedAt: testTime2,
State: ActionStateInit,
}
)

// TestActionStorage tests that the ActionsListDB CRUD logic.
func TestActionStorage(t *testing.T) {
ctx := context.Background()
clock := clock.NewTestClock(testTime1)

db, err := NewBoltDB(t.TempDir(), "test.db", nil, clock)
require.NoError(t, err)
t.Cleanup(func() {
_ = db.Close()
})

actions, _, _, err := db.ListActions(
ctx, nil,
Expand Down Expand Up @@ -157,6 +158,8 @@ func TestActionStorage(t *testing.T) {
// TestListActions tests some ListAction options.
// TODO(elle): cover more test cases here.
func TestListActions(t *testing.T) {
t.Parallel()

tmpDir := t.TempDir()
ctx := context.Background()

Expand Down Expand Up @@ -357,6 +360,43 @@ func TestListGroupActions(t *testing.T) {

group1 := intToSessionID(0)

sessionID1 := intToSessionID(1)
action1Req := &AddActionReq{
SessionID: fn.Some(sessionID1),
MacaroonIdentifier: sessionID1,
ActorName: "Autopilot",
FeatureName: "auto-fees",
Trigger: "fee too low",
Intent: "increase fee",
StructuredJsonData: "{\"something\":\"nothing\"}",
RPCMethod: "UpdateChanPolicy",
RPCParamsJson: []byte("new fee"),
}

action1 := &Action{
AddActionReq: *action1Req,
AttemptedAt: testTime1,
State: ActionStateDone,
}

sessionID2 := intToSessionID(2)
action2Req := &AddActionReq{
SessionID: fn.Some(sessionID2),
MacaroonIdentifier: sessionID2,
ActorName: "Autopilot",
FeatureName: "rebalancer",
Trigger: "channels not balanced",
Intent: "balance",
RPCMethod: "SendToRoute",
RPCParamsJson: []byte("hops, amount"),
}

action2 := &Action{
AddActionReq: *action2Req,
AttemptedAt: testTime2,
State: ActionStateInit,
}

// Link session 1 and session 2 to group 1.
index := NewMockSessionDB()
index.AddPair(sessionID1, group1)
Expand Down
Loading