services_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package apiv1
  2. import (
  3. "testing"
  4. )
  5. func TestType_String(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. t Type
  9. want string
  10. }{
  11. {"default", "", "softcas"},
  12. {"SoftCAS", SoftCAS, "softcas"},
  13. {"CloudCAS", CloudCAS, "cloudcas"},
  14. {"UnknownCAS", "UnknownCAS", "unknowncas"},
  15. }
  16. for _, tt := range tests {
  17. t.Run(tt.name, func(t *testing.T) {
  18. if got := tt.t.String(); got != tt.want {
  19. t.Errorf("Type.String() = %v, want %v", got, tt.want)
  20. }
  21. })
  22. }
  23. }
  24. func TestNotImplementedError_Error(t *testing.T) {
  25. type fields struct {
  26. Message string
  27. }
  28. tests := []struct {
  29. name string
  30. fields fields
  31. want string
  32. }{
  33. {"default", fields{""}, "not implemented"},
  34. {"with message", fields{"method not supported"}, "method not supported"},
  35. }
  36. for _, tt := range tests {
  37. t.Run(tt.name, func(t *testing.T) {
  38. e := NotImplementedError{
  39. Message: tt.fields.Message,
  40. }
  41. if got := e.Error(); got != tt.want {
  42. t.Errorf("NotImplementedError.Error() = %v, want %v", got, tt.want)
  43. }
  44. })
  45. }
  46. }
  47. func TestNotImplementedError_StatusCode(t *testing.T) {
  48. type fields struct {
  49. Message string
  50. }
  51. tests := []struct {
  52. name string
  53. fields fields
  54. want int
  55. }{
  56. {"default", fields{""}, 501},
  57. {"with message", fields{"method not supported"}, 501},
  58. }
  59. for _, tt := range tests {
  60. t.Run(tt.name, func(t *testing.T) {
  61. s := NotImplementedError{
  62. Message: tt.fields.Message,
  63. }
  64. if got := s.StatusCode(); got != tt.want {
  65. t.Errorf("NotImplementedError.StatusCode() = %v, want %v", got, tt.want)
  66. }
  67. })
  68. }
  69. }
  70. func TestValidationError_Error(t *testing.T) {
  71. type fields struct {
  72. Message string
  73. }
  74. tests := []struct {
  75. name string
  76. fields fields
  77. want string
  78. }{
  79. {"default", fields{""}, "bad request"},
  80. {"with message", fields{"token is empty"}, "token is empty"},
  81. }
  82. for _, tt := range tests {
  83. t.Run(tt.name, func(t *testing.T) {
  84. e := ValidationError{
  85. Message: tt.fields.Message,
  86. }
  87. if got := e.Error(); got != tt.want {
  88. t.Errorf("ValidationError.Error() = %v, want %v", got, tt.want)
  89. }
  90. })
  91. }
  92. }
  93. func TestValidationError_StatusCode(t *testing.T) {
  94. type fields struct {
  95. Message string
  96. }
  97. tests := []struct {
  98. name string
  99. fields fields
  100. want int
  101. }{
  102. {"default", fields{""}, 400},
  103. {"with message", fields{"token is empty"}, 400},
  104. }
  105. for _, tt := range tests {
  106. t.Run(tt.name, func(t *testing.T) {
  107. e := ValidationError{
  108. Message: tt.fields.Message,
  109. }
  110. if got := e.StatusCode(); got != tt.want {
  111. t.Errorf("ValidationError.StatusCode() = %v, want %v", got, tt.want)
  112. }
  113. })
  114. }
  115. }