MCPcopy Create free account
hub / github.com/golang/appengine / TestKeyEncoding

Function TestKeyEncoding

datastore/key_test.go:17–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestKeyEncoding(t *testing.T) {
18 testCases := []struct {
19 desc string
20 key *Key
21 exp string
22 }{
23 {
24 desc: "A simple key with an int ID",
25 key: &Key{
26 kind: "Person",
27 intID: 1,
28 appID: "glibrary",
29 },
30 exp: "aghnbGlicmFyeXIMCxIGUGVyc29uGAEM",
31 },
32 {
33 desc: "A simple key with a string ID",
34 key: &Key{
35 kind: "Graph",
36 stringID: "graph:7-day-active",
37 appID: "glibrary",
38 },
39 exp: "aghnbGlicmFyeXIdCxIFR3JhcGgiEmdyYXBoOjctZGF5LWFjdGl2ZQw",
40 },
41 {
42 desc: "A key with a parent",
43 key: &Key{
44 kind: "WordIndex",
45 intID: 1033,
46 parent: &Key{
47 kind: "WordIndex",
48 intID: 1020032,
49 appID: "glibrary",
50 },
51 appID: "glibrary",
52 },
53 exp: "aghnbGlicmFyeXIhCxIJV29yZEluZGV4GIChPgwLEglXb3JkSW5kZXgYiQgM",
54 },
55 }
56 for _, tc := range testCases {
57 enc := tc.key.Encode()
58 if enc != tc.exp {
59 t.Errorf("%s: got %q, want %q", tc.desc, enc, tc.exp)
60 }
61
62 key, err := DecodeKey(tc.exp)
63 if err != nil {
64 t.Errorf("%s: failed decoding key: %v", tc.desc, err)
65 continue
66 }
67 if !key.Equal(tc.key) {
68 t.Errorf("%s: decoded key %v, want %v", tc.desc, key, tc.key)
69 }
70 }
71}
72
73func TestKeyGob(t *testing.T) {
74 k := &Key{

Callers

nothing calls this directly

Calls 3

DecodeKeyFunction · 0.70
EncodeMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…