@@ -5,6 +5,19 @@ const s3_utils = require('../../../endpoint/s3/s3_utils');
5
5
const { S3Error } = require ( '../../../endpoint/s3/s3_errors' ) ;
6
6
const config = require ( '../../../../config' ) ;
7
7
8
+ function create_dummy_nb_response ( ) {
9
+ return {
10
+ headers : { } ,
11
+ setHeader : function ( k , v ) {
12
+ if ( Array . isArray ( v ) ) {
13
+ v = v . join ( ',' ) ;
14
+ }
15
+
16
+ this . headers [ k ] = v ;
17
+ }
18
+ } ;
19
+ }
20
+
8
21
describe ( 's3_utils' , ( ) => {
9
22
describe ( 'parse_restrore_request_days' , ( ) => {
10
23
it ( 'should parse correctly when 0 < days < max days' , ( ) => {
@@ -57,4 +70,49 @@ describe('s3_utils', () => {
57
70
config . S3_RESTORE_REQUEST_MAX_DAYS_BEHAVIOUR = initial ;
58
71
} ) ;
59
72
} ) ;
73
+
74
+ describe ( 'set_response_object_md' , ( ) => {
75
+ it ( 'should return no restore status when restore_status is absent' , ( ) => {
76
+ const object_md = {
77
+ xattr : { }
78
+ } ;
79
+ const res = create_dummy_nb_response ( ) ;
80
+
81
+ // @ts -ignore
82
+ s3_utils . set_response_object_md ( res , object_md ) ;
83
+
84
+ expect ( res . headers [ 'x-amz-restore' ] ) . toBeUndefined ( ) ;
85
+ } ) ;
86
+
87
+ it ( 'should return restore status when restore is requested and ongoing' , ( ) => {
88
+ const object_md = {
89
+ xattr : { } ,
90
+ restore_status : {
91
+ ongoing : true ,
92
+ } ,
93
+ } ;
94
+ const res = create_dummy_nb_response ( ) ;
95
+
96
+ // @ts -ignore
97
+ s3_utils . set_response_object_md ( res , object_md ) ;
98
+
99
+ expect ( res . headers [ 'x-amz-restore' ] ) . toBeDefined ( ) ;
100
+ } ) ;
101
+
102
+ it ( 'should return restore status when restore is completed' , ( ) => {
103
+ const object_md = {
104
+ xattr : { } ,
105
+ restore_status : {
106
+ ongoing : false ,
107
+ expiry_time : new Date ( ) ,
108
+ } ,
109
+ } ;
110
+ const res = create_dummy_nb_response ( ) ;
111
+
112
+ // @ts -ignore
113
+ s3_utils . set_response_object_md ( res , object_md ) ;
114
+
115
+ expect ( res . headers [ 'x-amz-restore' ] ) . toBeDefined ( ) ;
116
+ } ) ;
117
+ } ) ;
60
118
} ) ;
0 commit comments