@@ -7,14 +7,18 @@ use slog_scope::debug;
7
7
8
8
/// GCPSnapshotUploader is a snapshot uploader working using Google Cloud Platform services
9
9
pub struct RemoteSnapshotUploader {
10
+ bucket : String ,
10
11
file_uploader : Box < dyn RemoteFileUploader > ,
11
12
}
12
13
13
14
impl RemoteSnapshotUploader {
14
15
/// GCPSnapshotUploader factory
15
- pub fn new ( file_uploader : Box < dyn RemoteFileUploader > ) -> Self {
16
+ pub fn new ( file_uploader : Box < dyn RemoteFileUploader > , bucket : String ) -> Self {
16
17
debug ! ( "New GCPSnapshotUploader created" ) ;
17
- Self { file_uploader }
18
+ Self {
19
+ bucket,
20
+ file_uploader,
21
+ }
18
22
}
19
23
}
20
24
@@ -23,8 +27,8 @@ impl SnapshotUploader for RemoteSnapshotUploader {
23
27
async fn upload_snapshot ( & self , snapshot_filepath : & Path ) -> Result < SnapshotLocation , String > {
24
28
let archive_name = snapshot_filepath. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
25
29
let location = format ! (
26
- "https://storage.googleapis.com/cardano-testnet /{}" ,
27
- archive_name
30
+ "https://storage.googleapis.com/{} /{}" ,
31
+ self . bucket , archive_name
28
32
) ;
29
33
30
34
self . file_uploader . upload_file ( snapshot_filepath) . await ?;
@@ -44,7 +48,8 @@ mod tests {
44
48
async fn test_upload_snapshot_ok ( ) {
45
49
let mut file_uploader = MockRemoteFileUploader :: new ( ) ;
46
50
file_uploader. expect_upload_file ( ) . return_const ( Ok ( ( ) ) ) ;
47
- let snapshot_uploader = RemoteSnapshotUploader :: new ( Box :: new ( file_uploader) ) ;
51
+ let snapshot_uploader =
52
+ RemoteSnapshotUploader :: new ( Box :: new ( file_uploader) , "cardano-testnet" . to_string ( ) ) ;
48
53
let snapshot_filepath = Path :: new ( "test/snapshot.xxx.tar.gz" ) ;
49
54
let expected_location =
50
55
"https://storage.googleapis.com/cardano-testnet/snapshot.xxx.tar.gz" . to_string ( ) ;
@@ -61,7 +66,8 @@ mod tests {
61
66
file_uploader
62
67
. expect_upload_file ( )
63
68
. return_const ( Err ( "unexpected error" . to_string ( ) ) ) ;
64
- let snapshot_uploader = RemoteSnapshotUploader :: new ( Box :: new ( file_uploader) ) ;
69
+ let snapshot_uploader =
70
+ RemoteSnapshotUploader :: new ( Box :: new ( file_uploader) , "" . to_string ( ) ) ;
65
71
let snapshot_filepath = Path :: new ( "test/snapshot.xxx.tar.gz" ) ;
66
72
67
73
let result = snapshot_uploader. upload_snapshot ( snapshot_filepath) . await ;
0 commit comments