mock_factory.go 2.9 KB

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