refactor checkpt

This commit is contained in:
JackDoan committed 2026-09-29 18:41:01 -05:00
1 parent 317388e37d
commit 84a26846f4
2 files changed
+8 -8

No files matched your search

+2 -2
View File
@@ -53,7 +53,7 @@ func addRulesFromConfig(l *slog.Logger, inbound bool, c *config.C, ra ruleAdder)
}
for i, t := range rs {
r, err := convertRule(l, t, table, i)
r, err := yamlToConfigRule(l, t, table, i)
if err != nil {
return fmt.Errorf("%s rule #%v; %s", table, i, err)
}
@@ -157,7 +157,7 @@ type configRule struct {
CASha string
}
func convertRule(l *slog.Logger, p any, table string, i int) (configRule, error) {
func yamlToConfigRule(l *slog.Logger, p any, table string, i int) (configRule, error) {
r := configRule{}
m, ok := p.(map[string]any)
+6 -6
View File
@@ -302,7 +302,7 @@ func Test_convertRule(t *testing.T) {
"group": []any{"group1"},
}
r, err := convertRule(l, c, "test", 1)
r, err := yamlToConfigRule(l, c, "test", 1)
assert.Contains(t, ob.String(), "group was an array with a single value, converting to simple value")
assert.Contains(t, ob.String(), "table=test")
assert.Contains(t, ob.String(), "rule=1")
@@ -315,7 +315,7 @@ func Test_convertRule(t *testing.T) {
"group": []any{"group1", "group2"},
}
r, err = convertRule(l, c, "test", 1)
r, err = yamlToConfigRule(l, c, "test", 1)
assert.Empty(t, ob.String())
require.Error(t, err, "group should contain a single value, an array with more than one entry was provided")
@@ -325,7 +325,7 @@ func Test_convertRule(t *testing.T) {
"group": "group1",
}
r, err = convertRule(l, c, "test", 1)
r, err = yamlToConfigRule(l, c, "test", 1)
require.NoError(t, err)
assert.Equal(t, []string{"group1"}, r.Groups)
}
@@ -345,7 +345,7 @@ func Test_convertRuleSanity(t *testing.T) {
{"groups": []any{"group2"}, "cidr": "1.1.1.1/1", "host": "bob"},
}
for _, c := range noWarningPlease {
r, err := convertRule(l, c, "test", 1)
r, err := yamlToConfigRule(l, c, "test", 1)
require.NoError(t, err)
require.NoError(t, r.sanity(), "should not generate a sanity warning, %+v", c)
}
@@ -361,7 +361,7 @@ func Test_convertRuleSanity(t *testing.T) {
}
for _, c := range yesWarningPlease {
c["host"] = "any"
r, err := convertRule(l, c, "test", 1)
r, err := yamlToConfigRule(l, c, "test", 1)
require.NoError(t, err)
err = r.sanity()
require.Error(t, err, "I wanted a warning: %+v", c)
@@ -377,7 +377,7 @@ func Test_convertRuleSanity(t *testing.T) {
{"groups": []any{"group2"}, "cidr": "1.1.1.1/1", "host": "bob"},
}
for _, c := range yesWarningPlease {
r, err := convertRule(l, c, "test", 1)
r, err := yamlToConfigRule(l, c, "test", 1)
require.NoError(t, err)
r.Groups = append(r.Groups, "any")
err = r.sanity()