Improve account copying (#1069)

With this fix, all nested slices and pointers will be copied by value.
Also, this fixes tests to compare the original and copy account by their
values by marshaling them to JSON strings.

Before that, they were copying the pointers that also passed the simple `=` compassion
(as the addresses match).
This commit is contained in:
Yury Gargay
2023-08-22 17:56:39 +02:00
committed by GitHub
parent 892db25021
commit e586eca16c
11 changed files with 88 additions and 30 deletions

View File

@ -1,8 +1,9 @@
package route
import (
"github.com/netbirdio/netbird/management/server/status"
"net/netip"
"github.com/netbirdio/netbird/management/server/status"
)
// Windows has some limitation regarding metric size that differ from Unix-like systems.
@ -83,7 +84,7 @@ func (r *Route) EventMeta() map[string]any {
// Copy copies a route object
func (r *Route) Copy() *Route {
return &Route{
route := &Route{
ID: r.ID,
Description: r.Description,
NetID: r.NetID,
@ -93,8 +94,10 @@ func (r *Route) Copy() *Route {
Metric: r.Metric,
Masquerade: r.Masquerade,
Enabled: r.Enabled,
Groups: r.Groups,
Groups: make([]string, len(r.Groups)),
}
copy(route.Groups, r.Groups)
return route
}
// IsEqual compares one route with the other