Counters: forget the totals of objects that no longer exist
hc counters kept listing the objects of a configuration replaced since housecarld started (an import with --replace gives every object a new ID) beside the current ones. Disabled objects, built-ins and policies keep their totals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d813ce13db
commit
429c910df1
4 files changed
+61
-1
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -437,3 +438,26 @@ func TestShadowInContainer(t *testing.T) {
|
||||
t.Errorf("the shadow fallback isn't recognised: %+v %v", tb, err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPruneCounters: the totals of objects gone (an import with --replace
|
||||
// gives every object a new ID) are forgotten; built-ins, policies and
|
||||
// disabled objects keep theirs.
|
||||
func TestPruneCounters(t *testing.T) {
|
||||
base := map[string]Counter{}
|
||||
for _, m := range []string{"r1", "r2", "r3", "f4", "f4-hairpin", "f4-6", "f5-hairpin", "s6", "d7", "d8", "b-established", "p-input", "fallback-input"} {
|
||||
base[m] = Counter{Packets: 1}
|
||||
}
|
||||
st := model.NewState()
|
||||
st.Rules = []*model.Rule{{ID: 1}, {ID: 3, Disabled: true}}
|
||||
st.Forwards = []*model.PortForward{{ID: 4}}
|
||||
st.Redirects = []*model.Redirect{{ID: 8}}
|
||||
pruneCounters(base, st)
|
||||
var got []string
|
||||
for m := range base {
|
||||
got = append(got, m)
|
||||
}
|
||||
sort.Strings(got)
|
||||
if strings.Join(got, " ") != "b-established d8 f4 f4-6 f4-hairpin fallback-input p-input r1 r3" {
|
||||
t.Errorf("kept %v", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user