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

Side by Side Diff: server/logdog/storage/bigtable/rowKey_test.go

Issue 1909943003: LogDog: Add project support to Storage. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-coordinator-services
Patch Set: Rebase? Created 4 years, 7 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
« no previous file with comments | « server/logdog/storage/bigtable/rowKey.go ('k') | server/logdog/storage/bigtable/storage.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 bigtable 5 package bigtable
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strings" 9 "strings"
10 "testing" 10 "testing"
11 11
12 . "github.com/smartystreets/goconvey/convey" 12 . "github.com/smartystreets/goconvey/convey"
13 ) 13 )
14 14
15 func TestRowKey(t *testing.T) { 15 func TestRowKey(t *testing.T) {
16 t.Parallel() 16 t.Parallel()
17 17
18 » Convey(`A row key, constructed from "a/b/+/c/d"`, t, func() { 18 » Convey(`A row key, constructed from "test-project" and "a/b/+/c/d"`, t, func() {
19 » » project := "test-project"
19 path := "a/b/+/c/d" 20 path := "a/b/+/c/d"
20 » » rk := newRowKey(path, 1337, 42) 21
22 » » rk := newRowKey(project, path, 1337, 42)
21 23
22 Convey(`Shares a path with a row key from the same Path.`, func( ) { 24 Convey(`Shares a path with a row key from the same Path.`, func( ) {
23 » » » So(rk.sharesPathWith(newRowKey(path, 2468, 0)), ShouldBe True) 25 » » » So(rk.sharesPathWith(newRowKey(project, path, 2468, 0)), ShouldBeTrue)
24 }) 26 })
25 27
26 » » for _, v := range []string{ 28 » » for _, project := range []string{
27 » » » "a/b/+/c",
28 » » » "asdf",
29 "", 29 "",
30 "other-test-project",
30 } { 31 } {
31 » » » Convey(fmt.Sprintf(`Does not share a path with: %q`, v), func() { 32 » » » for _, path := range []string{
32 » » » » So(rk.sharesPathWith(newRowKey(v, 0, 0)), Should BeFalse) 33 » » » » "a/b/+/c",
33 » » » }) 34 » » » » "asdf",
35 » » » » "",
36 » » » } {
37 » » » » Convey(fmt.Sprintf(`Does not share a path with p roject %q, path %q`, project, path), func() {
38 » » » » » So(rk.sharesPathWith(newRowKey(project, path, 0, 0)), ShouldBeFalse)
39 » » » » })
40 » » » }
34 } 41 }
35 42
36 Convey(`Can be encoded, then decoded into its fields.`, func() { 43 Convey(`Can be encoded, then decoded into its fields.`, func() {
37 enc := rk.encode() 44 enc := rk.encode()
38 So(len(enc), ShouldBeLessThanOrEqualTo, maxEncodedKeySiz e) 45 So(len(enc), ShouldBeLessThanOrEqualTo, maxEncodedKeySiz e)
39 46
40 drk, err := decodeRowKey(enc) 47 drk, err := decodeRowKey(enc)
41 So(err, ShouldBeNil) 48 So(err, ShouldBeNil)
42 49
43 So(drk.pathHash, ShouldResemble, rk.pathHash) 50 So(drk.pathHash, ShouldResemble, rk.pathHash)
44 So(drk.index, ShouldEqual, rk.index) 51 So(drk.index, ShouldEqual, rk.index)
45 So(drk.count, ShouldEqual, rk.count) 52 So(drk.count, ShouldEqual, rk.count)
46 }) 53 })
47 }) 54 })
48 55
49 Convey(`A series of ordered row keys`, t, func() { 56 Convey(`A series of ordered row keys`, t, func() {
50 prev := "" 57 prev := ""
51 for _, i := range []int64{ 58 for _, i := range []int64{
52 -1, /* Why not? */ 59 -1, /* Why not? */
53 0, 60 0,
54 7, 61 7,
55 8, 62 8,
56 257, 63 257,
57 1029, 64 1029,
58 1337, 65 1337,
59 } { 66 } {
60 Convey(fmt.Sprintf(`Row key %d should be ascendingly sor ted and parsable.`, i), func() { 67 Convey(fmt.Sprintf(`Row key %d should be ascendingly sor ted and parsable.`, i), func() {
61 » » » » rk := newRowKey("test", i, i) 68 » » » » rk := newRowKey("test-project", "test", i, i)
62 69
63 // Test that it encodes/decodes back to identity . 70 // Test that it encodes/decodes back to identity .
64 enc := rk.encode() 71 enc := rk.encode()
65 drk, err := decodeRowKey(enc) 72 drk, err := decodeRowKey(enc)
66 So(err, ShouldBeNil) 73 So(err, ShouldBeNil)
67 So(drk.index, ShouldEqual, i) 74 So(drk.index, ShouldEqual, i)
68 75
69 // Assert that it is ordered. 76 // Assert that it is ordered.
70 if prev != "" { 77 if prev != "" {
71 So(prev, ShouldBeLessThan, enc) 78 So(prev, ShouldBeLessThan, enc)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 {"Varint overflow", "a94a8fe5ccb19ba61c4c0873d391e987982 fbbd3~ffffffffffff"}, 122 {"Varint overflow", "a94a8fe5ccb19ba61c4c0873d391e987982 fbbd3~ffffffffffff"},
116 {"Trailing data", "a94a8fe5ccb19ba61c4c0873d391e987982fb bd3~8080badd06"}, 123 {"Trailing data", "a94a8fe5ccb19ba61c4c0873d391e987982fb bd3~8080badd06"},
117 } { 124 } {
118 Convey(fmt.Sprintf(`Row key fails to decode [%s]: %q`, t .name, t.v), func() { 125 Convey(fmt.Sprintf(`Row key fails to decode [%s]: %q`, t .name, t.v), func() {
119 _, err := decodeRowKey(t.v) 126 _, err := decodeRowKey(t.v)
120 So(err, ShouldEqual, errMalformedRowKey) 127 So(err, ShouldEqual, errMalformedRowKey)
121 }) 128 })
122 } 129 }
123 }) 130 })
124 } 131 }
OLDNEW
« no previous file with comments | « server/logdog/storage/bigtable/rowKey.go ('k') | server/logdog/storage/bigtable/storage.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698