You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

3 years ago
  1. package container
  2. import (
  3. "fmt"
  4. "reflect"
  5. "testing"
  6. )
  7. func TestInstance_GetCaller(t *testing.T) {
  8. var content = "content"
  9. instance := Instance(reflect.ValueOf(&TestServiceImplement{content}))
  10. caller, err := instance.GetCaller("String")
  11. if err != nil {
  12. t.Fatalf("意外错误:%s", err.Error())
  13. }
  14. result := caller([]reflect.Value{})
  15. if len(result) != 2 {
  16. t.Fatalf("调用器返回结果数量错误!")
  17. }
  18. if result[0].Interface() != content {
  19. t.Fatalf("调用器返回内容错误!")
  20. }
  21. }
  22. func TestInstance_GetCaller_EmptyMethodNameError(t *testing.T) {
  23. _, err := serviceInstance.GetCaller("")
  24. if err == nil {
  25. t.Fatalf("意外的没有错误!")
  26. }
  27. if err.Error() != fmt.Sprintf("方法名不能为空!") {
  28. t.Fatalf("意外错误:%s", err.Error())
  29. }
  30. }
  31. func TestInstance_GetCaller_MissingMethodError(t *testing.T) {
  32. _, err := serviceInstance.GetCaller("NoMethod")
  33. if err == nil {
  34. t.Fatalf("意外的没有错误!")
  35. }
  36. if err.Error() != fmt.Sprintf("未找到方法!") {
  37. t.Fatalf("意外错误:%s", err.Error())
  38. }
  39. }