source_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "github.com/lf-edge/ekuiper/pkg/ast"
  19. )
  20. func TestGetSourceConf(t *testing.T) {
  21. type args struct {
  22. sourceType string
  23. options *ast.Options
  24. }
  25. tests := []struct {
  26. name string
  27. args args
  28. want map[string]interface{}
  29. }{
  30. {
  31. name: "default",
  32. args: args{
  33. sourceType: "mqtt",
  34. options: &ast.Options{
  35. CONF_KEY: "",
  36. },
  37. },
  38. want: map[string]interface{}{
  39. "qos": 1,
  40. "server": "tcp://127.0.0.1:1883",
  41. "format": "json",
  42. "key": "",
  43. },
  44. },
  45. {
  46. name: "demo_conf",
  47. args: args{
  48. sourceType: "mqtt",
  49. options: &ast.Options{
  50. CONF_KEY: "Demo_conf",
  51. },
  52. },
  53. want: map[string]interface{}{
  54. "qos": 0,
  55. "server": "tcp://10.211.55.6:1883",
  56. "format": "json",
  57. "key": "",
  58. },
  59. },
  60. }
  61. for _, tt := range tests {
  62. t.Run(tt.name, func(t *testing.T) {
  63. if got := GetSourceConf(tt.args.sourceType, tt.args.options); !reflect.DeepEqual(got, tt.want) {
  64. t.Errorf("GetSourceConf() = %v, want %v", got, tt.want)
  65. }
  66. })
  67. }
  68. }