Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go

Issue 1240573002: Reland: Refactor current GAE abstraction library to be free of the SDK* (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: expand coverage range to fit 32bit test expectations Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "testing"
9
10 . "github.com/smartystreets/goconvey/convey"
11 )
12
13 type keyLeftRight struct{ key, left, right []byte }
14
15 var testCollisionCases = []struct {
16 name string
17 left, right []kv // inserts into left and right collections
18 expect []keyLeftRight
19 }{
20 {
21 name: "nil",
22 },
23 {
24 name: "empty",
25 left: []kv{},
26 right: []kv{},
27 },
28 {
29 name: "all old",
30 left: []kv{
31 {cat(1), cat()},
32 {cat(0), cat()},
33 },
34 expect: []keyLeftRight{
35 {cat(0), cat(), nil},
36 {cat(1), cat(), nil},
37 },
38 },
39 {
40 name: "all new",
41 right: []kv{
42 {cat(1), cat()},
43 {cat(0), cat()},
44 },
45 expect: []keyLeftRight{
46 {cat(0), nil, cat()},
47 {cat(1), nil, cat()},
48 },
49 },
50 {
51 name: "new vals",
52 left: []kv{
53 {cat(1), cat("hi")},
54 {cat(0), cat("newb")},
55 },
56 right: []kv{
57 {cat(0), cat(2.5)},
58 {cat(1), cat(58)},
59 },
60 expect: []keyLeftRight{
61 {cat(0), cat("newb"), cat(2.5)},
62 {cat(1), cat("hi"), cat(58)},
63 },
64 },
65 {
66 name: "mixed",
67 left: []kv{
68 {cat(1), cat("one")},
69 {cat(0), cat("hi")},
70 {cat(6), cat()},
71 {cat(3), cat(1.3)},
72 {cat(2), []byte("zoop")},
73 {cat(-1), cat("bob")},
74 },
75 right: []kv{
76 {cat(3), cat(1)},
77 {cat(1), cat(58)},
78 {cat(0), cat(2.5)},
79 {cat(4), cat(1337)},
80 {cat(2), cat("ski", 7)},
81 {cat(20), cat("nerd")},
82 },
83 expect: []keyLeftRight{
84 {cat(-1), cat("bob"), nil},
85 {cat(0), cat("hi"), cat(2.5)},
86 {cat(1), cat("one"), cat(58)},
87 {cat(2), []byte("zoop"), cat("ski", 7)},
88 {cat(3), cat(1.3), cat(1)},
89 {cat(4), nil, cat(1337)},
90 {cat(6), cat(), nil},
91 {cat(20), nil, cat("nerd")},
92 },
93 },
94 }
95
96 func getFilledColl(s *memStore, fill []kv) *memCollection {
97 if fill == nil {
98 return nil
99 }
100 ret := s.MakePrivateCollection(nil)
101 for _, i := range fill {
102 ret.Set(i.k, i.v)
103 }
104 return ret
105 }
106
107 func TestCollision(t *testing.T) {
108 t.Parallel()
109
110 Convey("Test gkvCollide", t, func() {
111 s := newMemStore()
112 for _, tc := range testCollisionCases {
113 Convey(tc.name, func() {
114 left := getFilledColl(s, tc.left)
115 right := getFilledColl(s, tc.right)
116 i := 0
117 gkvCollide(left, right, func(key, left, right [] byte) {
118 e := tc.expect[i]
119 So(key, ShouldResemble, e.key)
120 So(left, ShouldResemble, e.left)
121 So(right, ShouldResemble, e.right)
122 i++
123 })
124 So(i, ShouldEqual, len(tc.expect))
125 })
126 }
127 })
128 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/gkvlite_utils.go ('k') | go/src/infra/gae/libs/wrapper/memory/globalinfo.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698