kv_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2023 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 keyedstate
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/lf-edge/ekuiper/internal/testx"
  19. )
  20. func init() {
  21. testx.InitEnv()
  22. }
  23. func TestGetKeyedState(t *testing.T) {
  24. // env set up
  25. InitKeyedStateKV()
  26. type args struct {
  27. groupName string
  28. key string
  29. value interface{}
  30. }
  31. tests := []struct {
  32. name string
  33. args args
  34. want interface{}
  35. }{
  36. {
  37. name: "string",
  38. args: args{
  39. key: "status",
  40. value: "0",
  41. },
  42. want: "0",
  43. },
  44. }
  45. for _, tt := range tests {
  46. t.Run(tt.name, func(t *testing.T) {
  47. err := SetKeyedState(tt.args.key, tt.args.value)
  48. if err != nil {
  49. t.Errorf("SetKeyedState() = %v", err)
  50. }
  51. got, err := GetKeyedState(tt.args.key)
  52. if err != nil {
  53. t.Errorf("GetKeyedState() = %v", err)
  54. } else {
  55. if !reflect.DeepEqual(got, tt.want) {
  56. t.Errorf("expect: %v, get: %v", tt.want, got)
  57. }
  58. }
  59. })
  60. }
  61. _ = ClearKeyedState()
  62. }