context_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package cli
  2. import (
  3. "reflect"
  4. "sync"
  5. "testing"
  6. )
  7. func TestContext_Bind(t *testing.T) {
  8. type fields struct {
  9. ID int32
  10. CmdStr string
  11. Args []string
  12. locker sync.RWMutex
  13. Values map[string]interface{}
  14. response *Response
  15. }
  16. type args struct {
  17. i interface{}
  18. }
  19. tests := []struct {
  20. name string
  21. fields fields
  22. args args
  23. wantErr bool
  24. }{
  25. // TODO: Add test cases.
  26. }
  27. for _, tt := range tests {
  28. t.Run(tt.name, func(t *testing.T) {
  29. ctx := &Context{
  30. ID: tt.fields.ID,
  31. CmdStr: tt.fields.CmdStr,
  32. Args: tt.fields.Args,
  33. locker: tt.fields.locker,
  34. Values: tt.fields.Values,
  35. response: tt.fields.response,
  36. }
  37. if err := ctx.Bind(tt.args.i); (err != nil) != tt.wantErr {
  38. t.Errorf("Bind() error = %v, wantErr %v", err, tt.wantErr)
  39. }
  40. })
  41. }
  42. }
  43. func TestContext_Error(t *testing.T) {
  44. type fields struct {
  45. ID int32
  46. CmdStr string
  47. Args []string
  48. locker sync.RWMutex
  49. Values map[string]interface{}
  50. response *Response
  51. }
  52. type args struct {
  53. code int
  54. msg string
  55. }
  56. tests := []struct {
  57. name string
  58. fields fields
  59. args args
  60. wantErr bool
  61. }{
  62. // TODO: Add test cases.
  63. }
  64. for _, tt := range tests {
  65. t.Run(tt.name, func(t *testing.T) {
  66. ctx := &Context{
  67. ID: tt.fields.ID,
  68. CmdStr: tt.fields.CmdStr,
  69. Args: tt.fields.Args,
  70. locker: tt.fields.locker,
  71. Values: tt.fields.Values,
  72. response: tt.fields.response,
  73. }
  74. if err := ctx.Error(tt.args.code, tt.args.msg); (err != nil) != tt.wantErr {
  75. t.Errorf("Error() error = %v, wantErr %v", err, tt.wantErr)
  76. }
  77. })
  78. }
  79. }
  80. func TestContext_Success(t *testing.T) {
  81. type fields struct {
  82. ID int32
  83. CmdStr string
  84. Args []string
  85. locker sync.RWMutex
  86. Values map[string]interface{}
  87. response *Response
  88. }
  89. type args struct {
  90. i interface{}
  91. }
  92. tests := []struct {
  93. name string
  94. fields fields
  95. args args
  96. wantErr bool
  97. }{
  98. // TODO: Add test cases.
  99. }
  100. for _, tt := range tests {
  101. t.Run(tt.name, func(t *testing.T) {
  102. ctx := &Context{
  103. ID: tt.fields.ID,
  104. CmdStr: tt.fields.CmdStr,
  105. Args: tt.fields.Args,
  106. locker: tt.fields.locker,
  107. Values: tt.fields.Values,
  108. response: tt.fields.response,
  109. }
  110. if err := ctx.Success(tt.args.i); (err != nil) != tt.wantErr {
  111. t.Errorf("Success() error = %v, wantErr %v", err, tt.wantErr)
  112. }
  113. })
  114. }
  115. }
  116. func TestRef(t *testing.T) {
  117. type x struct {
  118. A string
  119. }
  120. refVal := reflect.Indirect(reflect.ValueOf(&x{A: "xxx"}))
  121. t.Log(refVal.Field(0).Kind())
  122. t.Log(refVal.Type().Field(0).Name)
  123. }