goherence/internal/executor/condition_test.go
2026-09-11 10:17:25 +03:00

35 lines
905 B
Go

package executor
import "testing"
func TestEvalWhen(t *testing.T) {
vars := map[string]interface{}{
"os_family": "Debian",
"clear_cache": true,
"http_port": float64(80),
}
cases := []struct {
expr string
want bool
}{
{`os_family == "Debian"`, true},
{`os_family == "RedHat"`, false},
{`os_family != "RedHat"`, true},
{`clear_cache == true`, true},
{`clear_cache == false`, false},
{`http_port == 80`, true},
{`http_port > 79`, true},
{`http_port < 79`, false},
{`os_family == "Debian" and clear_cache == true`, true},
{`os_family == "RedHat" or clear_cache == true`, true},
{`not clear_cache == false`, true},
{`(os_family == "Debian") and (http_port == 80)`, true},
{`unknown_var == "x"`, false},
}
for _, c := range cases {
got := evalWhen(c.expr, vars)
if got != c.want {
t.Errorf("evalWhen(%q) = %v, хотел %v", c.expr, got, c.want)
}
}
}