mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 10:50:45 +01:00
fix nameserver tests
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
This commit is contained in:
parent
70f1c394c1
commit
5cc07ba42a
@ -938,15 +938,23 @@ func TestValidateDomain(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNameServerAccountPeerUpdate(t *testing.T) {
|
func TestNameServerAccountPeersUpdate(t *testing.T) {
|
||||||
manager, account, peer1, _, _ := setupNetworkMapTest(t)
|
manager, account, peer1, peer2, _ := setupNetworkMapTest(t)
|
||||||
|
|
||||||
var newNameServerGroup *nbdns.NameServerGroup
|
var newNameServerGroupA *nbdns.NameServerGroup
|
||||||
|
var newNameServerGroupB *nbdns.NameServerGroup
|
||||||
|
|
||||||
err := manager.SaveGroup(context.Background(), account.Id, userID, &nbgroup.Group{
|
err := manager.SaveGroups(context.Background(), account.Id, userID, []*nbgroup.Group{
|
||||||
ID: "group-id",
|
{
|
||||||
Name: "GroupA",
|
ID: "groupA",
|
||||||
Peers: []string{},
|
Name: "GroupA",
|
||||||
|
Peers: []string{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ID: "groupB",
|
||||||
|
Name: "GroupB",
|
||||||
|
Peers: []string{peer1.ID, peer2.ID},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
@ -964,13 +972,13 @@ func TestNameServerAccountPeerUpdate(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
newNameServerGroup, err = manager.CreateNameServerGroup(
|
newNameServerGroupA, err = manager.CreateNameServerGroup(
|
||||||
context.Background(), account.Id, "ns-group-1", "ns-group-1", []nbdns.NameServer{{
|
context.Background(), account.Id, "nsGroupA", "nsGroupA", []nbdns.NameServer{{
|
||||||
IP: netip.MustParseAddr(peer1.IP.String()),
|
IP: netip.MustParseAddr("1.1.1.1"),
|
||||||
NSType: nbdns.UDPNameServerType,
|
NSType: nbdns.UDPNameServerType,
|
||||||
Port: nbdns.DefaultDNSPort,
|
Port: nbdns.DefaultDNSPort,
|
||||||
}},
|
}},
|
||||||
[]string{"group-id"},
|
[]string{"groupA"},
|
||||||
true, []string{}, true, userID, false,
|
true, []string{}, true, userID, false,
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
@ -982,8 +990,50 @@ func TestNameServerAccountPeerUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
err = manager.GroupAddPeer(context.Background(), account.Id, "group-id", peer1.ID)
|
// saving a nameserver group with a distribution group with no peers should not update account peers
|
||||||
assert.NoError(t, err)
|
// and not send peer update
|
||||||
|
t.Run("saving nameserver group with distribution group no peers", func(t *testing.T) {
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
err = manager.SaveNameServerGroup(context.Background(), account.Id, userID, newNameServerGroupA)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Error("timeout waiting for peerShouldNotReceiveUpdate")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Creating a nameserver group with a distribution group no peers should update account peers and send peer update
|
||||||
|
t.Run("creating nameserver group with distribution group has peers", func(t *testing.T) {
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
peerShouldReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
newNameServerGroupB, err = manager.CreateNameServerGroup(
|
||||||
|
context.Background(), account.Id, "nsGroupB", "nsGroupB", []nbdns.NameServer{{
|
||||||
|
IP: netip.MustParseAddr("1.1.1.1"),
|
||||||
|
NSType: nbdns.UDPNameServerType,
|
||||||
|
Port: nbdns.DefaultDNSPort,
|
||||||
|
}},
|
||||||
|
[]string{"groupB"},
|
||||||
|
true, []string{}, true, userID, false,
|
||||||
|
)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Error("timeout waiting for peerShouldNotReceiveUpdate")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// saving a nameserver group with a distribution group with peers should update account peers and send peer update
|
// saving a nameserver group with a distribution group with peers should update account peers and send peer update
|
||||||
t.Run("saving nameserver group with distribution group has peers", func(t *testing.T) {
|
t.Run("saving nameserver group with distribution group has peers", func(t *testing.T) {
|
||||||
@ -993,7 +1043,12 @@ func TestNameServerAccountPeerUpdate(t *testing.T) {
|
|||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = manager.SaveNameServerGroup(context.Background(), account.Id, userID, newNameServerGroup)
|
newNameServerGroupB.NameServers = []nbdns.NameServer{{
|
||||||
|
IP: netip.MustParseAddr("1.1.1.2"),
|
||||||
|
NSType: nbdns.UDPNameServerType,
|
||||||
|
Port: nbdns.DefaultDNSPort,
|
||||||
|
}}
|
||||||
|
err = manager.SaveNameServerGroup(context.Background(), account.Id, userID, newNameServerGroupB)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -1003,4 +1058,26 @@ func TestNameServerAccountPeerUpdate(t *testing.T) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// saving unchanged nameserver group should update account peers and not send peer update
|
||||||
|
t.Run("saving unchanged nameserver group", func(t *testing.T) {
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
peerShouldNotReceiveUpdate(t, updMsg)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
newNameServerGroupB.NameServers = []nbdns.NameServer{{
|
||||||
|
IP: netip.MustParseAddr("1.1.1.2"),
|
||||||
|
NSType: nbdns.UDPNameServerType,
|
||||||
|
Port: nbdns.DefaultDNSPort,
|
||||||
|
}}
|
||||||
|
err = manager.SaveNameServerGroup(context.Background(), account.Id, userID, newNameServerGroupB)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
t.Error("timeout waiting for peerShouldNotReceiveUpdate")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user