function_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package function
  15. import (
  16. "fmt"
  17. "testing"
  18. )
  19. func TestManager(t *testing.T) {
  20. tests := []struct {
  21. name string
  22. found bool
  23. }{
  24. {
  25. name: "sum",
  26. found: true,
  27. }, {
  28. name: "agg",
  29. found: false,
  30. }, {
  31. name: "ln",
  32. found: true,
  33. }, {
  34. name: "regexp_matches",
  35. found: true,
  36. }, {
  37. name: "encode",
  38. found: true,
  39. }, {
  40. name: "json_path_query",
  41. found: true,
  42. }, {
  43. name: "window_start",
  44. found: true,
  45. }, {
  46. name: "cardinality",
  47. found: true,
  48. },
  49. }
  50. m := GetManager()
  51. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  52. for _, tt := range tests {
  53. f, _ := m.Function(tt.name)
  54. found := f != nil
  55. if tt.found != found {
  56. t.Errorf("%s result mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", tt.name, tt.found, found)
  57. }
  58. }
  59. h := m.HasFunctionSet("internal")
  60. if !h {
  61. t.Errorf("can't find function set internal")
  62. }
  63. h = m.HasFunctionSet("other")
  64. if h {
  65. t.Errorf("find undefined function set other")
  66. }
  67. }