Remove copying Merge() on Report

It was only used in a few places, and all of those were better off
using the Unsafe variant.
This commit is contained in:
Bryan Boreham
2020-03-06 15:03:43 +00:00
parent b07bfb294b
commit a47cf0a2aa
4 changed files with 5 additions and 13 deletions

View File

@@ -50,8 +50,8 @@ func TestCollector(t *testing.T) {
c.Add(ctx, r2, nil)
merged := report.MakeReport()
merged = merged.Merge(r1)
merged = merged.Merge(r2)
merged.UnsafeMerge(r1)
merged.UnsafeMerge(r2)
have, err = c.Report(ctx, mtime.Now())
if err != nil {
t.Error(err)

View File

@@ -222,7 +222,7 @@ func (r *Registry) Report() (report.Report, error) {
if plugin.Implements("controller") {
r.updateAndRegisterControlsInReport(&pluginReport)
}
rpt = rpt.Merge(pluginReport)
rpt.UnsafeMerge(pluginReport)
})
return rpt, nil
}

View File

@@ -10,7 +10,7 @@ import (
)
func TestReportLocalNetworks(t *testing.T) {
r := report.MakeReport().Merge(report.Report{
r := report.Report{
Host: report.Topology{
Nodes: report.Nodes{
"nonets": report.MakeNode("nonets"),
@@ -27,7 +27,7 @@ func TestReportLocalNetworks(t *testing.T) {
),
},
},
})
}.Copy()
want := report.MakeNetworks()
for _, cidr := range []string{"10.0.0.1/8", "192.168.1.1/24", "10.32.0.1/12"} {
if err := want.AddCIDR(cidr); err != nil {

View File

@@ -334,14 +334,6 @@ func (r Report) Copy() Report {
return newReport
}
// Merge merges another Report into the receiver and returns the result. The
// original is not modified.
func (r Report) Merge(other Report) Report {
newReport := r.Copy()
newReport.UnsafeMerge(other)
return newReport
}
// UnsafeMerge merges another Report into the receiver. The original is modified.
func (r *Report) UnsafeMerge(other Report) {
r.DNS = r.DNS.Merge(other.DNS)