MCPcopy
hub / github.com/dgraph-io/dgraph / TestDataKey

Function TestDataKey

x/keys_test.go:27–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25}
26
27func TestDataKey(t *testing.T) {
28 var uid uint64
29
30 // key with uid = 0 is invalid
31 uid = 0
32 key := DataKey(AttrInRootNamespace("bad uid"), uid)
33 _, err := Parse(key)
34 require.Error(t, err)
35
36 for uid = 1; uid < 1001; uid++ {
37 // Use the uid to derive the attribute so it has variable length and the test
38 // can verify that multiple sizes of attr work correctly.
39 sattr := fmt.Sprintf("attr:%d", uid)
40 key := DataKey(AttrInRootNamespace(sattr), uid)
41 pk, err := Parse(key)
42 require.NoError(t, err)
43
44 require.True(t, pk.IsData())
45 require.Equal(t, sattr, ParseAttr(pk.Attr))
46 require.Equal(t, uid, pk.Uid)
47 require.Equal(t, uint64(0), pk.StartUid)
48 }
49
50 keys := make([]string, 0, 1024)
51 for uid = 1024; uid >= 1; uid-- {
52 key := DataKey(AttrInRootNamespace("testing.key"), uid)
53 keys = append(keys, string(key))
54 }
55 // Test that sorting is as expected.
56 sort.Strings(keys)
57 require.True(t, sort.StringsAreSorted(keys))
58 for i, key := range keys {
59 exp := DataKey(AttrInRootNamespace("testing.key"), uint64(i+1))
60 require.Equal(t, string(exp), key)
61 }
62}
63
64func TestParseDataKeyWithStartUid(t *testing.T) {
65 var uid uint64

Callers

nothing calls this directly

Calls 6

AttrInRootNamespaceFunction · 0.85
ParseAttrFunction · 0.85
IsDataMethod · 0.80
DataKeyFunction · 0.70
ParseFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected