fix dhcp clone function #149

This commit is contained in:
bakito 2023-02-07 21:43:58 +01:00
parent 6d08d42626
commit 49f301589d
No known key found for this signature in database
GPG key ID: BCCEB081DB8A24D8
3 changed files with 63 additions and 1 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ main
.adguardhome-sync.yaml
tmp
bin
config.yaml

View file

@ -22,7 +22,7 @@ type DHCPServerConfig struct {
// Clone the config
func (c *DHCPServerConfig) Clone() *DHCPServerConfig {
clone := &DHCPServerConfig{}
_ = copier.Copy(c, clone)
_ = copier.Copy(clone, c)
return clone
}

View file

@ -2,6 +2,7 @@ package types_test
import (
"encoding/json"
"net"
"os"
"github.com/bakito/adguardhome-sync/pkg/types"
@ -360,4 +361,64 @@ var _ = Describe("Types", func() {
})
})
})
Context("DHCPServerConfig", func() {
Context("Equals", func() {
It("should be equal", func() {
dc1 := &types.DHCPServerConfig{
V4: &types.V4ServerConfJSON{
GatewayIP: net.IPv4(1, 2, 3, 4),
LeaseDuration: 123,
RangeStart: net.IPv4(1, 2, 3, 5),
RangeEnd: net.IPv4(1, 2, 3, 6),
SubnetMask: net.IPv4(255, 255, 255, 0),
},
}
dc2 := &types.DHCPServerConfig{
V4: &types.V4ServerConfJSON{
GatewayIP: net.IPv4(1, 2, 3, 4),
LeaseDuration: 123,
RangeStart: net.IPv4(1, 2, 3, 5),
RangeEnd: net.IPv4(1, 2, 3, 6),
SubnetMask: net.IPv4(255, 255, 255, 0),
},
}
Ω(dc1.Equals(dc2)).Should(BeTrue())
})
It("should not be equal", func() {
dc1 := &types.DHCPServerConfig{
V4: &types.V4ServerConfJSON{
GatewayIP: net.IPv4(1, 2, 3, 3),
LeaseDuration: 123,
RangeStart: net.IPv4(1, 2, 3, 5),
RangeEnd: net.IPv4(1, 2, 3, 6),
SubnetMask: net.IPv4(255, 255, 255, 0),
},
}
dc2 := &types.DHCPServerConfig{
V4: &types.V4ServerConfJSON{
GatewayIP: net.IPv4(1, 2, 3, 4),
LeaseDuration: 123,
RangeStart: net.IPv4(1, 2, 3, 5),
RangeEnd: net.IPv4(1, 2, 3, 6),
SubnetMask: net.IPv4(255, 255, 255, 0),
},
}
Ω(dc1.Equals(dc2)).ShouldNot(BeTrue())
})
})
Context("Clone", func() {
It("clone should be equal", func() {
dc1 := &types.DHCPServerConfig{
V4: &types.V4ServerConfJSON{
GatewayIP: net.IPv4(1, 2, 3, 4),
LeaseDuration: 123,
RangeStart: net.IPv4(1, 2, 3, 5),
RangeEnd: net.IPv4(1, 2, 3, 6),
SubnetMask: net.IPv4(255, 255, 255, 0),
},
}
Ω(dc1.Clone().Equals(dc1)).Should(BeTrue())
})
})
})
})