connect_selector_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 conf
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestConSelector_ReadCfgFromYaml(t *testing.T) {
  20. type fields struct {
  21. ConnSelectorStr string
  22. Type string
  23. CfgKey string
  24. }
  25. tests := []struct {
  26. name string
  27. fields fields
  28. wantProps map[string]interface{}
  29. wantErr bool
  30. }{
  31. {
  32. name: "mqtt localConnection",
  33. fields: fields{
  34. ConnSelectorStr: "mqtt.localconnection",
  35. Type: "mqtt",
  36. CfgKey: "localConnection",
  37. },
  38. wantProps: map[string]interface{}{
  39. "username": "ekuiper",
  40. "password": "password",
  41. "server": "tcp://127.0.0.1:1883",
  42. },
  43. wantErr: false,
  44. },
  45. {
  46. name: "edgex redisMsgBus",
  47. fields: fields{
  48. ConnSelectorStr: "edgex.redismsgbus",
  49. Type: "edgex",
  50. CfgKey: "redisMsgBus",
  51. },
  52. wantProps: map[string]interface{}{
  53. "protocol": "redis",
  54. "port": 6379,
  55. "server": "127.0.0.1",
  56. "type": "redis",
  57. },
  58. wantErr: false,
  59. },
  60. }
  61. for _, tt := range tests {
  62. t.Run(tt.name, func(t *testing.T) {
  63. c := &ConSelector{
  64. ConnSelectorStr: tt.fields.ConnSelectorStr,
  65. Type: tt.fields.Type,
  66. CfgKey: tt.fields.CfgKey,
  67. }
  68. gotProps, err := c.ReadCfgFromYaml()
  69. if (err != nil) != tt.wantErr {
  70. t.Errorf("ReadCfgFromYaml() error = %v, wantErr %v", err, tt.wantErr)
  71. return
  72. }
  73. if !reflect.DeepEqual(gotProps, tt.wantProps) {
  74. t.Errorf("ReadCfgFromYaml() gotProps = %v, want %v", gotProps, tt.wantProps)
  75. }
  76. })
  77. }
  78. }