Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ func compileRuleTree(cf compiler.RuntimeI, tree *parser.TreeT) (compiler.ObjsT,

opts := []compiler.CompilerOptT{
compiler.WithRuntime(cf),
compiler.WithPlugin(schema.ScopeNode, compiler.NewDefaultPlugin()),
}

if nodeObjs, err = compiler.CompileTree(tree, schema.ScopeDefault, opts...); err != nil {
if nodeObjs, err = compiler.CompileTree(tree, schema.ScopeNode, opts...); err != nil {
return nil, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/ux/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ LOOP:
}

return StatsT{
"rules": u.Rules,
"problems": u.Problems,
"rules": int64(u.Rules),
"problems": int64(u.Problems),
"lines": u.Lines.Load(),
"bytes": u.Bytes.Value(),
}, nil
Expand Down
16 changes: 8 additions & 8 deletions internal/pkg/ux/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,31 @@ func TestUxEvalT_FinalStats(t *testing.T) {
}

// Convert map values to the correct type for comparison
rules, ok := stats["rules"].(uint32)
rules, ok := stats["rules"]
if !ok {
t.Fatal("Expected rules to be uint32")
}
if rules != 5 {
t.Errorf("Expected rules to be 5, got %d", rules)
}

problems, ok := stats["problems"].(uint32)
problems, ok := stats["problems"]
if !ok {
t.Fatal("Expected problems to be uint32")
}
if problems != 2 {
t.Errorf("Expected problems to be 2, got %d", problems)
}

lines, ok := stats["lines"].(int64)
lines, ok := stats["lines"]
if !ok {
t.Fatal("Expected lines to be int64")
}
if lines != 1000 {
t.Errorf("Expected lines to be 1000, got %d", lines)
}

bytes, ok := stats["bytes"].(int64)
bytes, ok := stats["bytes"]
if !ok {
t.Fatal("Expected bytes to be int64")
}
Expand All @@ -190,16 +190,16 @@ func TestUxEvalT_FinalStats(t *testing.T) {
t.Errorf("Expected no error, got %v", err)
}

if rules, ok := stats["rules"].(uint32); !ok || rules != 0 {
if rules, ok := stats["rules"]; !ok || rules != 0 {
t.Errorf("Expected rules to be 0, got %v", rules)
}
if problems, ok := stats["problems"].(uint32); !ok || problems != 0 {
if problems, ok := stats["problems"]; !ok || problems != 0 {
t.Errorf("Expected problems to be 0, got %v", problems)
}
if lines, ok := stats["lines"].(int64); !ok || lines != 0 {
if lines, ok := stats["lines"]; !ok || lines != 0 {
t.Errorf("Expected lines to be 0, got %v", lines)
}
if bytes, ok := stats["bytes"].(int64); !ok || bytes != 0 {
if bytes, ok := stats["bytes"]; !ok || bytes != 0 {
t.Errorf("Expected bytes to be 0, got %v", bytes)
}
})
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/ux/ux.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var (
HelpAcceptUpdates = "Accept updates to rules or new release"
)

type StatsT map[string]any
type StatsT map[string]int64

type UxFactoryI interface {
NewBytesTracker(src string) (*progress.Tracker, error)
Expand Down
18 changes: 15 additions & 3 deletions test/preq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestSuccessExamples(t *testing.T) {
var tests = map[string]struct {
rulePath string
dataPath string
negative bool
}{
"Example00": {
rulePath: "../examples/00-rules-document-example.yaml",
Expand All @@ -44,10 +45,12 @@ func TestSuccessExamples(t *testing.T) {
"Example03": {
rulePath: "../examples/03-set-negative-example.yaml",
dataPath: "../examples/03-example.log",
negative: true,
},
"Example04": {
rulePath: "../examples/04-set-1x1-example.yaml",
dataPath: "../examples/04-example.log",
negative: true,
},
"Example08": {
rulePath: "../examples/08-sequence-example-good-window.yaml",
Expand All @@ -56,6 +59,7 @@ func TestSuccessExamples(t *testing.T) {
"Example09": {
rulePath: "../examples/09-sequence-negate-example.yaml",
dataPath: "../examples/09-example.log",
negative: true,
},
"Example13": {
rulePath: "../examples/13-string-example.yaml",
Expand Down Expand Up @@ -84,6 +88,7 @@ func TestSuccessExamples(t *testing.T) {
"Example21": {
rulePath: "../examples/21-negative-example.yaml",
dataPath: "../examples/21-example.log",
negative: true,
},
"Example22": {
rulePath: "../examples/21-negative-example.yaml",
Expand Down Expand Up @@ -144,8 +149,15 @@ func TestSuccessExamples(t *testing.T) {
t.Fatalf("Error running detection: %v", err)
}

if stats["problems"] == 0 {
t.Fatalf("Expected problems, got %d", stats["problems"])
switch stats["problems"] {
case 0:
if !test.negative {
t.Fatalf("Expected problems, got %d", stats["problems"])
}
default:
if test.negative {
t.Fatalf("Expected no problems, got %d", stats["problems"])
}
}
})
}
Expand Down Expand Up @@ -232,7 +244,7 @@ func TestMissExamples(t *testing.T) {
t.Fatalf("Error running detection: %v", err)
}

if stats["problems"] != uint32(0) {
if stats["problems"] != 0 {
t.Fatalf("Expected no problems, got %d", stats["problems"])
}
})
Expand Down
Loading