redis_store_config_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package conf
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func TestRedisStorageConSelectorApply(t *testing.T) {
  7. type args struct {
  8. conf *KuiperConf
  9. conSelector string
  10. }
  11. tests := []struct {
  12. name string
  13. args args
  14. wantErr bool
  15. }{
  16. {
  17. name: "pass",
  18. args: args{
  19. conf: &KuiperConf{},
  20. conSelector: "edgex.redisMsgBus",
  21. },
  22. wantErr: false,
  23. },
  24. {
  25. name: "do not support mqtt message bus type, fail",
  26. args: args{
  27. conf: &KuiperConf{},
  28. conSelector: "edgex.mqttMsgBus",
  29. },
  30. wantErr: true,
  31. },
  32. {
  33. name: "not exist connection selector",
  34. args: args{
  35. conf: &KuiperConf{},
  36. conSelector: "noexist.mqtt",
  37. },
  38. wantErr: true,
  39. },
  40. }
  41. for _, tt := range tests {
  42. t.Run(tt.name, func(t *testing.T) {
  43. if err := RedisStorageConSelectorApply(tt.args.conSelector, tt.args.conf); (err != nil) != tt.wantErr {
  44. t.Errorf("RedisStorageConSelectorApply() error = %v, wantErr %v", err, tt.wantErr)
  45. }
  46. })
  47. }
  48. }
  49. func TestRedisStorageConSelector(t *testing.T) {
  50. envs := map[string]string{
  51. "KUIPER__STORE__TYPE": "redis",
  52. "KUIPER__STORE__REDIS__CONNECTIONSELECTOR": "edgex.redisMsgBus",
  53. "CONNECTION__EDGEX__REDISMSGBUS__SERVER": "edgex-redis",
  54. "CONNECTION__EDGEX__REDISMSGBUS__OPTIONAL__PASSWORD": "password",
  55. }
  56. for key, value := range envs {
  57. err := os.Setenv(key, value)
  58. if err != nil {
  59. t.Error(err)
  60. }
  61. }
  62. InitConf()
  63. if Config.Store.Type != "redis" {
  64. t.Errorf("env variable should set it to redis")
  65. }
  66. if Config.Store.Redis.Host != "edgex-redis" {
  67. t.Errorf("env variable should set it to edgex-redis")
  68. }
  69. if Config.Store.Redis.Password != "password" {
  70. t.Errorf("env variable should set it to password")
  71. }
  72. }