mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-23 00:23:36 +01:00
9e8725618e
- dupword checks for duplicate words in the source code - durationcheck checks for two durations multiplied together - forbidigo forbids identifiers - mirror reports wrong mirror patterns of bytes/strings usage - misspell finds commonly misspelled English words in comments - predeclared finds code that shadows one of Go's predeclared identifiers - thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
|
)
|
|
|
|
func generateAndStoreEvents(t *testing.T, manager *DefaultAccountManager, typ activity.Activity, initiatorID, targetID,
|
|
accountID string, count int) {
|
|
t.Helper()
|
|
for i := 0; i < count; i++ {
|
|
_, err := manager.eventStore.Save(&activity.Event{
|
|
Timestamp: time.Now().UTC(),
|
|
Activity: typ,
|
|
InitiatorID: initiatorID,
|
|
TargetID: targetID,
|
|
AccountID: accountID,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDefaultAccountManager_GetEvents(t *testing.T) {
|
|
manager, err := createManager(t)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
accountID := "accountID"
|
|
|
|
t.Run("get empty events list", func(t *testing.T) {
|
|
events, err := manager.GetEvents(accountID, userID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
assert.Len(t, events, 0)
|
|
_ = manager.eventStore.Close() //nolint
|
|
})
|
|
|
|
t.Run("get events", func(t *testing.T) {
|
|
generateAndStoreEvents(t, manager, activity.PeerAddedByUser, userID, "peer", accountID, 10)
|
|
events, err := manager.GetEvents(accountID, userID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
assert.Len(t, events, 10)
|
|
_ = manager.eventStore.Close() //nolint
|
|
})
|
|
|
|
t.Run("get events without duplicates", func(t *testing.T) {
|
|
generateAndStoreEvents(t, manager, activity.UserJoined, userID, "", accountID, 10)
|
|
events, err := manager.GetEvents(accountID, userID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
assert.Len(t, events, 1)
|
|
_ = manager.eventStore.Close() //nolint
|
|
})
|
|
}
|