model_test.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 portable
  15. import (
  16. "fmt"
  17. "reflect"
  18. "testing"
  19. "github.com/lf-edge/ekuiper/internal/plugin/portable/runtime"
  20. "github.com/lf-edge/ekuiper/internal/testx"
  21. )
  22. func TestValidate(t *testing.T) {
  23. tests := []struct {
  24. p *PluginInfo
  25. err string
  26. }{
  27. {
  28. p: &PluginInfo{
  29. PluginMeta: runtime.PluginMeta{
  30. Name: "mirror",
  31. Version: "1.0.0",
  32. Language: "go",
  33. Executable: "mirror.exe",
  34. },
  35. },
  36. err: "invalid plugin, must define at lease one source, sink or function",
  37. }, {
  38. p: &PluginInfo{
  39. PluginMeta: runtime.PluginMeta{
  40. Name: "wrr",
  41. Version: "1.0.0",
  42. Language: "go",
  43. Executable: "mirror.exe",
  44. },
  45. Sources: []string{"a", "b"},
  46. },
  47. err: "invalid plugin, expect name 'mirror' but got 'wrr'",
  48. }, {
  49. p: &PluginInfo{
  50. PluginMeta: runtime.PluginMeta{
  51. Name: "mirror",
  52. Language: "go",
  53. Executable: "mirror.exe",
  54. },
  55. Sinks: []string{"a", "b"},
  56. },
  57. err: "",
  58. }, {
  59. p: &PluginInfo{
  60. PluginMeta: runtime.PluginMeta{
  61. Name: "mirror",
  62. Version: "1.0.0",
  63. Language: "go",
  64. },
  65. Sources: []string{"a", "b"},
  66. Sinks: []string{"a", "b"},
  67. Functions: []string{"aa"},
  68. },
  69. err: "invalid plugin, missing executable",
  70. }, {
  71. p: &PluginInfo{
  72. PluginMeta: runtime.PluginMeta{
  73. Name: "mirror",
  74. Version: "1.0.0",
  75. Executable: "tt",
  76. },
  77. Sources: []string{"a", "b"},
  78. Sinks: []string{"a", "b"},
  79. Functions: []string{"aa"},
  80. },
  81. err: "invalid plugin, missing language",
  82. }, {
  83. p: &PluginInfo{
  84. PluginMeta: runtime.PluginMeta{
  85. Name: "mirror",
  86. Version: "1.0.0",
  87. Language: "c",
  88. Executable: "tt",
  89. },
  90. Sources: []string{"a", "b"},
  91. Sinks: []string{"a", "b"},
  92. Functions: []string{"aa"},
  93. },
  94. err: "invalid plugin, language 'c' is not supported",
  95. },
  96. }
  97. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  98. for i, tt := range tests {
  99. err := tt.p.Validate("mirror")
  100. if !reflect.DeepEqual(tt.err, testx.Errstring(err)) {
  101. t.Errorf("%d error mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.err, err.Error())
  102. }
  103. }
  104. }