mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-15 13:19:56 +00:00
[client] Add unit tests for engine synchronization and Info flag copying
- Introduced tests for the Engine's handleSync method to verify behavior when SkipNetworkMapUpdate is true and when NetworkMap is nil. - Added a test for the Info struct to ensure correct copying of flag values from one instance to another, while preserving unrelated fields.
This commit is contained in:
@@ -1,13 +1,72 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
func TestInfo_CopyFlagsFrom(t *testing.T) {
|
||||
origin := &Info{}
|
||||
serverSSHAllowed := true
|
||||
origin.SetFlags(
|
||||
true, // RosenpassEnabled
|
||||
false, // RosenpassPermissive
|
||||
&serverSSHAllowed,
|
||||
true, // DisableClientRoutes
|
||||
false, // DisableServerRoutes
|
||||
true, // DisableDNS
|
||||
false, // DisableFirewall
|
||||
true, // BlockLANAccess
|
||||
false, // BlockInbound
|
||||
true, // LazyConnectionEnabled
|
||||
)
|
||||
|
||||
got := &Info{}
|
||||
got.CopyFlagsFrom(origin)
|
||||
|
||||
if got.RosenpassEnabled != true {
|
||||
t.Fatalf("RosenpassEnabled not copied: got %v", got.RosenpassEnabled)
|
||||
}
|
||||
if got.RosenpassPermissive != false {
|
||||
t.Fatalf("RosenpassPermissive not copied: got %v", got.RosenpassPermissive)
|
||||
}
|
||||
if got.ServerSSHAllowed != true {
|
||||
t.Fatalf("ServerSSHAllowed not copied: got %v", got.ServerSSHAllowed)
|
||||
}
|
||||
if got.DisableClientRoutes != true {
|
||||
t.Fatalf("DisableClientRoutes not copied: got %v", got.DisableClientRoutes)
|
||||
}
|
||||
if got.DisableServerRoutes != false {
|
||||
t.Fatalf("DisableServerRoutes not copied: got %v", got.DisableServerRoutes)
|
||||
}
|
||||
if got.DisableDNS != true {
|
||||
t.Fatalf("DisableDNS not copied: got %v", got.DisableDNS)
|
||||
}
|
||||
if got.DisableFirewall != false {
|
||||
t.Fatalf("DisableFirewall not copied: got %v", got.DisableFirewall)
|
||||
}
|
||||
if got.BlockLANAccess != true {
|
||||
t.Fatalf("BlockLANAccess not copied: got %v", got.BlockLANAccess)
|
||||
}
|
||||
if got.BlockInbound != false {
|
||||
t.Fatalf("BlockInbound not copied: got %v", got.BlockInbound)
|
||||
}
|
||||
if got.LazyConnectionEnabled != true {
|
||||
t.Fatalf("LazyConnectionEnabled not copied: got %v", got.LazyConnectionEnabled)
|
||||
}
|
||||
|
||||
// ensure CopyFlagsFrom does not touch unrelated fields
|
||||
origin.Hostname = "host-a"
|
||||
got.Hostname = "host-b"
|
||||
got.CopyFlagsFrom(origin)
|
||||
if got.Hostname != "host-b" {
|
||||
t.Fatalf("CopyFlagsFrom should not overwrite non-flag fields, got Hostname=%q", got.Hostname)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_LocalWTVersion(t *testing.T) {
|
||||
got := GetInfo(context.TODO())
|
||||
want := "development"
|
||||
|
||||
Reference in New Issue
Block a user