mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-02 15:16:38 +00:00
Change the logic and add moc data
This commit is contained in:
46
client/internal/lazyconn/inactivity/manager_test.go
Normal file
46
client/internal/lazyconn/inactivity/manager_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package inactivity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/netbirdio/netbird/util"
|
||||
)
|
||||
|
||||
func init() {
|
||||
_ = util.InitLog("trace", "console")
|
||||
}
|
||||
|
||||
func TestNewManager(t *testing.T) {
|
||||
for i, sc := range scenarios {
|
||||
timer := NewFakeTimer()
|
||||
newTicker = func(d time.Duration) Ticker {
|
||||
return newFakeTicker(d, timer)
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("Scenario %d", i), func(t *testing.T) {
|
||||
mock := newMockWgInterface("peer1", sc.Data, timer)
|
||||
manager := NewManager(mock)
|
||||
manager.AddPeer("peer1")
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
manager.Start(ctx)
|
||||
|
||||
var inactiveResult bool
|
||||
select {
|
||||
case <-manager.InactivePeersChan:
|
||||
inactiveResult = true
|
||||
default:
|
||||
inactiveResult = false
|
||||
}
|
||||
|
||||
if inactiveResult != sc.ExpectedInactive {
|
||||
t.Errorf("Expected inactive peers: %v, got: %v", sc.ExpectedInactive, inactiveResult)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user