Chromium Code Reviews

Side by Side Diff: impl/memory/testing_utils_test.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « impl/memory/taskqueue_test.go ('k') | impl/prod/context.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "time" 10 "time"
11 11
12 » "github.com/luci/gae" 12 » rds "github.com/luci/gae/service/rawdatastore"
13 » "github.com/luci/gae/helper"
14 "github.com/luci/luci-go/common/cmpbin" 13 "github.com/luci/luci-go/common/cmpbin"
15 ) 14 )
16 15
17 type kv struct{ k, v []byte } 16 type kv struct{ k, v []byte }
18 17
19 func indx(kind string, orders ...string) *qIndex { 18 func indx(kind string, orders ...string) *qIndex {
20 ancestor := false 19 ancestor := false
21 if kind[len(kind)-1] == '!' { 20 if kind[len(kind)-1] == '!' {
22 ancestor = true 21 ancestor = true
23 kind = kind[:len(kind)-1] 22 kind = kind[:len(kind)-1]
24 } 23 }
25 ret := &qIndex{kind, ancestor, nil} 24 ret := &qIndex{kind, ancestor, nil}
26 for _, o := range orders { 25 for _, o := range orders {
27 dir := qASC 26 dir := qASC
28 if o[0] == '-' { 27 if o[0] == '-' {
29 dir = qDEC 28 dir = qDEC
30 o = o[1:] 29 o = o[1:]
31 } 30 }
32 ret.sortby = append(ret.sortby, qSortBy{o, dir}) 31 ret.sortby = append(ret.sortby, qSortBy{o, dir})
33 } 32 }
34 return ret 33 return ret
35 } 34 }
36 35
37 var ( 36 var (
38 » prop = gae.MkDSProperty 37 » prop = rds.MkProperty
39 » propNI = gae.MkDSPropertyNI 38 » propNI = rds.MkPropertyNI
40 ) 39 )
41 40
42 func key(kind string, id interface{}, parent ...gae.DSKey) gae.DSKey { 41 func key(kind string, id interface{}, parent ...rds.Key) rds.Key {
43 » p := gae.DSKey(nil) 42 » p := rds.Key(nil)
44 if len(parent) > 0 { 43 if len(parent) > 0 {
45 p = parent[0] 44 p = parent[0]
46 } 45 }
47 switch x := id.(type) { 46 switch x := id.(type) {
48 case string: 47 case string:
49 » » return helper.NewDSKey(globalAppID, "ns", kind, x, 0, p) 48 » » return rds.NewKey(globalAppID, "ns", kind, x, 0, p)
50 case int: 49 case int:
51 » » return helper.NewDSKey(globalAppID, "ns", kind, "", int64(x), p) 50 » » return rds.NewKey(globalAppID, "ns", kind, "", int64(x), p)
52 default: 51 default:
53 panic(fmt.Errorf("what the %T: %v", id, id)) 52 panic(fmt.Errorf("what the %T: %v", id, id))
54 } 53 }
55 } 54 }
56 55
57 // cat is a convenience method for concatenating anything with an underlying 56 // cat is a convenience method for concatenating anything with an underlying
58 // byte representation into a single []byte. 57 // byte representation into a single []byte.
59 func cat(bytethings ...interface{}) []byte { 58 func cat(bytethings ...interface{}) []byte {
60 buf := &bytes.Buffer{} 59 buf := &bytes.Buffer{}
61 for _, thing := range bytethings { 60 for _, thing := range bytethings {
62 switch x := thing.(type) { 61 switch x := thing.(type) {
63 case int64: 62 case int64:
64 cmpbin.WriteInt(buf, x) 63 cmpbin.WriteInt(buf, x)
65 case int: 64 case int:
66 cmpbin.WriteInt(buf, int64(x)) 65 cmpbin.WriteInt(buf, int64(x))
67 case uint64: 66 case uint64:
68 cmpbin.WriteUint(buf, x) 67 cmpbin.WriteUint(buf, x)
69 case uint: 68 case uint:
70 cmpbin.WriteUint(buf, uint64(x)) 69 cmpbin.WriteUint(buf, uint64(x))
71 case float64: 70 case float64:
72 cmpbin.WriteFloat64(buf, x) 71 cmpbin.WriteFloat64(buf, x)
73 case byte: 72 case byte:
74 buf.WriteByte(x) 73 buf.WriteByte(x)
75 » » case gae.DSPropertyType: 74 » » case rds.PropertyType:
76 buf.WriteByte(byte(x)) 75 buf.WriteByte(byte(x))
77 case string: 76 case string:
78 cmpbin.WriteString(buf, x) 77 cmpbin.WriteString(buf, x)
79 case []byte: 78 case []byte:
80 buf.Write(x) 79 buf.Write(x)
81 case time.Time: 80 case time.Time:
82 » » » helper.WriteTime(buf, x) 81 » » » rds.WriteTime(buf, x)
83 » » case gae.DSKey: 82 » » case rds.Key:
84 » » » helper.WriteDSKey(buf, helper.WithoutContext, x) 83 » » » rds.WriteKey(buf, rds.WithoutContext, x)
85 case *qIndex: 84 case *qIndex:
86 x.WriteBinary(buf) 85 x.WriteBinary(buf)
87 default: 86 default:
88 panic(fmt.Errorf("I don't know how to deal with %T: %#v" , thing, thing)) 87 panic(fmt.Errorf("I don't know how to deal with %T: %#v" , thing, thing))
89 } 88 }
90 } 89 }
91 ret := buf.Bytes() 90 ret := buf.Bytes()
92 if ret == nil { 91 if ret == nil {
93 ret = []byte{} 92 ret = []byte{}
94 } 93 }
95 return ret 94 return ret
96 } 95 }
97 96
98 func icat(bytethings ...interface{}) []byte { 97 func icat(bytethings ...interface{}) []byte {
99 ret := cat(bytethings...) 98 ret := cat(bytethings...)
100 for i := range ret { 99 for i := range ret {
101 ret[i] ^= 0xFF 100 ret[i] ^= 0xFF
102 } 101 }
103 return ret 102 return ret
104 } 103 }
105 104
106 func sat(bytethings ...interface{}) string { 105 func sat(bytethings ...interface{}) string {
107 return string(cat(bytethings...)) 106 return string(cat(bytethings...))
108 } 107 }
OLDNEW
« no previous file with comments | « impl/memory/taskqueue_test.go ('k') | impl/prod/context.go » ('j') | no next file with comments »

Powered by Google App Engine