mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-04 22:10:56 +01:00
765aba2c1c
propagate context from all the API calls and log request ID, account ID and peer ID --------- Co-authored-by: Zoltan Papp <zoltan.pmail@gmail.com>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
|
)
|
|
|
|
func TestNewSQLiteStore(t *testing.T) {
|
|
dataDir := t.TempDir()
|
|
key, _ := GenerateKey()
|
|
store, err := NewSQLiteStore(context.Background(), dataDir, key)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
defer store.Close(context.Background()) //nolint
|
|
|
|
accountID := "account_1"
|
|
|
|
for i := 0; i < 10; i++ {
|
|
_, err = store.Save(context.Background(), &activity.Event{
|
|
Timestamp: time.Now().UTC(),
|
|
Activity: activity.PeerAddedByUser,
|
|
InitiatorID: "user_" + fmt.Sprint(i),
|
|
TargetID: "peer_" + fmt.Sprint(i),
|
|
AccountID: accountID,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
}
|
|
|
|
result, err := store.Get(context.Background(), accountID, 0, 10, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
|
|
assert.Len(t, result, 10)
|
|
assert.True(t, result[0].Timestamp.Before(result[len(result)-1].Timestamp))
|
|
|
|
result, err = store.Get(context.Background(), accountID, 0, 5, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
return
|
|
}
|
|
|
|
assert.Len(t, result, 5)
|
|
assert.True(t, result[0].Timestamp.After(result[len(result)-1].Timestamp))
|
|
}
|