store_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2022-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 store
  15. import (
  16. "reflect"
  17. "testing"
  18. )
  19. func TestReg(t *testing.T) {
  20. db = &database{
  21. tables: make(map[string]*tableCount),
  22. }
  23. reg1, err := Reg("test", nil, "a")
  24. if err != nil {
  25. t.Errorf("register test error: %v", err)
  26. return
  27. }
  28. _, err2 := Reg("test", nil, "a")
  29. if err2 != nil {
  30. t.Errorf("register test error: %v", err2)
  31. return
  32. }
  33. exp := map[string]*tableCount{
  34. "test_a": {
  35. count: 2,
  36. t: reg1,
  37. },
  38. }
  39. if !reflect.DeepEqual(exp, db.tables) {
  40. t.Errorf("register expect %v, but got %v", exp, db.tables)
  41. return
  42. }
  43. Unreg("test", "a")
  44. exp = map[string]*tableCount{
  45. "test_a": {
  46. count: 1,
  47. t: reg1,
  48. },
  49. }
  50. if !reflect.DeepEqual(exp, db.tables) {
  51. t.Errorf("unregister expect %v, but got %v", exp, db.tables)
  52. return
  53. }
  54. }