@@ -5,15 +5,39 @@ const getReplicationInfo =
55 require ( '../../../../lib/api/apiUtils/object/getReplicationInfo' ) ;
66const { makeAuthInfo } = require ( '../../helpers' ) ;
77
8- function _getObjectReplicationInfo ( replicationConfig , authInfo , isDeleteMarker ) {
8+ function _getObjectReplicationInfo ( replicationEndpoints , replicationConfig , authInfo , isDeleteMarker ) {
99 const bucketInfo = new BucketInfo (
1010 'testbucket' , 'someCanonicalId' , 'accountDisplayName' ,
1111 new Date ( ) . toJSON ( ) ,
1212 null , null , null , null , null , null , null , null , null ,
1313 replicationConfig ) ;
14- return getReplicationInfo ( 'fookey' , bucketInfo , true , 123 , null , null , authInfo , isDeleteMarker ) ;
14+ return getReplicationInfo ( replicationEndpoints ,
15+ 'fookey' , bucketInfo , true , 123 , null , null , authInfo , isDeleteMarker ) ;
1516}
1617
18+ const TEST_CONFIG = {
19+ locationConstraints : {
20+ awsbackend : {
21+ type : 'aws_s3' ,
22+ legacyAwsBehavior : true ,
23+ details : {
24+ awsEndpoint : 's3.amazonaws.com' ,
25+ bucketName : 'multitester555' ,
26+ bucketMatch : true ,
27+ credentialsProfile : 'default' ,
28+ } ,
29+ } ,
30+ } ,
31+ replicationEndpoints : [ {
32+ site : 'zenko' ,
33+ servers : [ '127.0.0.1:8000' ] ,
34+ default : true ,
35+ } , {
36+ site : 'us-east-2' ,
37+ type : 'aws_s3' ,
38+ } ] ,
39+ } ;
40+
1741describe ( 'getReplicationInfo helper' , ( ) => {
1842 it ( 'should get replication info when rules are enabled' , ( ) => {
1943 const replicationConfig = {
@@ -25,7 +49,7 @@ describe('getReplicationInfo helper', () => {
2549 } ] ,
2650 destination : 'tosomewhere' ,
2751 } ;
28- const replicationInfo = _getObjectReplicationInfo ( replicationConfig ) ;
52+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG , replicationConfig ) ;
2953 assert . deepStrictEqual ( replicationInfo , {
3054 status : 'PENDING' ,
3155 backends : [ {
@@ -53,7 +77,8 @@ describe('getReplicationInfo helper', () => {
5377 } ;
5478
5579 const authInfo = makeAuthInfo ( 'accessKey1' , null , 'another-session' ) ;
56- const replicationInfo = _getObjectReplicationInfo ( replicationConfig , authInfo , true ) ;
80+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG ,
81+ replicationConfig , authInfo , true ) ;
5782
5883 assert . deepStrictEqual ( replicationInfo , {
5984 status : 'PENDING' ,
@@ -83,7 +108,8 @@ describe('getReplicationInfo helper', () => {
83108 } ;
84109
85110 const authInfo = makeAuthInfo ( 'accessKey1' , null , 'backbeat-lifecycle' ) ;
86- const replicationInfo = _getObjectReplicationInfo ( replicationConfig , authInfo , false ) ;
111+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG ,
112+ replicationConfig , authInfo , false ) ;
87113
88114 assert . deepStrictEqual ( replicationInfo , {
89115 status : 'PENDING' ,
@@ -110,11 +136,11 @@ describe('getReplicationInfo helper', () => {
110136 } ] ,
111137 destination : 'tosomewhere' ,
112138 } ;
113- const replicationInfo = _getObjectReplicationInfo ( replicationConfig ) ;
139+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG , replicationConfig ) ;
114140 assert . deepStrictEqual ( replicationInfo , undefined ) ;
115141 } ) ;
116142
117- it ( 'should not get replication info when action comming from lifecycle session' , ( ) => {
143+ it ( 'should not get replication info when action coming from lifecycle session' , ( ) => {
118144 const replicationConfig = {
119145 role : 'arn:aws:iam::root:role/s3-replication-role' ,
120146 rules : [ {
@@ -126,8 +152,83 @@ describe('getReplicationInfo helper', () => {
126152 } ;
127153
128154 const authInfo = makeAuthInfo ( 'accessKey1' , null , 'backbeat-lifecycle' ) ;
129- const replicationInfo = _getObjectReplicationInfo ( replicationConfig , authInfo , true ) ;
155+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG ,
156+ replicationConfig , authInfo , true ) ;
157+
158+ assert . deepStrictEqual ( replicationInfo , undefined ) ;
159+ } ) ;
160+
161+ it ( 'should get replication info with default StorageClass when rules are enabled' , ( ) => {
162+ const replicationConfig = {
163+ role : 'arn:aws:iam::root:role/s3-replication-role-1,arn:aws:iam::root:role/s3-replication-role-2' ,
164+ rules : [ {
165+ prefix : '' ,
166+ enabled : true ,
167+ } ] ,
168+ destination : 'tosomewhere' ,
169+ } ;
170+ const replicationInfo = _getObjectReplicationInfo ( TEST_CONFIG , replicationConfig ) ;
171+ assert . deepStrictEqual ( replicationInfo , {
172+ status : 'PENDING' ,
173+ backends : [ {
174+ site : 'zenko' ,
175+ status : 'PENDING' ,
176+ dataStoreVersionId : '' ,
177+ } ] ,
178+ content : [ 'METADATA' ] ,
179+ destination : 'tosomewhere' ,
180+ storageClass : 'zenko' ,
181+ role : 'arn:aws:iam::root:role/s3-replication-role-1,arn:aws:iam::root:role/s3-replication-role-2' ,
182+ storageType : '' ,
183+ } ) ;
184+ } ) ;
130185
186+ it ( 'should return undefined with specified StorageClass mode if no replication endpoint is configured' , ( ) => {
187+ const replicationConfig = {
188+ role : 'arn:aws:iam::root:role/s3-replication-role' ,
189+ rules : [ {
190+ prefix : '' ,
191+ enabled : true ,
192+ storageClass : 'awsbackend' ,
193+ } ] ,
194+ destination : 'tosomewhere' ,
195+ } ;
196+ const configWithNoReplicationEndpoint = {
197+ locationConstraints : TEST_CONFIG . locationConstraints ,
198+ replicationEndpoints : [ ] ,
199+ } ;
200+ const replicationInfo = _getObjectReplicationInfo ( configWithNoReplicationEndpoint ,
201+ replicationConfig ) ;
202+ assert . deepStrictEqual ( replicationInfo , {
203+ status : 'PENDING' ,
204+ backends : [ {
205+ site : 'awsbackend' ,
206+ status : 'PENDING' ,
207+ dataStoreVersionId : '' ,
208+ } ] ,
209+ content : [ 'METADATA' ] ,
210+ destination : 'tosomewhere' ,
211+ storageClass : 'awsbackend' ,
212+ role : 'arn:aws:iam::root:role/s3-replication-role' ,
213+ storageType : 'aws_s3' ,
214+ } ) ;
215+ } ) ;
216+
217+ it ( 'should return undefined with default StorageClass if no replication endpoint is configured' , ( ) => {
218+ const replicationConfig = {
219+ role : 'arn:aws:iam::root:role/s3-replication-role-1,arn:aws:iam::root:role/s3-replication-role-2' ,
220+ rules : [ {
221+ prefix : '' ,
222+ enabled : true ,
223+ } ] ,
224+ destination : 'tosomewhere' ,
225+ } ;
226+ const configWithNoReplicationEndpoint = {
227+ locationConstraints : TEST_CONFIG . locationConstraints ,
228+ replicationEndpoints : [ ] ,
229+ } ;
230+ const replicationInfo = _getObjectReplicationInfo ( configWithNoReplicationEndpoint ,
231+ replicationConfig ) ;
131232 assert . deepStrictEqual ( replicationInfo , undefined ) ;
132233 } ) ;
133234} ) ;
0 commit comments