added echo filter for testing purposes

This commit is contained in:
BroodjeAap 2022-12-19 21:04:36 +00:00
parent 01f3393968
commit d12f40fb36
2 changed files with 34 additions and 0 deletions

View file

@ -76,6 +76,11 @@ func processFilters(filters []Filter, web *Web, watch *Watch, debug bool, schedu
getCronDebugResult(filter)
continue
}
if filter.Type == "echo" {
getFilterResultEcho(filter)
processedMap[filter.ID] = true
continue
}
if len(filter.Parents) == 0 && !debug {
continue
}
@ -221,6 +226,10 @@ func getFilterResult(filters []Filter, filter *Filter, watch *Watch, web *Web, d
}
}
}
case filter.Type == "echo":
{
getFilterResultEcho(filter)
}
default:
filter.log("getFilterResult called with filter.Type == '", filter.Type, "'")
}
@ -895,3 +904,8 @@ func getFilterResultLua(filter *Filter) {
},
)
}
func getFilterResultEcho(filter *Filter) {
log.Println(filter.Var1)
filter.Results = append(filter.Results, filter.Var1)
}

View file

@ -1235,3 +1235,23 @@ func TestFilterLuaLogs(t *testing.T) {
t.Errorf("Unexpected log message: '%s'", filter.Logs[0])
}
}
func TestEchoFilter(t *testing.T) {
helloWorld := "Hello World!"
filters := []Filter{
{
ID: 0,
Name: "Echo",
Type: "echo",
Var1: helloWorld,
},
}
filter1 := &filters[0]
connections := []FilterConnection{}
buildFilterTree(filters, connections)
processFilters(filters, nil, nil, false, nil)
if !reflect.DeepEqual(filter1.Results, []string{helloWorld}) {
t.Errorf("%s did not match %s", helloWorld, filter1.Results)
}
}