From 49f301589d234e4cbff01b5230723e3f04023886 Mon Sep 17 00:00:00 2001 From: bakito Date: Tue, 7 Feb 2023 21:43:58 +0100 Subject: [PATCH] fix dhcp clone function #149 --- .gitignore | 1 + pkg/types/dhcp.go | 2 +- pkg/types/types_test.go | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 5922a79..47e5d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ main .adguardhome-sync.yaml tmp bin +config.yaml diff --git a/pkg/types/dhcp.go b/pkg/types/dhcp.go index ab6df4f..a2860b7 100644 --- a/pkg/types/dhcp.go +++ b/pkg/types/dhcp.go @@ -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 } diff --git a/pkg/types/types_test.go b/pkg/types/types_test.go index 293aeb4..71b08ce 100644 --- a/pkg/types/types_test.go +++ b/pkg/types/types_test.go @@ -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()) + }) + }) + }) })