feat(filter): add basic json parsing test case
arcad/edge/pipeline/head This commit looks good Details

This commit is contained in:
wpetit 2023-10-11 11:43:17 +02:00
parent 8a5a1cd482
commit 4d064de164
2 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package filter
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/pkg/errors"
)
func TestFilterFromJSON(t *testing.T) {
files, err := filepath.Glob("testdata/json/*.json")
if err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
for _, f := range files {
testName := filepath.Base(f)
t.Run(testName, func(t *testing.T) {
data, err := os.ReadFile(f)
if err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
var rawFilter map[string]any
if err := json.Unmarshal(data, &rawFilter); err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
if _, err := NewFrom(rawFilter); err != nil {
t.Fatalf("%+v", errors.WithStack(err))
}
})
}
}

View File

@ -0,0 +1,52 @@
{
"and": [
{
"and": [
{
"gt": {
"dateEnd": "2023-10-11T09:07:02.598Z"
}
},
{
"lt": {
"dateStart": "2023-10-11T09:07:02.598Z"
}
},
{
"eq": {
"enabled": true
}
}
]
},
{
"or": [
{
"eq": {
"_id": "01GV0WXF6BADGWGNWVDVXPP8WF"
}
},
{
"eq": {
"_id": "01HAVB47GM41XK2XRW1M2T3216"
}
},
{
"eq": {
"_id": "01GV0WXF6BADGWGNWVDVXPP8WF"
}
},
{
"eq": {
"_id": "01HAVB47GM41XK2XRW1M2T3216"
}
},
{
"eq": {
"_id": "01HC1X2K5F726F8FWZFB1WCAM4"
}
}
]
}
]
}