schema_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. var 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. i: &Info{
  36. Type: "static",
  37. Name: "aa",
  38. Content: "bb",
  39. FilePath: "cc",
  40. SoPath: "dd",
  41. },
  42. err: errors.New("cannot specify both content and file"),
  43. },
  44. {
  45. i: &Info{
  46. Type: "protobuf",
  47. FilePath: "cc",
  48. SoPath: "dd",
  49. },
  50. err: errors.New("name is required"),
  51. }, {
  52. i: &Info{
  53. Type: "protobuf",
  54. Name: "aa",
  55. SoPath: "dd",
  56. },
  57. err: errors.New("must specify content or file"),
  58. }, {
  59. i: &Info{
  60. Type: "protobuf",
  61. Name: "aa",
  62. Content: "bb",
  63. SoPath: "dd",
  64. },
  65. err: nil,
  66. }, {
  67. i: &Info{
  68. Type: "protobuf",
  69. Name: "aa",
  70. Content: "bb",
  71. },
  72. err: nil,
  73. }, {
  74. i: &Info{
  75. Type: "custom",
  76. Name: "aa",
  77. SoPath: "bb",
  78. },
  79. err: nil,
  80. }, {
  81. i: &Info{
  82. Type: "custom",
  83. Name: "aa",
  84. Content: "bb",
  85. },
  86. err: errors.New("soFile is required"),
  87. },
  88. }
  89. fmt.Printf("The test bucket size is %d.\n\n", len(tests))
  90. for i, tt := range tests {
  91. err := tt.i.Validate()
  92. if !reflect.DeepEqual(err, tt.err) {
  93. t.Errorf("%d failed,\n expect: %v, \nbut got: %v", i, tt.err, err)
  94. }
  95. }
  96. }