filer_grpc_server_traverse_meta_test.go 762 B

12345678910111213141516171819202122232425262728293031
  1. package weed_server
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "github.com/viant/ptrie"
  5. "testing"
  6. )
  7. func TestPtrie(t *testing.T) {
  8. b := []byte("/topics/abc/dev")
  9. excludedTrie := ptrie.New[bool]()
  10. excludedTrie.Put([]byte("/topics/abc/d"), true)
  11. excludedTrie.Put([]byte("/topics/abc"), true)
  12. assert.True(t, excludedTrie.MatchPrefix(b, func(key []byte, value bool) bool {
  13. println("matched1", string(key))
  14. return true
  15. }))
  16. assert.True(t, excludedTrie.MatchAll(b, func(key []byte, value bool) bool {
  17. println("matched2", string(key))
  18. return true
  19. }))
  20. assert.False(t, excludedTrie.MatchAll([]byte("/topics/ab"), func(key []byte, value bool) bool {
  21. println("matched3", string(key))
  22. return true
  23. }))
  24. assert.False(t, excludedTrie.Has(b))
  25. }