binder_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 io
  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 TestBindings(t *testing.T) {
  22. m := mock.NewMockFactory()
  23. e := binder.FactoryEntry{
  24. Name: "mock",
  25. Factory: m,
  26. }
  27. err := Initialize([]binder.FactoryEntry{e})
  28. if err != nil {
  29. t.Error(err)
  30. return
  31. }
  32. var tests = []struct {
  33. name string
  34. isSource bool
  35. isLookupSource bool
  36. isSink bool
  37. }{
  38. {
  39. name: "unknown",
  40. isSource: false,
  41. isLookupSource: false,
  42. isSink: false,
  43. }, {
  44. name: "mqtt",
  45. isSource: true,
  46. isLookupSource: false,
  47. isSink: true,
  48. }, {
  49. name: "mock1",
  50. isSource: true,
  51. isLookupSource: false,
  52. isSink: true,
  53. }, {
  54. name: "rest",
  55. isSource: false,
  56. isLookupSource: false,
  57. isSink: true,
  58. }, {
  59. name: "redis",
  60. isSource: false,
  61. isLookupSource: true,
  62. isSink: true,
  63. },
  64. }
  65. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  66. for _, tt := range tests {
  67. _, err := Source(tt.name)
  68. isSource := err == nil
  69. if tt.isSource != isSource {
  70. t.Errorf("%s is source: expect %v but got %v", tt.name, tt.isSource, isSource)
  71. }
  72. _, err = LookupSource(tt.name)
  73. if tt.isLookupSource != (err == nil) {
  74. t.Errorf("%s is lookup source: expect %v but got %v", tt.name, tt.isLookupSource, err == nil)
  75. }
  76. _, err = Sink(tt.name)
  77. isSink := err == nil
  78. if tt.isSink != isSink {
  79. t.Errorf("%s is sink: expect %v but got %v", tt.name, tt.isSink, isSink)
  80. }
  81. }
  82. }