MCPcopy Create free account
hub / github.com/daodst/chat / TestValidateRuleNegatives

Function TestValidateRuleNegatives

internal/pushrules/validate_test.go:8–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestValidateRuleNegatives(t *testing.T) {
9 tsts := []struct {
10 Name string
11 Kind Kind
12 Rule Rule
13 WantErrString string
14 }{
15 {"emptyRuleID", OverrideKind, Rule{}, "invalid rule ID"},
16 {"invalidKind", Kind("something else"), Rule{}, "invalid rule kind"},
17 {"ruleIDBackslash", OverrideKind, Rule{RuleID: "#foo\\:example.com"}, "invalid rule ID"},
18 {"noActions", OverrideKind, Rule{}, "missing actions"},
19 {"invalidAction", OverrideKind, Rule{Actions: []*Action{{}}}, "invalid rule action kind"},
20 {"invalidCondition", OverrideKind, Rule{Conditions: []*Condition{{}}}, "invalid rule condition kind"},
21 {"overrideNoCondition", OverrideKind, Rule{}, "missing rule conditions"},
22 {"underrideNoCondition", UnderrideKind, Rule{}, "missing rule conditions"},
23 {"contentNoPattern", ContentKind, Rule{}, "missing content rule pattern"},
24 }
25 for _, tst := range tsts {
26 t.Run(tst.Name, func(t *testing.T) {
27 errs := ValidateRule(tst.Kind, &tst.Rule)
28 var foundErr error
29 for _, err := range errs {
30 t.Logf("Got error %#v", err)
31 if strings.Contains(err.Error(), tst.WantErrString) {
32 foundErr = err
33 }
34 }
35 if foundErr == nil {
36 t.Errorf("errs: got %#v, want containing %q", errs, tst.WantErrString)
37 }
38 })
39 }
40}
41
42func TestValidateRulePositives(t *testing.T) {
43 tsts := []struct {

Callers

nothing calls this directly

Calls 4

ValidateRuleFunction · 0.85
RunMethod · 0.80
KindTypeAlias · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected