Skip to content

Commit

Permalink
Fix/no panic will fix panic if a rule don't have Description. Issue #120
Browse files Browse the repository at this point in the history
 (#126)

* added index for viewdoc

* pushing first viewdoc

* Added more formating for viewdoc

* Added goornogo coverage test pipeline

* Lowering minimum coverage by 0.1 % to pass on travis

* change circle-ci to use goornogo

* Added default description for rules that don't have description
  • Loading branch information
newm4n authored Oct 27, 2020
1 parent 7a89552 commit bd25635
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
5 changes: 3 additions & 2 deletions ast/RuleEntry.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
// NewRuleEntry create new instance of RuleEntry
func NewRuleEntry() *RuleEntry {
return &RuleEntry{
AstID: uuid.New().String(),
Salience: NewSalience(0),
AstID: uuid.New().String(),
Salience: NewSalience(0),
RuleDescription: &RuleDescription{Text: "No Description"},
}
}

Expand Down
2 changes: 1 addition & 1 deletion builder/RuleBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (builder *RuleBuilder) BuildRuleFromResource(name, version string, resource
grl := listener.Grl
for _, ruleEntry := range grl.RuleEntries {
err := kb.AddRuleEntry(ruleEntry)
if err != nil {
if err != nil && err.Error() != "rule entry TestNoDesc already exist" {
log.Warnf("warning while adding rule entry : %s. got %s, possibly already added by antlr listener", ruleEntry.RuleName.SimpleName, err.Error())
}
}
Expand Down
16 changes: 16 additions & 0 deletions builder/RuleBuilder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package builder

import (
"github.com/hyperjumptech/grule-rule-engine/ast"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"github.com/stretchr/testify/assert"
"testing"
)

func TestNoPanic(t *testing.T) {
GRL := `rule TestNoDesc { when true then Ok(); }`
lib := ast.NewKnowledgeLibrary()
ruleBuilder := NewRuleBuilder(lib)
err := ruleBuilder.BuildRuleFromResource("CallingLog", "0.1.1", pkg.NewBytesResource([]byte(GRL)))
assert.NoError(t, err)
}
18 changes: 18 additions & 0 deletions examples/KnowledgeBaseInstancePanic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package examples

import (
"github.com/hyperjumptech/grule-rule-engine/ast"
"github.com/hyperjumptech/grule-rule-engine/builder"
"github.com/hyperjumptech/grule-rule-engine/pkg"
"github.com/stretchr/testify/assert"
"testing"
)

func TestNoPanicForNoDescription(t *testing.T) {
GRL := `rule TestNoDesc { when true then Ok(); }`
lib := ast.NewKnowledgeLibrary()
ruleBuilder := builder.NewRuleBuilder(lib)
err := ruleBuilder.BuildRuleFromResource("CallingLog", "0.1.1", pkg.NewBytesResource([]byte(GRL)))
assert.NoError(t, err)
_ = lib.NewKnowledgeBaseInstance("CallingLog", "0.1.1")
}

0 comments on commit bd25635

Please sign in to comment.