binder_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. "github.com/lf-edge/ekuiper/internal/binder"
  18. "github.com/lf-edge/ekuiper/internal/binder/mock"
  19. "testing"
  20. )
  21. func TestBinding(t *testing.T) {
  22. // Initialize binding
  23. m := mock.NewMockFactory()
  24. e := binder.FactoryEntry{
  25. Name: "mock",
  26. Factory: m,
  27. }
  28. err := Initialize([]binder.FactoryEntry{e})
  29. if err != nil {
  30. t.Error(err)
  31. return
  32. }
  33. var tests = []struct {
  34. name string
  35. isFunc bool
  36. isFuncset bool
  37. hasAgg bool
  38. isAgg bool
  39. }{
  40. {
  41. name: "mockFunc1",
  42. isFunc: true,
  43. isFuncset: true,
  44. hasAgg: false,
  45. }, {
  46. name: "mockFunc2",
  47. isFunc: true,
  48. isFuncset: true,
  49. hasAgg: false,
  50. }, {
  51. name: "count",
  52. isFunc: true,
  53. isFuncset: false,
  54. hasAgg: true,
  55. isAgg: true,
  56. }, {
  57. name: "echo",
  58. isFunc: false,
  59. isFuncset: false,
  60. hasAgg: false,
  61. }, {
  62. name: "internal",
  63. isFunc: false,
  64. isFuncset: true,
  65. hasAgg: false,
  66. }, {
  67. name: "cast",
  68. isFunc: true,
  69. isFuncset: false,
  70. hasAgg: true,
  71. isAgg: false,
  72. },
  73. }
  74. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  75. for _, tt := range tests {
  76. _, err := Function(tt.name)
  77. isFunc := err == nil
  78. if tt.isFunc != isFunc {
  79. t.Errorf("%s is function: expect %v but got %v", tt.name, tt.isFunc, isFunc)
  80. }
  81. isFuncset := HasFunctionSet(tt.name)
  82. if tt.isFuncset != isFuncset {
  83. t.Errorf("%s is function set: expect %v but got %v", tt.name, tt.isFuncset, isFuncset)
  84. }
  85. if tt.hasAgg {
  86. isAgg := IsAggFunc(tt.name)
  87. if tt.isAgg != isAgg {
  88. t.Errorf("%s is aggregate: expect %v but got %v", tt.name, tt.isAgg, isAgg)
  89. }
  90. }
  91. }
  92. }