You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.3 KiB

  1. package script
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "testing"
  5. )
  6. func TestCondition_Check(t *testing.T) {
  7. variables := VariableSet{
  8. "global": map[string]string{
  9. "test": "32",
  10. },
  11. "devices:dummy:01;dummy:02": map[string]string{
  12. "tstxo": "tsyeym",
  13. },
  14. "match:lucifer:tag:Soverom": map[string]string{
  15. "mode": "daytime",
  16. "stuff": "54",
  17. },
  18. }
  19. table := []struct {
  20. L string
  21. R bool
  22. C Condition
  23. M string
  24. D []string
  25. }{
  26. {
  27. "global_gte", true,
  28. Condition{"global", "test", "gte", "16", false},
  29. "", []string{},
  30. },
  31. {
  32. "global_!gte", true,
  33. Condition{"global", "test", "gte", "64", true},
  34. "", []string{},
  35. },
  36. {
  37. "global_eq", true,
  38. Condition{"global", "test", "eq", "32", false},
  39. "", []string{},
  40. },
  41. {
  42. "match_exists", true,
  43. Condition{"devices", "tstxo", "exists", "", false},
  44. "", []string{"dummy:01", "dummy:02"},
  45. },
  46. {
  47. "match_!exists", false,
  48. Condition{"devices", "tstxo", "exists", "", true},
  49. "", []string{"dummy:01", "dummy:02"},
  50. },
  51. {
  52. "devices_contains", true,
  53. Condition{"match", "mode", "contains", "time", false},
  54. "lucifer:tag:Soverom", []string{},
  55. },
  56. }
  57. for _, row := range table {
  58. t.Run(row.L, func(t *testing.T) {
  59. assert.Equal(t, row.R, row.C.Check(variables, row.M, row.D))
  60. })
  61. }
  62. }