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

Side by Side Diff: appengine/logdog/coordinator/endpoints/services/loadStream_test.go

Issue 1863973002: LogDog: Update to archival V2. (Closed) Base URL: https://github.com/luci/luci-go@grpcutil-errors
Patch Set: Fix proto comment. Created 4 years, 8 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
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 services 5 package services
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "testing" 9 "testing"
10 "time"
10 11
11 "github.com/golang/protobuf/proto" 12 "github.com/golang/protobuf/proto"
12 "github.com/luci/gae/filter/featureBreaker" 13 "github.com/luci/gae/filter/featureBreaker"
13 "github.com/luci/gae/impl/memory" 14 "github.com/luci/gae/impl/memory"
14 ds "github.com/luci/gae/service/datastore" 15 ds "github.com/luci/gae/service/datastore"
16 "github.com/luci/luci-go/appengine/logdog/coordinator"
15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest " 17 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest "
16 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" 18 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
17 "github.com/luci/luci-go/common/clock/testclock" 19 "github.com/luci/luci-go/common/clock/testclock"
18 » "github.com/luci/luci-go/common/proto/logdog/svcconfig" 20 » "github.com/luci/luci-go/common/proto/google"
19 "github.com/luci/luci-go/server/auth" 21 "github.com/luci/luci-go/server/auth"
20 "github.com/luci/luci-go/server/auth/authtest" 22 "github.com/luci/luci-go/server/auth/authtest"
21 "golang.org/x/net/context" 23 "golang.org/x/net/context"
22 24
23 . "github.com/luci/luci-go/common/testing/assertions" 25 . "github.com/luci/luci-go/common/testing/assertions"
24 . "github.com/smartystreets/goconvey/convey" 26 . "github.com/smartystreets/goconvey/convey"
25 ) 27 )
26 28
27 func TestLoadStream(t *testing.T) { 29 func TestLoadStream(t *testing.T) {
28 t.Parallel() 30 t.Parallel()
29 31
30 Convey(`With a testing configuration`, t, func() { 32 Convey(`With a testing configuration`, t, func() {
31 » » c, _ := testclock.UseTime(context.Background(), testclock.TestTi meLocal) 33 » » c, tc := testclock.UseTime(context.Background(), testclock.TestT imeUTC)
32 » » c = memory.Use(context.Background()) 34 » » c = memory.Use(c)
33 » » be := Server{}
34 35
35 » » c = ct.UseConfig(c, &svcconfig.Coordinator{ 36 » » svcStub := ct.Services{}
36 » » » ServiceAuthGroup: "test-services", 37 » » svcStub.InitConfig()
37 » » }) 38 » » svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi ces"
39 » » be := Server{
40 » » » ServiceBase: coordinator.ServiceBase{&svcStub},
41 » » }
42
38 fs := authtest.FakeState{} 43 fs := authtest.FakeState{}
39 c = auth.WithState(c, &fs) 44 c = auth.WithState(c, &fs)
40 45
41 // Register a test stream. 46 // Register a test stream.
42 desc := ct.TestLogStreamDescriptor(c, "foo/bar") 47 desc := ct.TestLogStreamDescriptor(c, "foo/bar")
43 ls := ct.TestLogStream(c, desc) 48 ls := ct.TestLogStream(c, desc)
44 » » if err := ls.Put(ds.Get(c)); err != nil { 49 » » if err := ds.Get(c).Put(ls); err != nil {
45 panic(err) 50 panic(err)
46 } 51 }
47 52
48 // Prepare a request to load the test stream. 53 // Prepare a request to load the test stream.
49 req := logdog.LoadStreamRequest{ 54 req := logdog.LoadStreamRequest{
50 Path: string(ls.Path()), 55 Path: string(ls.Path()),
51 } 56 }
52 57
53 Convey(`Returns Forbidden error if not a service.`, func() { 58 Convey(`Returns Forbidden error if not a service.`, func() {
54 _, err := be.LoadStream(c, &logdog.LoadStreamRequest{}) 59 _, err := be.LoadStream(c, &logdog.LoadStreamRequest{})
55 So(err, ShouldBeRPCPermissionDenied) 60 So(err, ShouldBeRPCPermissionDenied)
56 }) 61 })
57 62
58 Convey(`When logged in as a service`, func() { 63 Convey(`When logged in as a service`, func() {
59 fs.IdentityGroups = []string{"test-services"} 64 fs.IdentityGroups = []string{"test-services"}
60 65
61 Convey(`Will succeed.`, func() { 66 Convey(`Will succeed.`, func() {
62 resp, err := be.LoadStream(c, &req) 67 resp, err := be.LoadStream(c, &req)
63 So(err, ShouldBeNil) 68 So(err, ShouldBeNil)
64 So(resp, ShouldResemble, &logdog.LoadStreamRespo nse{ 69 So(resp, ShouldResemble, &logdog.LoadStreamRespo nse{
65 State: &logdog.LogStreamState{ 70 State: &logdog.LogStreamState{
66 Path: "testing/+/foo/ba r", 71 Path: "testing/+/foo/ba r",
67 ProtoVersion: "1", 72 ProtoVersion: "1",
68 TerminalIndex: -1, 73 TerminalIndex: -1,
69 }, 74 },
70 }) 75 })
71 }) 76 })
72 77
78 Convey(`Will return archival properties.`, func() {
79 tc.Add(1 * time.Hour)
80 ls.ArchivalKey = []byte("archival key")
81 if err := ds.Get(c).Put(ls); err != nil {
82 panic(err)
83 }
84
85 resp, err := be.LoadStream(c, &req)
86 So(err, ShouldBeNil)
87 So(resp, ShouldResemble, &logdog.LoadStreamRespo nse{
88 State: &logdog.LogStreamState{
89 Path: "testing/+/foo/ba r",
90 ProtoVersion: "1",
91 TerminalIndex: -1,
92 },
93 ArchivalKey: []byte("archival key"),
94 Age: google.NewDuration(1 * time .Hour),
95 })
96 })
97
73 Convey(`Will succeed, and return the descriptor when req uested.`, func() { 98 Convey(`Will succeed, and return the descriptor when req uested.`, func() {
74 req.Desc = true 99 req.Desc = true
75 100
76 d, err := proto.Marshal(desc) 101 d, err := proto.Marshal(desc)
77 if err != nil { 102 if err != nil {
78 panic(err) 103 panic(err)
79 } 104 }
80 105
81 resp, err := be.LoadStream(c, &req) 106 resp, err := be.LoadStream(c, &req)
82 So(err, ShouldBeNil) 107 So(err, ShouldBeNil)
(...skipping 24 matching lines...) Expand all
107 Convey(`Will return Internal for random datastore failur es.`, func() { 132 Convey(`Will return Internal for random datastore failur es.`, func() {
108 c, fb := featureBreaker.FilterRDS(c, nil) 133 c, fb := featureBreaker.FilterRDS(c, nil)
109 fb.BreakFeatures(errors.New("test error"), "GetM ulti") 134 fb.BreakFeatures(errors.New("test error"), "GetM ulti")
110 135
111 _, err := be.LoadStream(c, &req) 136 _, err := be.LoadStream(c, &req)
112 So(err, ShouldBeRPCInternal) 137 So(err, ShouldBeRPCInternal)
113 }) 138 })
114 }) 139 })
115 }) 140 })
116 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698