mock_factory.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright 2021-2023 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 mock
  15. import (
  16. "strings"
  17. "github.com/lf-edge/ekuiper/internal/plugin"
  18. "github.com/lf-edge/ekuiper/pkg/api"
  19. "github.com/lf-edge/ekuiper/pkg/errorx"
  20. )
  21. type MockFactory struct{}
  22. func NewMockFactory() *MockFactory {
  23. return &MockFactory{}
  24. }
  25. func (f *MockFactory) Source(name string) (api.Source, error) {
  26. if strings.HasPrefix(name, "mock") {
  27. return &mockSource{}, nil
  28. } else {
  29. return nil, errorx.NotFoundErr
  30. }
  31. }
  32. func (f *MockFactory) SourcePluginInfo(_ string) (plugin.EXTENSION_TYPE, string, string) {
  33. return plugin.INTERNAL, "", ""
  34. }
  35. func (f *MockFactory) LookupSource(name string) (api.LookupSource, error) {
  36. return nil, nil
  37. }
  38. func (f *MockFactory) Sink(name string) (api.Sink, error) {
  39. if strings.HasPrefix(name, "mock") {
  40. return &mockSink{}, nil
  41. } else {
  42. return nil, errorx.NotFoundErr
  43. }
  44. }
  45. func (f *MockFactory) SinkPluginInfo(_ string) (plugin.EXTENSION_TYPE, string, string) {
  46. return plugin.INTERNAL, "", ""
  47. }
  48. func (f *MockFactory) Function(name string) (api.Function, error) {
  49. if strings.HasPrefix(name, "mock") {
  50. return &mockFunc{}, nil
  51. } else {
  52. return nil, errorx.NotFoundErr
  53. }
  54. }
  55. func (f *MockFactory) ConvName(name string) (string, bool) {
  56. return name, true
  57. }
  58. func (f *MockFactory) HasFunctionSet(funcName string) bool {
  59. if strings.HasPrefix(funcName, "mock") {
  60. return true
  61. } else {
  62. return false
  63. }
  64. }
  65. func (f *MockFactory) FunctionPluginInfo(funcName string) (plugin.EXTENSION_TYPE, string, string) {
  66. return plugin.NONE_EXTENSION, "", ""
  67. }
  68. type mockFunc struct{}
  69. func (m *mockFunc) Validate(_ []interface{}) error {
  70. return nil
  71. }
  72. func (m *mockFunc) Exec(_ []interface{}, _ api.FunctionContext) (interface{}, bool) {
  73. return nil, true
  74. }
  75. func (m *mockFunc) IsAggregate() bool {
  76. return false
  77. }
  78. type mockSource struct{}
  79. func (m *mockSource) Open(_ api.StreamContext, _ chan<- api.SourceTuple, _ chan<- error) {
  80. return
  81. }
  82. func (m *mockSource) Configure(_ string, _ map[string]interface{}) error {
  83. return nil
  84. }
  85. func (m *mockSource) Close(_ api.StreamContext) error {
  86. return nil
  87. }
  88. type mockSink struct{}
  89. func (m *mockSink) Open(_ api.StreamContext) error {
  90. return nil
  91. }
  92. func (m *mockSink) Configure(_ map[string]interface{}) error {
  93. return nil
  94. }
  95. func (m *mockSink) Collect(_ api.StreamContext, _ interface{}) error {
  96. return nil
  97. }
  98. func (m *mockSink) Close(_ api.StreamContext) error {
  99. return nil
  100. }