model_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright erfenjiao, 630166475@qq.com.
  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 wasm
  15. import (
  16. "fmt"
  17. "github.com/lf-edge/ekuiper/internal/plugin/wasm/runtime"
  18. "github.com/lf-edge/ekuiper/internal/testx"
  19. "reflect"
  20. "testing"
  21. )
  22. func TestValidate(t *testing.T) {
  23. var tests = []struct {
  24. p *PluginInfo
  25. err string
  26. }{
  27. { //0 true
  28. p: &PluginInfo{
  29. PluginMeta: runtime.PluginMeta{
  30. Name: "fibonacci",
  31. Version: "1.0.0",
  32. WasmEngine: "wasmedge",
  33. },
  34. Functions: []string{"fib"},
  35. },
  36. err: "",
  37. }, { // 1
  38. p: &PluginInfo{
  39. PluginMeta: runtime.PluginMeta{
  40. Name: "fibonacci",
  41. Version: "1.0.0",
  42. WasmEngine: "wasmedge",
  43. },
  44. },
  45. err: "invalid plugin, must define at lease one function",
  46. }, { // 2
  47. p: &PluginInfo{
  48. PluginMeta: runtime.PluginMeta{
  49. Name: "fibonacci",
  50. Version: "1.0.0",
  51. WasmEngine: "",
  52. },
  53. Functions: []string{"fib"},
  54. },
  55. err: "invalid WasmEngine",
  56. }, { // 3
  57. p: &PluginInfo{
  58. PluginMeta: runtime.PluginMeta{
  59. Name: "wrong",
  60. Version: "1.0.0",
  61. WasmEngine: "wasmedge",
  62. },
  63. Functions: []string{"fib"},
  64. },
  65. err: "invalid plugin, expect name 'fibonacci' but got 'wrong'",
  66. },
  67. }
  68. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  69. for i, tt := range tests {
  70. err := tt.p.Validate("fibonacci")
  71. if !reflect.DeepEqual(tt.err, testx.Errstring(err)) { //not same
  72. t.Errorf("%d error mismatch:\n\nexp=%#v\n\ngot=%#v\n\n", i, tt.err, err.Error())
  73. }
  74. fmt.Println("err: ", err)
  75. }
  76. }