|
|
package script
import ( "github.com/stretchr/testify/assert" "testing" )
func TestCondition_Check(t *testing.T) { variables := VariableSet{ "global": map[string]string{ "test": "32", }, "devices:dummy:01;dummy:02": map[string]string{ "tstxo": "tsyeym", }, "match:lucifer:tag:Soverom": map[string]string{ "mode": "daytime", "stuff": "54", }, }
table := []struct { L string R bool C Condition M string D []string }{ { "global_gte", true, Condition{"global", "test", "gte", "16", false}, "", []string{}, }, { "global_!gte", true, Condition{"global", "test", "gte", "64", true}, "", []string{}, }, { "global_eq", true, Condition{"global", "test", "eq", "32", false}, "", []string{}, }, { "match_exists", true, Condition{"devices", "tstxo", "exists", "", false}, "", []string{"dummy:01", "dummy:02"}, }, { "match_!exists", false, Condition{"devices", "tstxo", "exists", "", true}, "", []string{"dummy:01", "dummy:02"}, }, { "devices_contains", true, Condition{"match", "mode", "contains", "time", false}, "lucifer:tag:Soverom", []string{}, }, }
for _, row := range table { t.Run(row.L, func(t *testing.T) { assert.Equal(t, row.R, row.C.Check(variables, row.M, row.D)) }) } }
|