refactor: remove unnecessary Copy() code

This commit is contained in:
Matthias Radestock
2017-07-04 07:18:55 +01:00
parent f0ae2bd98c
commit a6491a35c3
4 changed files with 3 additions and 44 deletions

View File

@@ -47,29 +47,3 @@ func TestNodeMetadata(t *testing.T) {
}
}
}
func TestMetadataRowCopy(t *testing.T) {
var (
row = report.MetadataRow{
ID: "id",
Value: "value",
Priority: 1,
Datatype: "datatype",
}
cp = row.Copy()
)
// copy should be identical
if !reflect.DeepEqual(row, cp) {
t.Error(test.Diff(row, cp))
}
// changing the copy should not change the original
cp.ID = ""
cp.Value = ""
cp.Priority = 2
cp.Datatype = ""
if row.ID != "id" || row.Value != "value" || row.Priority != 1 || row.Datatype != "datatype" {
t.Errorf("Expected changing the copy not to modify the original")
}
}

View File

@@ -28,11 +28,6 @@ type MetadataTemplate struct {
From string `json:"from,omitempty"` // Defines how to get the value from a report node
}
// Copy returns a value-copy of the template
func (t MetadataTemplate) Copy() MetadataTemplate {
return t
}
// MetadataRows returns the rows for a node
func (t MetadataTemplate) MetadataRows(n Node) []MetadataRow {
from := fromDefault
@@ -90,11 +85,6 @@ type MetadataRow struct {
Truncate int `json:"truncate,omitempty"`
}
// Copy returns a value copy of a metadata row.
func (m MetadataRow) Copy() MetadataRow {
return m
}
// MetadataTemplates is a mergeable set of metadata templates
type MetadataTemplates map[string]MetadataTemplate
@@ -115,7 +105,7 @@ func (e MetadataTemplates) Copy() MetadataTemplates {
}
result := MetadataTemplates{}
for k, v := range e {
result[k] = v.Copy()
result[k] = v
}
return result
}

View File

@@ -34,11 +34,6 @@ func (t MetricTemplate) MetricRows(n Node) []MetricRow {
return []MetricRow{row}
}
// Copy returns a value-copy of the metric template
func (t MetricTemplate) Copy() MetricTemplate {
return t
}
// MetricTemplates is a mergeable set of metric templates
type MetricTemplates map[string]MetricTemplate
@@ -59,7 +54,7 @@ func (e MetricTemplates) Copy() MetricTemplates {
}
result := MetricTemplates{}
for k, v := range e {
result[k] = v.Copy()
result[k] = v
}
return result
}

View File

@@ -25,6 +25,6 @@ func PruneNode(node report.Node) report.Node {
return report.MakeNode(
node.ID).
WithTopology(node.Topology).
WithAdjacent(node.Adjacency.Copy()...).
WithAdjacent(node.Adjacency...).
WithChildren(prunedChildren)
}