(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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 | |
| 42 | func TestValidateRulePositives(t *testing.T) { |
| 43 | tsts := []struct { |
nothing calls this directly
no test coverage detected