| OLD | NEW |
| 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 "testing" | 8 "testing" |
| 9 "time" |
| 9 | 10 |
| 10 "github.com/luci/luci-go/common/errors" | 11 "github.com/luci/luci-go/common/errors" |
| 11 "github.com/luci/luci-go/common/grpcutil" | 12 "github.com/luci/luci-go/common/grpcutil" |
| 13 "github.com/luci/luci-go/server/logdog/storage" |
| 14 "golang.org/x/net/context" |
| 15 "google.golang.org/cloud/bigtable" |
| 16 |
| 12 . "github.com/smartystreets/goconvey/convey" | 17 . "github.com/smartystreets/goconvey/convey" |
| 13 ) | 18 ) |
| 14 | 19 |
| 15 func TestBigTable(t *testing.T) { | 20 func TestBigTable(t *testing.T) { |
| 16 t.Parallel() | 21 t.Parallel() |
| 17 | 22 |
| 23 Convey(`Testing BigTable internal functions`, t, func() { |
| 24 var bt btTableTest |
| 25 defer bt.close() |
| 26 |
| 27 s := newBTStorage(context.Background(), Options{ |
| 28 Project: "test-project", |
| 29 Zone: "test-zone", |
| 30 Cluster: "test-cluster", |
| 31 LogTable: "test-log-table", |
| 32 }, nil, nil) |
| 33 |
| 34 s.raw = &bt |
| 35 defer s.Close() |
| 36 |
| 37 Convey(`Given a fake BigTable row`, func() { |
| 38 fakeRow := bigtable.Row{ |
| 39 "log": []bigtable.ReadItem{ |
| 40 { |
| 41 Row: "testrow", |
| 42 Column: logColName, |
| 43 Value: []byte("here is my data"
), |
| 44 }, |
| 45 }, |
| 46 } |
| 47 |
| 48 Convey(`Can extract log data.`, func() { |
| 49 d, err := getLogRowData(fakeRow) |
| 50 So(err, ShouldBeNil) |
| 51 So(d, ShouldResemble, []byte("here is my data")) |
| 52 }) |
| 53 |
| 54 Convey(`Will fail to extract if the column is missing.`,
func() { |
| 55 fakeRow["log"][0].Column = "not-data" |
| 56 |
| 57 _, err := getLogRowData(fakeRow) |
| 58 So(err, ShouldEqual, storage.ErrDoesNotExist) |
| 59 }) |
| 60 |
| 61 Convey(`Will fail to extract if the family does not exis
t.`, func() { |
| 62 So(getReadItem(fakeRow, "invalid", "invalid"), S
houldBeNil) |
| 63 }) |
| 64 |
| 65 Convey(`Will fail to extract if the column does not exis
t.`, func() { |
| 66 So(getReadItem(fakeRow, "log", "invalid"), Shoul
dBeNil) |
| 67 }) |
| 68 }) |
| 69 |
| 70 Convey(`When pushing a configuration`, func() { |
| 71 cfg := storage.Config{ |
| 72 MaxLogAge: 1 * time.Hour, |
| 73 } |
| 74 |
| 75 Convey(`Can successfully apply configuration.`, func() { |
| 76 So(s.Config(cfg), ShouldBeNil) |
| 77 So(bt.maxLogAge, ShouldEqual, cfg.MaxLogAge) |
| 78 }) |
| 79 |
| 80 Convey(`With return an error if the configuration fails
to apply.`, func() { |
| 81 bt.err = errors.New("test error") |
| 82 |
| 83 So(s.Config(cfg), ShouldEqual, bt.err) |
| 84 }) |
| 85 }) |
| 86 }) |
| 87 } |
| 88 |
| 89 func TestBigTableErrors(t *testing.T) { |
| 90 t.Parallel() |
| 91 |
| 18 Convey(`A nil error is not marked transient.`, t, func() { | 92 Convey(`A nil error is not marked transient.`, t, func() { |
| 19 So(wrapTransient(nil), ShouldBeNil) | 93 So(wrapTransient(nil), ShouldBeNil) |
| 20 }) | 94 }) |
| 21 | 95 |
| 22 Convey(`A regular error is not marked transient.`, t, func() { | 96 Convey(`A regular error is not marked transient.`, t, func() { |
| 23 So(grpcutil.IsTransient(grpcutil.Canceled), ShouldBeFalse) | 97 So(grpcutil.IsTransient(grpcutil.Canceled), ShouldBeFalse) |
| 24 So(errors.IsTransient(wrapTransient(grpcutil.Canceled)), ShouldB
eFalse) | 98 So(errors.IsTransient(wrapTransient(grpcutil.Canceled)), ShouldB
eFalse) |
| 25 }) | 99 }) |
| 26 | 100 |
| 27 Convey(`An gRPC transient error is marked transient.`, t, func() { | 101 Convey(`An gRPC transient error is marked transient.`, t, func() { |
| 28 So(grpcutil.IsTransient(grpcutil.Internal), ShouldBeTrue) | 102 So(grpcutil.IsTransient(grpcutil.Internal), ShouldBeTrue) |
| 29 So(errors.IsTransient(wrapTransient(grpcutil.Internal)), ShouldB
eTrue) | 103 So(errors.IsTransient(wrapTransient(grpcutil.Internal)), ShouldB
eTrue) |
| 30 }) | 104 }) |
| 31 } | 105 } |
| OLD | NEW |