mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
refactor: remove report latest map Delete()
It wasn't used, and is problematic in any case since it introduces non-monotonicity.
This commit is contained in:
@@ -125,14 +125,6 @@ function generate_latest_map() {
|
||||
return ${latest_map_type}{m.Map.Set(key, &${entry_type}{Timestamp: timestamp, Value: value})}
|
||||
}
|
||||
|
||||
// Delete the value for the given key.
|
||||
func (m ${latest_map_type}) Delete(key string) ${latest_map_type} {
|
||||
if m.Map == nil {
|
||||
return m
|
||||
}
|
||||
return ${latest_map_type}{m.Map.Delete(key)}
|
||||
}
|
||||
|
||||
// ForEach executes fn on each key value pair in the map.
|
||||
func (m ${latest_map_type}) ForEach(fn func(k string, timestamp time.Time, v ${data_type})) {
|
||||
if m.Map != nil {
|
||||
|
||||
@@ -92,11 +92,13 @@ func TestContainer(t *testing.T) {
|
||||
|
||||
test.Poll(t, 100*time.Millisecond, want, func() interface{} {
|
||||
node := c.GetNode()
|
||||
node.Latest.ForEach(func(k string, _ time.Time, v string) {
|
||||
if v == "0" || v == "" {
|
||||
node.Latest = node.Latest.Delete(k)
|
||||
latest := report.MakeStringLatestMap()
|
||||
node.Latest.ForEach(func(k string, t time.Time, v string) {
|
||||
if v != "0" && v != "" {
|
||||
latest = latest.Set(k, t, v)
|
||||
}
|
||||
})
|
||||
node.Latest = latest
|
||||
return node
|
||||
})
|
||||
}
|
||||
|
||||
@@ -92,14 +92,6 @@ func (m StringLatestMap) Set(key string, timestamp time.Time, value string) Stri
|
||||
return StringLatestMap{m.Map.Set(key, &stringLatestEntry{Timestamp: timestamp, Value: value})}
|
||||
}
|
||||
|
||||
// Delete the value for the given key.
|
||||
func (m StringLatestMap) Delete(key string) StringLatestMap {
|
||||
if m.Map == nil {
|
||||
return m
|
||||
}
|
||||
return StringLatestMap{m.Map.Delete(key)}
|
||||
}
|
||||
|
||||
// ForEach executes fn on each key value pair in the map.
|
||||
func (m StringLatestMap) ForEach(fn func(k string, timestamp time.Time, v string)) {
|
||||
if m.Map != nil {
|
||||
@@ -231,14 +223,6 @@ func (m NodeControlDataLatestMap) Set(key string, timestamp time.Time, value Nod
|
||||
return NodeControlDataLatestMap{m.Map.Set(key, &nodeControlDataLatestEntry{Timestamp: timestamp, Value: value})}
|
||||
}
|
||||
|
||||
// Delete the value for the given key.
|
||||
func (m NodeControlDataLatestMap) Delete(key string) NodeControlDataLatestMap {
|
||||
if m.Map == nil {
|
||||
return m
|
||||
}
|
||||
return NodeControlDataLatestMap{m.Map.Delete(key)}
|
||||
}
|
||||
|
||||
// ForEach executes fn on each key value pair in the map.
|
||||
func (m NodeControlDataLatestMap) ForEach(fn func(k string, timestamp time.Time, v NodeControlData)) {
|
||||
if m.Map != nil {
|
||||
|
||||
@@ -70,25 +70,6 @@ func TestLatestMapDeepEquals(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLatestMapDelete(t *testing.T) {
|
||||
now := time.Now()
|
||||
want := MakeStringLatestMap()
|
||||
have := MakeStringLatestMap().
|
||||
Set("foo", now, "Baz").
|
||||
Delete("foo")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func TestLatestMapDeleteNil(t *testing.T) {
|
||||
want := StringLatestMap{}
|
||||
have := StringLatestMap{}.Delete("foo")
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf(test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
|
||||
func nilStringLatestMap() StringLatestMap {
|
||||
m := MakeStringLatestMap()
|
||||
m.Map = nil
|
||||
|
||||
Reference in New Issue
Block a user