Skip to content

Commit dddd5b2

Browse files
committed
evaluate equality on clone - do not sort original - fixes #84
1 parent ff8e2d6 commit dddd5b2

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ fmt:
66
tidy:
77
go mod tidy
88

9+
generate: deepcopy-gen
10+
touch ./tmp/deepcopy-gen-boilerplate.go.txt
11+
deepcopy-gen -h ./tmp/deepcopy-gen-boilerplate.go.txt -i ./pkg/types
12+
913
# Run tests
10-
test: test-ci fmt
14+
test: generate test-ci fmt
1115

1216
# Run ci tests
1317
test-ci: mocks tidy
@@ -35,6 +39,11 @@ ifeq (, $(shell which mockgen))
3539
$(shell go install github.com/golang/mock/mockgen@v1.6.0)
3640
endif
3741

42+
deepcopy-gen:
43+
ifeq (, $(shell which deepcopy-gen))
44+
$(shell go install k8s.io/code-generator/cmd/deepcopy-gen@latest)
45+
endif
46+
3847
start-replica:
3948
podman run --pull always --rm -it -p 9090:80 -p 9091:3000 adguard/adguardhome
4049

pkg/types/deepcopy_generated.go

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/types/dns.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
// DNSConfig dns config
10+
// +k8s:deepcopy-gen=true
1011
type DNSConfig struct {
1112
Upstreams []string `json:"upstream_dns,omitempty"`
1213
UpstreamsFile string `json:"upstream_dns_file"`
@@ -31,11 +32,13 @@ type DNSConfig struct {
3132

3233
// Equals dns config equal check
3334
func (c *DNSConfig) Equals(o *DNSConfig) bool {
34-
c.Sort()
35-
o.Sort()
35+
cc := c.DeepCopy()
36+
oo := o.DeepCopy()
37+
cc.Sort()
38+
oo.Sort()
3639

37-
a, _ := json.Marshal(c)
38-
b, _ := json.Marshal(o)
40+
a, _ := json.Marshal(cc)
41+
b, _ := json.Marshal(oo)
3942
return string(a) == string(b)
4043
}
4144

0 commit comments

Comments
 (0)