@@ -29,7 +29,8 @@ use crate::DataAccessor;
29
29
use crate :: S3 ;
30
30
31
31
struct TestFixture {
32
- region : Region ,
32
+ region_name : String ,
33
+ endpoint_url : String ,
33
34
bucket_name : String ,
34
35
test_key : String ,
35
36
content : Vec < u8 > ,
@@ -39,17 +40,35 @@ impl TestFixture {
39
40
fn new ( size : usize , key : String ) -> Self {
40
41
let random_bytes: Vec < u8 > = ( 0 ..size) . map ( |_| rand:: random :: < u8 > ( ) ) . collect ( ) ;
41
42
Self {
42
- region : Region :: UsEast2 ,
43
- bucket_name : "poc-datafuse" . to_string ( ) ,
43
+ region_name : "us-east-1" . to_string ( ) ,
44
+ endpoint_url : "http://localhost:9000" . to_string ( ) ,
45
+ bucket_name : "test-bucket" . to_string ( ) ,
44
46
test_key : key,
45
47
content : random_bytes,
46
48
}
47
49
}
50
+
51
+ fn region ( & self ) -> Region {
52
+ Region :: Custom {
53
+ name : self . region_name . clone ( ) ,
54
+ endpoint : self . endpoint_url . clone ( ) ,
55
+ }
56
+ }
57
+
58
+ fn data_accessor ( & self ) -> common_exception:: Result < S3 > {
59
+ S3 :: try_create (
60
+ self . region_name . as_str ( ) ,
61
+ self . endpoint_url . as_str ( ) ,
62
+ self . bucket_name . as_str ( ) ,
63
+ "" ,
64
+ "" ,
65
+ )
66
+ }
48
67
}
49
68
50
69
impl TestFixture {
51
70
async fn gen_test_obj ( & self ) -> common_exception:: Result < ( ) > {
52
- let rusoto_client = S3Client :: new ( self . region . clone ( ) ) ;
71
+ let rusoto_client = S3Client :: new ( self . region ( ) ) ;
53
72
let put_req = PutObjectRequest {
54
73
bucket : self . bucket_name . clone ( ) ,
55
74
key : self . test_key . clone ( ) ,
@@ -64,47 +83,29 @@ impl TestFixture {
64
83
}
65
84
}
66
85
67
- // CI has no AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID yet
68
86
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
69
87
#[ ignore]
70
88
async fn test_s3_input_stream_api ( ) -> common_exception:: Result < ( ) > {
71
89
let test_key = "test_s3_input_stream" . to_string ( ) ;
72
90
let fixture = TestFixture :: new ( 1024 * 10 , test_key. clone ( ) ) ;
73
91
fixture. gen_test_obj ( ) . await ?;
74
92
75
- let s3 = S3 :: new ( fixture. region . clone ( ) , fixture . bucket_name . clone ( ) ) ;
93
+ let s3 = fixture. data_accessor ( ) ? ;
76
94
let mut input = s3. get_input_stream ( & test_key, None ) ?;
77
95
let mut buffer = vec ! [ ] ;
78
96
input. read_to_end ( & mut buffer) . await ?;
79
97
assert_eq ! ( fixture. content, buffer) ;
80
98
Ok ( ( ) )
81
99
}
82
100
83
- #[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
84
- #[ ignore]
85
- async fn test_s3_cli_with_credentials ( ) -> common_exception:: Result < ( ) > {
86
- let test_key = "test_s3_input_stream" . to_string ( ) ;
87
- let fixture = TestFixture :: new ( 1024 * 10 , test_key. clone ( ) ) ;
88
- fixture. gen_test_obj ( ) . await ?;
89
- let key = std:: env:: var ( "AWS_ACCESS_KEY_ID" ) . unwrap ( ) ;
90
- let secret = std:: env:: var ( "AWS_SECRET_ACCESS_KEY" ) . unwrap ( ) ;
91
-
92
- let s3 = S3 :: with_credentials ( fixture. region . name ( ) , & fixture. bucket_name , & key, & secret) ?;
93
- let mut buffer = vec ! [ ] ;
94
- let mut input = s3. get_input_stream ( & test_key, None ) ?;
95
- input. read_to_end ( & mut buffer) . await ?;
96
- assert_eq ! ( fixture. content, buffer) ;
97
- Ok ( ( ) )
98
- }
99
-
100
101
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
101
102
#[ ignore]
102
103
async fn test_s3_input_stream_seek_api ( ) -> common_exception:: Result < ( ) > {
103
- let test_key = "test_s3_seek_stream " . to_string ( ) ;
104
+ let test_key = "test_s3_seek_stream_seek " . to_string ( ) ;
104
105
let fixture = TestFixture :: new ( 1024 * 10 , test_key. clone ( ) ) ;
105
106
fixture. gen_test_obj ( ) . await ?;
106
107
107
- let s3 = S3 :: new ( fixture. region . clone ( ) , fixture . bucket_name . clone ( ) ) ;
108
+ let s3 = fixture. data_accessor ( ) ? ;
108
109
let mut input = s3. get_input_stream ( & test_key, None ) ?;
109
110
let mut buffer = vec ! [ ] ;
110
111
input. seek ( SeekFrom :: Current ( 1 ) ) . await ?;
0 commit comments