mock_factory.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 mock
  15. import (
  16. "github.com/lf-edge/ekuiper/pkg/api"
  17. "github.com/lf-edge/ekuiper/pkg/errorx"
  18. "strings"
  19. )
  20. type MockFactory struct {
  21. }
  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) Sink(name string) (api.Sink, error) {
  33. if strings.HasPrefix(name, "mock") {
  34. return &mockSink{}, nil
  35. } else {
  36. return nil, errorx.NotFoundErr
  37. }
  38. }
  39. func (f *MockFactory) Function(name string) (api.Function, error) {
  40. if strings.HasPrefix(name, "mock") {
  41. return &mockFunc{}, nil
  42. } else {
  43. return nil, errorx.NotFoundErr
  44. }
  45. }
  46. func (f *MockFactory) ConvName(name string) (string, bool) {
  47. return name, true
  48. }
  49. func (f *MockFactory) HasFunctionSet(funcName string) bool {
  50. if strings.HasPrefix(funcName, "mock") {
  51. return true
  52. } else {
  53. return false
  54. }
  55. }
  56. type mockFunc struct{}
  57. func (m *mockFunc) Validate(_ []interface{}) error {
  58. return nil
  59. }
  60. func (m *mockFunc) Exec(_ []interface{}, _ api.FunctionContext) (interface{}, bool) {
  61. return nil, true
  62. }
  63. func (m *mockFunc) IsAggregate() bool {
  64. return false
  65. }
  66. type mockSource struct{}
  67. func (m *mockSource) Open(_ api.StreamContext, _ chan<- api.SourceTuple, _ chan<- error) {
  68. return
  69. }
  70. func (m *mockSource) Configure(_ string, _ map[string]interface{}) error {
  71. return nil
  72. }
  73. func (m *mockSource) Close(_ api.StreamContext) error {
  74. return nil
  75. }
  76. type mockSink struct{}
  77. func (m *mockSink) Open(_ api.StreamContext) error {
  78. return nil
  79. }
  80. func (m *mockSink) Configure(_ map[string]interface{}) error {
  81. return nil
  82. }
  83. func (m *mockSink) Collect(_ api.StreamContext, _ interface{}) error {
  84. return nil
  85. }
  86. func (m *mockSink) Close(_ api.StreamContext) error {
  87. return nil
  88. }