Add JSON input support (#74)

* added basic json input support
* add coverage to make test
* enhanced unit tests, switch to testify/assert
* reduce ci runs
This commit is contained in:
T.v.Dein
2025-10-01 20:48:49 +02:00
committed by GitHub
parent 5f3f7c417c
commit 06a5d74fb6
18 changed files with 328 additions and 113 deletions

View File

@@ -19,9 +19,9 @@ package lib
import (
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tlinden/tablizer/cfg"
)
@@ -56,13 +56,11 @@ func TestMatchPattern(t *testing.T) {
}
err := conf.PreparePattern(inputdata.patterns)
if err != nil {
t.Errorf("PreparePattern returned error: %s", err)
}
if !matchPattern(conf, inputdata.line) {
t.Errorf("matchPattern() did not match\nExp: true\nGot: false\n")
}
assert.NoError(t, err)
res := matchPattern(conf, inputdata.line)
assert.EqualValues(t, true, res)
})
}
}
@@ -163,14 +161,12 @@ func TestFilterByFields(t *testing.T) {
conf := cfg.Config{Rawfilters: inputdata.filter, InvertMatch: inputdata.invert}
err := conf.PrepareFilters()
if err != nil {
t.Errorf("PrepareFilters returned error: %s", err)
}
assert.NoError(t, err)
data, _, _ := FilterByFields(conf, &data)
if !reflect.DeepEqual(*data, inputdata.expect) {
t.Errorf("Filtered data does not match expected data:\ngot: %+v\nexp: %+v", data, inputdata.expect)
}
assert.EqualValues(t, inputdata.expect, *data)
})
}
}