schema_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2022 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 schema
  15. import (
  16. "errors"
  17. "fmt"
  18. "reflect"
  19. "testing"
  20. )
  21. func TestSchemaInfo(t *testing.T) {
  22. tests := []struct {
  23. i *Info
  24. err error
  25. }{
  26. {
  27. i: &Info{
  28. Type: "static",
  29. Name: "aa",
  30. Content: "bb",
  31. SoPath: "dd",
  32. },
  33. err: errors.New("unsupported type: static"),
  34. },
  35. {
  36. i: &Info{
  37. Type: "static",
  38. Name: "aa",
  39. Content: "bb",
  40. FilePath: "cc",
  41. SoPath: "dd",
  42. },
  43. err: errors.New("cannot specify both content and file"),
  44. },
  45. {
  46. i: &Info{
  47. Type: "protobuf",
  48. FilePath: "cc",
  49. SoPath: "dd",
  50. },
  51. err: errors.New("name is required"),
  52. },
  53. {
  54. i: &Info{
  55. Type: "protobuf",
  56. Name: "aa",
  57. SoPath: "dd",
  58. },
  59. err: errors.New("must specify content or file"),
  60. },
  61. {
  62. i: &Info{
  63. Type: "protobuf",
  64. Name: "aa",
  65. Content: "bb",
  66. SoPath: "dd",
  67. },
  68. err: nil,
  69. },
  70. {
  71. i: &Info{
  72. Type: "protobuf",
  73. Name: "aa",
  74. Content: "bb",
  75. },
  76. err: nil,
  77. },
  78. {
  79. i: &Info{
  80. Type: "custom",
  81. Name: "aa",
  82. SoPath: "bb",
  83. },
  84. err: nil,
  85. },
  86. {
  87. i: &Info{
  88. Type: "custom",
  89. Name: "aa",
  90. Content: "bb",
  91. },
  92. err: errors.New("soFile is required"),
  93. },
  94. }
  95. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  96. for i, tt := range tests {
  97. err := tt.i.Validate()
  98. if !reflect.DeepEqual(err, tt.err) {
  99. t.Errorf("%d failed,\n expect: %v, \nbut got: %v", i, tt.err, err)
  100. }
  101. }
  102. }