binder_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 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. isSink bool
  36. }{
  37. {
  38. name: "unknown",
  39. isSource: false,
  40. isSink: false,
  41. }, {
  42. name: "mqtt",
  43. isSource: true,
  44. isSink: true,
  45. }, {
  46. name: "mock1",
  47. isSource: true,
  48. isSink: true,
  49. }, {
  50. name: "rest",
  51. isSource: false,
  52. isSink: true,
  53. },
  54. }
  55. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  56. for _, tt := range tests {
  57. _, err := Source(tt.name)
  58. isSource := err == nil
  59. if tt.isSource != isSource {
  60. t.Errorf("%s is source: expect %v but got %v", tt.name, tt.isSource, isSource)
  61. }
  62. _, err = Sink(tt.name)
  63. isSink := err == nil
  64. if tt.isSink != isSink {
  65. t.Errorf("%s is sink: expect %v but got %v", tt.name, tt.isSink, isSink)
  66. }
  67. }
  68. }