echo_func_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 main
  15. import (
  16. "testing"
  17. "github.com/lf-edge/ekuiper/sdk/go/mock"
  18. )
  19. func TestValidate(t *testing.T) {
  20. f := &echo{}
  21. var args []interface{}
  22. err := f.Validate(args)
  23. if err != nil {
  24. exp := "echo function only supports 1 parameter but got 0"
  25. if err.Error() != exp {
  26. t.Errorf("expect error %s but got %s", exp, err.Error())
  27. }
  28. return
  29. }
  30. t.Errorf("should have validation error")
  31. }
  32. func TestExec(t *testing.T) {
  33. tests := []mock.FuncTest{
  34. {
  35. Args: []interface{}{"abc"},
  36. Result: "abc",
  37. Ok: true,
  38. }, {
  39. Args: []interface{}{1234},
  40. Result: 1234,
  41. Ok: true,
  42. }, {
  43. Args: []interface{}{[]string{"abc"}},
  44. Result: []string{"abc"},
  45. Ok: true,
  46. },
  47. }
  48. f := &echo{}
  49. mock.TestFuncExec(f, tests, t)
  50. }