github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/proto/dispatch/v1/02_resolvermeta_test.go (about) 1 package dispatchv1 2 3 import ( 4 "testing" 5 6 "github.com/bits-and-blooms/bloom/v3" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestRecordTraversal(t *testing.T) { 11 var rm *ResolverMeta 12 _, err := rm.RecordTraversal("test") 13 require.ErrorContains(t, err, "missing") 14 15 rm = &ResolverMeta{} 16 _, err = rm.RecordTraversal("test") 17 require.ErrorContains(t, err, "missing") 18 19 rm = &ResolverMeta{TraversalBloom: []byte("")} 20 _, err = rm.RecordTraversal("test") 21 require.ErrorContains(t, err, "missing") 22 23 rm = &ResolverMeta{TraversalBloom: []byte("foo")} 24 _, err = rm.RecordTraversal("test") 25 require.ErrorContains(t, err, "unmarshall") 26 27 bf, err := NewTraversalBloomFilter(100) 28 require.NoError(t, err) 29 rm.TraversalBloom = bf 30 possiblyLoop, err := rm.RecordTraversal("test") 31 require.False(t, possiblyLoop) 32 require.NoError(t, err) 33 34 bfs := bloom.BloomFilter{} 35 err = bfs.UnmarshalBinary(rm.TraversalBloom) 36 require.NoError(t, err) 37 require.True(t, bfs.TestString("test")) 38 39 possiblyLoop, err = rm.RecordTraversal("test") 40 require.True(t, possiblyLoop) 41 require.NoError(t, err) 42 }