From 4e2cf9c63a9c8ca3195b2285d666a32d95b31c9c Mon Sep 17 00:00:00 2001
From: bcmmbaga <bethuelmbaga12@gmail.com>
Date: Fri, 6 Sep 2024 12:15:13 +0300
Subject: [PATCH] fix tests

Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
---
 management/server/account_test.go | 12 +++++++++++-
 management/server/dns_test.go     | 13 ++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/management/server/account_test.go b/management/server/account_test.go
index 73b490b4e..d89ce4e4a 100644
--- a/management/server/account_test.go
+++ b/management/server/account_test.go
@@ -1185,7 +1185,17 @@ func TestAccountManager_NetworkUpdates_DeletePolicy(t *testing.T) {
 }
 
 func TestAccountManager_NetworkUpdates_SavePolicy(t *testing.T) {
-	manager, account, peer1, _, _ := setupNetworkMapTest(t)
+	manager, account, peer1, peer2, _ := setupNetworkMapTest(t)
+
+	group := group.Group{
+		ID:    "group-id",
+		Name:  "GroupA",
+		Peers: []string{peer1.ID, peer2.ID},
+	}
+	if err := manager.SaveGroup(context.Background(), account.Id, userID, &group); err != nil {
+		t.Errorf("save group: %v", err)
+		return
+	}
 
 	updMsg := manager.peersUpdateManager.CreateChannel(context.Background(), peer1.ID)
 	defer manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID)
diff --git a/management/server/dns_test.go b/management/server/dns_test.go
index c06ee1679..53ab1eaaf 100644
--- a/management/server/dns_test.go
+++ b/management/server/dns_test.go
@@ -485,7 +485,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) {
 	err := manager.SaveGroup(context.Background(), account.Id, userID, &group.Group{
 		ID:    "group-id",
 		Name:  "GroupA",
-		Peers: []string{peer1.ID, peer2.ID, peer3.ID},
+		Peers: []string{},
 	})
 	assert.NoError(t, err)
 
@@ -494,7 +494,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) {
 		manager.peersUpdateManager.CloseChannel(context.Background(), peer1.ID)
 	})
 
-	// Saving DNS settings with unused groups should not update account peers and not send peer update
+	// Saving DNS settings with groups that have no peers should not trigger updates to account peers or send peer updates
 	t.Run("saving dns setting with unused groups", func(t *testing.T) {
 		done := make(chan struct{})
 		go func() {
@@ -514,6 +514,13 @@ func TestDNSAccountPeerUpdate(t *testing.T) {
 		}
 	})
 
+	err = manager.SaveGroup(context.Background(), account.Id, userID, &group.Group{
+		ID:    "group-id",
+		Name:  "GroupA",
+		Peers: []string{peer1.ID, peer2.ID, peer3.ID},
+	})
+	assert.NoError(t, err)
+
 	_, err = manager.CreateNameServerGroup(
 		context.Background(), account.Id, "ns-group-1", "ns-group-1", []dns.NameServer{{
 			IP:     netip.MustParseAddr(peer1.IP.String()),
@@ -525,7 +532,7 @@ func TestDNSAccountPeerUpdate(t *testing.T) {
 	)
 	assert.NoError(t, err)
 
-	// Saving DNS settings with used groups should update account peers and send peer update
+	// Saving DNS settings with groups that have peers should update account peers and send peer update
 	t.Run("saving dns setting with used groups", func(t *testing.T) {
 		done := make(chan struct{})
 		go func() {