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

Side by Side Diff: logdog/common/storage/archive/storage_test.go

Issue 2538203002: LogDog: Add signed GS URL fetching. (Closed)
Patch Set: Allow index signing, use gaesigner. Created 4 years 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 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package archive 5 package archive
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "io" 10 "io"
(...skipping 10 matching lines...) Expand all
21 21
22 cloudStorage "cloud.google.com/go/storage" 22 cloudStorage "cloud.google.com/go/storage"
23 "github.com/golang/protobuf/proto" 23 "github.com/golang/protobuf/proto"
24 "golang.org/x/net/context" 24 "golang.org/x/net/context"
25 25
26 . "github.com/luci/luci-go/common/testing/assertions" 26 . "github.com/luci/luci-go/common/testing/assertions"
27 . "github.com/smartystreets/goconvey/convey" 27 . "github.com/smartystreets/goconvey/convey"
28 ) 28 )
29 29
30 const ( 30 const (
31 » testIndexURL = "gs://+/index" 31 » testIndexPath = gs.Path("gs://+/index")
32 » testStreamURL = "gs://+/stream" 32 » testStreamPath = gs.Path("gs://+/stream")
33 ) 33 )
34 34
35 type logStreamGenerator struct { 35 type logStreamGenerator struct {
36 lines []string 36 lines []string
37 37
38 indexBuf bytes.Buffer 38 indexBuf bytes.Buffer
39 streamBuf bytes.Buffer 39 streamBuf bytes.Buffer
40 } 40 }
41 41
42 func (g *logStreamGenerator) lineFromEntry(e *storage.Entry) string { 42 func (g *logStreamGenerator) lineFromEntry(e *storage.Entry) string {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // If we have a client-level error, return it. 175 // If we have a client-level error, return it.
176 if c.err != nil { 176 if c.err != nil {
177 return nil, c.err 177 return nil, c.err
178 } 178 }
179 179
180 var ( 180 var (
181 data []byte 181 data []byte
182 readerErr error 182 readerErr error
183 ) 183 )
184 » switch string(p) { 184 » switch p {
185 » case testIndexURL: 185 » case testIndexPath:
186 data, readerErr = c.index, c.indexErr 186 data, readerErr = c.index, c.indexErr
187 » case testStreamURL: 187 » case testStreamPath:
188 data, readerErr = c.stream, c.streamErr 188 data, readerErr = c.stream, c.streamErr
189 default: 189 default:
190 return nil, cloudStorage.ErrObjectNotExist 190 return nil, cloudStorage.ErrObjectNotExist
191 } 191 }
192 192
193 if offset >= 0 { 193 if offset >= 0 {
194 if offset >= int64(len(data)) { 194 if offset >= int64(len(data)) {
195 offset = int64(len(data)) 195 offset = int64(len(data))
196 } 196 }
197 data = data[offset:] 197 data = data[offset:]
(...skipping 13 matching lines...) Expand all
211 211
212 Convey(`A testing archive instance`, t, func() { 212 Convey(`A testing archive instance`, t, func() {
213 var ( 213 var (
214 c = context.Background() 214 c = context.Background()
215 client fakeGSClient 215 client fakeGSClient
216 gen logStreamGenerator 216 gen logStreamGenerator
217 ) 217 )
218 defer client.Close() 218 defer client.Close()
219 219
220 opts := Options{ 220 opts := Options{
221 » » » IndexURL: testIndexURL, 221 » » » Index: testIndexPath,
222 » » » StreamURL: testStreamURL, 222 » » » Stream: testStreamPath,
223 » » » Client: &client, 223 » » » Client: &client,
224 } 224 }
225 st, err := New(c, opts) 225 st, err := New(c, opts)
226 So(err, ShouldBeNil) 226 So(err, ShouldBeNil)
227 defer st.Close() 227 defer st.Close()
228 228
229 stImpl := st.(*storageImpl) 229 stImpl := st.(*storageImpl)
230 230
231 Convey(`Will fail to configure with ErrReadOnly`, func() { 231 Convey(`Will fail to configure with ErrReadOnly`, func() {
232 So(st.Config(storage.Config{}), ShouldEqual, storage.Err ReadOnly) 232 So(st.Config(storage.Config{}), ShouldEqual, storage.Err ReadOnly)
233 }) 233 })
234 234
235 Convey(`Will fail to Put with ErrReadOnly`, func() { 235 Convey(`Will fail to Put with ErrReadOnly`, func() {
236 So(st.Put(storage.PutRequest{}), ShouldEqual, storage.Er rReadOnly) 236 So(st.Put(storage.PutRequest{}), ShouldEqual, storage.Er rReadOnly)
237 }) 237 })
238 238
239 Convey(`Given a stream with 5 log entries`, func() { 239 Convey(`Given a stream with 5 log entries`, func() {
240 gen.generate("foo", "bar", "baz", "qux", "quux") 240 gen.generate("foo", "bar", "baz", "qux", "quux")
241 241
242 // Basic test cases. 242 // Basic test cases.
243 for _, tc := range []struct { 243 for _, tc := range []struct {
244 title string 244 title string
245 mod func() 245 mod func()
246 }{ 246 }{
247 {`Complete index`, func() {}}, 247 {`Complete index`, func() {}},
248 {`Empty index protobuf`, func() { gen.sparseInde x() }}, 248 {`Empty index protobuf`, func() { gen.sparseInde x() }},
249 » » » » {`No index provided`, func() { stImpl.indexPath = "" }}, 249 » » » » {`No index provided`, func() { stImpl.Index = "" }},
250 » » » » {`Invalid index path`, func() { stImpl.indexPath = "does-not-exist" }}, 250 » » » » {`Invalid index path`, func() { stImpl.Index = " does-not-exist" }},
251 {`Sparse index with a start and terminal entry`, func() { gen.sparseIndex(0, 2, 4) }}, 251 {`Sparse index with a start and terminal entry`, func() { gen.sparseIndex(0, 2, 4) }},
252 {`Sparse index with a terminal entry`, func() { gen.sparseIndex(1, 3, 4) }}, 252 {`Sparse index with a terminal entry`, func() { gen.sparseIndex(1, 3, 4) }},
253 {`Sparse index missing a terminal entry`, func() { gen.sparseIndex(1, 3) }}, 253 {`Sparse index missing a terminal entry`, func() { gen.sparseIndex(1, 3) }},
254 } { 254 } {
255 Convey(fmt.Sprintf(`Test Case: %q`, tc.title), f unc() { 255 Convey(fmt.Sprintf(`Test Case: %q`, tc.title), f unc() {
256 tc.mod() 256 tc.mod()
257 257
258 // Run through per-testcase variant set. 258 // Run through per-testcase variant set.
259 for _, variant := range []struct { 259 for _, variant := range []struct {
260 title string 260 title string
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 fn func() error 315 fn func() error
316 }{ 316 }{
317 {"Get", func() error { return st.Get(storage.GetRequest{ }, func(*storage.Entry) bool { return true }) }}, 317 {"Get", func() error { return st.Get(storage.GetRequest{ }, func(*storage.Entry) bool { return true }) }},
318 {"Tail", func() (err error) { 318 {"Tail", func() (err error) {
319 _, err = st.Tail("", "") 319 _, err = st.Tail("", "")
320 return 320 return
321 }}, 321 }},
322 } { 322 } {
323 Convey(fmt.Sprintf("Testing retrieval: %q", tc.title), f unc() { 323 Convey(fmt.Sprintf("Testing retrieval: %q", tc.title), f unc() {
324 Convey(`With missing log stream returns ErrDoesN otExist.`, func() { 324 Convey(`With missing log stream returns ErrDoesN otExist.`, func() {
325 » » » » » stImpl.streamPath = "does-not-exist" 325 » » » » » stImpl.Stream = "does-not-exist"
326 326
327 So(st.Get(storage.GetRequest{}, nil), Sh ouldEqual, storage.ErrDoesNotExist) 327 So(st.Get(storage.GetRequest{}, nil), Sh ouldEqual, storage.ErrDoesNotExist)
328 }) 328 })
329 329
330 Convey(`With a client error returns that error.` , func() { 330 Convey(`With a client error returns that error.` , func() {
331 client.err = errors.New("test error") 331 client.err = errors.New("test error")
332 332
333 So(errors.Unwrap(tc.fn()), ShouldEqual, client.err) 333 So(errors.Unwrap(tc.fn()), ShouldEqual, client.err)
334 }) 334 })
335 335
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 388 }
389 389
390 Convey(`Tail with no log entries returns ErrDoesNotExist.`, func () { 390 Convey(`Tail with no log entries returns ErrDoesNotExist.`, func () {
391 client.load(&gen) 391 client.load(&gen)
392 392
393 _, err := st.Tail("", "") 393 _, err := st.Tail("", "")
394 So(err, ShouldEqual, storage.ErrDoesNotExist) 394 So(err, ShouldEqual, storage.ErrDoesNotExist)
395 }) 395 })
396 }) 396 })
397 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698