| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 archivist | 5 package archivist |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 Path: string(desc.Path()), | 218 Path: string(desc.Path()), |
| 219 ProtoVersion: logpb.Version, | 219 ProtoVersion: logpb.Version, |
| 220 TerminalIndex: -1, | 220 TerminalIndex: -1, |
| 221 Archived: false, | 221 Archived: false, |
| 222 Purged: false, | 222 Purged: false, |
| 223 }, | 223 }, |
| 224 Desc: descBytes, | 224 Desc: descBytes, |
| 225 } | 225 } |
| 226 | 226 |
| 227 var archiveRequest *logdog.ArchiveStreamRequest | 227 var archiveRequest *logdog.ArchiveStreamRequest |
| 228 var archiveStreamErr error |
| 228 sc := testServicesClient{ | 229 sc := testServicesClient{ |
| 229 lsCallback: func(req *logdog.LoadStreamRequest) (*logdog
.LoadStreamResponse, error) { | 230 lsCallback: func(req *logdog.LoadStreamRequest) (*logdog
.LoadStreamResponse, error) { |
| 230 return &stream, nil | 231 return &stream, nil |
| 231 }, | 232 }, |
| 232 asCallback: func(req *logdog.ArchiveStreamRequest) error
{ | 233 asCallback: func(req *logdog.ArchiveStreamRequest) error
{ |
| 233 archiveRequest = req | 234 archiveRequest = req |
| 234 » » » » return nil | 235 » » » » return archiveStreamErr |
| 235 }, | 236 }, |
| 236 } | 237 } |
| 237 | 238 |
| 238 ar := Archivist{ | 239 ar := Archivist{ |
| 239 Service: &sc, | 240 Service: &sc, |
| 240 Storage: &st, | 241 Storage: &st, |
| 241 GSClient: &gsc, | 242 GSClient: &gsc, |
| 242 GSBase: gs.Path("gs://archive-test/path/to/archive/"),
// Extra slashes to test concatenation. | 243 GSBase: gs.Path("gs://archive-test/path/to/archive/"),
// Extra slashes to test concatenation. |
| 243 } | 244 } |
| 244 | 245 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 So(archiveRequest, ShouldResemble, &logd
og.ArchiveStreamRequest{ | 365 So(archiveRequest, ShouldResemble, &logd
og.ArchiveStreamRequest{ |
| 365 Path: task.Path, | 366 Path: task.Path, |
| 366 Complete: false, | 367 Complete: false, |
| 367 TerminalIndex: 4, | 368 TerminalIndex: 4, |
| 368 | 369 |
| 369 StreamUrl: gsURL("logstream.entr
ies"), | 370 StreamUrl: gsURL("logstream.entr
ies"), |
| 370 IndexUrl: gsURL("logstream.inde
x"), | 371 IndexUrl: gsURL("logstream.inde
x"), |
| 371 DataUrl: gsURL("data.bin"), | 372 DataUrl: gsURL("data.bin"), |
| 372 }) | 373 }) |
| 373 }) | 374 }) |
| 375 |
| 376 Convey(`When an archival error occurs, will subm
it an ArchiveStreamRequest with Error set.`, func() { |
| 377 gsc.newWriterErr = func(*testGSWriter) e
rror { return errors.New("test error") } |
| 378 archiveStreamErr = errors.New("test erro
r") |
| 379 |
| 380 So(ar.Archive(c, &task), ShouldEqual, ar
chiveStreamErr) |
| 381 So(archiveRequest, ShouldResemble, &logd
og.ArchiveStreamRequest{ |
| 382 Path: task.Path, |
| 383 Complete: false, |
| 384 TerminalIndex: -1, |
| 385 Error: true, |
| 386 }) |
| 387 }) |
| 374 }) | 388 }) |
| 375 | 389 |
| 376 Convey(`With terminal index 3`, func() { | 390 Convey(`With terminal index 3`, func() { |
| 377 stream.State.TerminalIndex = 3 | 391 stream.State.TerminalIndex = 3 |
| 378 | 392 |
| 379 Convey(`Will successfully archive if there are n
o entries.`, func() { | 393 Convey(`Will successfully archive if there are n
o entries.`, func() { |
| 380 So(ar.Archive(c, &task), ShouldBeNil) | 394 So(ar.Archive(c, &task), ShouldBeNil) |
| 381 | 395 |
| 382 So(hasStreams(true, true, false), Should
BeTrue) | 396 So(hasStreams(true, true, false), Should
BeTrue) |
| 383 So(archiveRequest, ShouldResemble, &logd
og.ArchiveStreamRequest{ | 397 So(archiveRequest, ShouldResemble, &logd
og.ArchiveStreamRequest{ |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 return e
rrors.New("other error") | 490 return e
rrors.New("other error") |
| 477 } | 491 } |
| 478 | 492 |
| 479 // First delete
(on create). | 493 // First delete
(on create). |
| 480 failed = true | 494 failed = true |
| 481 } | 495 } |
| 482 return nil | 496 return nil |
| 483 } | 497 } |
| 484 }}, | 498 }}, |
| 485 } { | 499 } { |
| 486 » » » » » Convey(fmt.Sprintf(`Can handle %s for %s
`, testCase.name, failName), func() { | 500 » » » » » Convey(fmt.Sprintf(`Can handle %s for %s
, and will not archive.`, testCase.name, failName), func() { |
| 487 testCase.setup() | 501 testCase.setup() |
| 488 So(ar.Archive(c, &task), ShouldE
rrLike, "test error") | 502 So(ar.Archive(c, &task), ShouldE
rrLike, "test error") |
| 503 So(archiveRequest, ShouldBeNil) |
| 489 }) | 504 }) |
| 490 } | 505 } |
| 491 } | 506 } |
| 492 }) | 507 }) |
| 493 }) | 508 }) |
| 494 } | 509 } |
| OLD | NEW |