Skip to content

Commit

Permalink
chore: Update wrong case for rules
Browse files Browse the repository at this point in the history
Signed-off-by: Timon Wong <[email protected]>
  • Loading branch information
timonwong committed Aug 29, 2022
1 parent f799a59 commit 20319dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
15 changes: 13 additions & 2 deletions flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ func TestIgnoredLoggerFlag(t *testing.T) {
assert.ErrorContains(t, err, "-ignoredloggers: unknown logger: \"unknownlogger\"")
}

func TestNoRuleFile(t *testing.T) {
f := ruleFileFlag{}

fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.SetOutput(io.Discard)
fs.Var(&f, "rulefile", "")

err := fs.Parse([]string{"-rulefile=testdata/xxx-not-exists-xxx.txt"})
assert.ErrorContains(t, err, "open testdata/xxx-not-exists-xxx.txt: no such file or directory")
}

func TestWrongRuleFile(t *testing.T) {
f := ruleFileFlag{}

fs := flag.NewFlagSet("test", flag.ContinueOnError)
fs.SetOutput(io.Discard)
fs.Var(&f, "rulefile", "")

err := fs.Parse([]string{"-rulefile=testdata/xxx-not-exists-xxx.yaml"})
assert.ErrorContains(t, err, "open testdata/xxx-not-exists-xxx.yaml: no such file or directory")
err := fs.Parse([]string{"-rulefile=testdata/wrong-rules.txt"})
assert.ErrorContains(t, err, "error parse rule at line 2: invalid rule format")
}
2 changes: 1 addition & 1 deletion rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/timonwong/loggercheck/internal/bytebufferpool"
)

var ErrInvalidRule = errors.New("invalid rule")
var ErrInvalidRule = errors.New("invalid rule format")

type RulesetList []Ruleset

Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions testdata/wrong-rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Wrong rule file
(*a/wrong.Method.Rule

0 comments on commit 20319dc

Please sign in to comment.