This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
/
testcopyfile.js
166 lines (163 loc) · 7 KB
/
testcopyfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
Copyright (c) 2011-2012 VMware, Inc.
put_hdrs = [ 'cache-control', 'content-disposition', 'content-encoding', 'content-length',
'content-type', 'expires'];
copy_hdrs = [ 'x-amz-copy-source-if-match', 'x-amz-copy-source-if-none-match',
'x-amz-copy-source-if-unmodified-since', 'x-amz-copy-source-if-modified-since',
'x-amz-metadata-directive', 'x-amz-storage-class'];
*/
var util = require('util');
var vows = require('vows');
var assert = require('assert');
var fs = require('fs');
var events = require('events');
var config = JSON.parse(require('./utils').execSync("curl http://localhost:9981/~config")); //must be the config you actually use for the vblob instance
var test_date = new Date().valueOf();
var container_name = '/sonic-test'+test_date;
var suite = vows.describe('testcopyfile: using container '+container_name+' against driver '+config['current_driver']+' on localhost:'+config.port);
var parse_xml = require('./utils').parse_xml;
var assertStatus = require('./utils').assertStatus;
var api = require('./utils').api;
var sax = require('sax');
var util = require('util');
var XMLNS = "http://s3.amazonaws.com/doc/2006-03-01/";
suite.addBatch({
'PUT container ' : {
topic: api.put(container_name),
'should respond with a 200 OK': assertStatus(200),
'should respond with the location of the container': function (err,res) {
assert.isString(res.headers['location']);
}
}
}).addBatch({
'PUT container/testcopyfile-1.txt': {
topic: api.put_data(container_name+'/testcopyfile-1.txt','./file1.txt',{
'cache-control':'No-cache', 'content-disposition':'attachment; filename=testing.txt',
'content-encoding':'x-gzip', 'content-type':'text/plain',
'expires':'Thu, 01 Dec 1994 16:00:00 GMT', 'x-amz-meta-hello':'world'
,'content-md5':'9M/h68wG3FYp6CT8mUV6rg=='
}),
'should respond with a 200 OK': assertStatus(200),
'should respond with the md5 hex of the file': function (err,res) {
assert.isString(res.headers.etag);
}
}
}).addBatch({
'REPLACE container/testcopyfile-2.txt': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'cache-control':'cache', 'content-disposition':'attachment; filename=copying.txt',
'content-encoding':'none', 'content-type':'text',
'expires':'Thu, 01 Dec 2011 16:00:00 GMT', 'x-amz-meta-hello':'hello',
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-metadata-directive':'REPLACE'
}),
'should respond with a 200 code': assertStatus(200),
'should respond with a copy message': function (err,res) {
assert.isNotNull(res.resp_body);
}
}
}).addBatch({
'GET 1 container/testcopyfile-2.txt': {
topic: api.get_data(container_name+'/testcopyfile-2.txt'),
'should respond with a 200 OK': assertStatus(200),
'should respond with the content of the file': function (err,res) {
var str1 = fs.readFileSync('./file1.txt');
assert.equal(str1,res.resp_body);
},
'should have correct meta info': function(err,res) {
assert.equal(res.headers['cache-control'],'cache');
assert.equal(res.headers['content-disposition'],'attachment; filename=copying.txt');
assert.equal(res.headers['content-encoding'],'none');
assert.equal(res.headers['content-type'],'text');
assert.equal(res.headers['expires'],'Thu, 01 Dec 2011 16:00:00 GMT');
assert.equal(res.headers['x-amz-meta-hello'],'hello');
}
}
}).addBatch({
'COPY container/testcopyfile-2.txt': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'cache-control':'cache', 'content-disposition':'attachment; filename=copying.txt',
'content-encoding':'none', 'content-type':'text',
'expires':'Thu, 01 Dec 2011 16:00:00 GMT', 'x-amz-meta-hello':'hello',
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-metadata-directive':'COPY'
}),
'should respond with a 200 code': assertStatus(200),
'should respond with a copy message': function (err,res) {
assert.isNotNull(res.resp_body);
}
}
}).addBatch({
'GET 2 container/testcopyfile-2.txt': {
topic: api.get_data(container_name+'/testcopyfile-2.txt'),
'should respond with a 200 OK': assertStatus(200),
'should respond with the content of the file': function (err,res) {
var str1 = fs.readFileSync('./file1.txt');
assert.equal(str1,res.resp_body);
},
'should have correct meta info': function(err,res) {
assert.equal(res.headers['cache-control'],'No-cache');
assert.equal(res.headers['content-disposition'],'attachment; filename=testing.txt');
assert.equal(res.headers['content-encoding'],'x-gzip');
assert.equal(res.headers['content-type'],'text/plain');
assert.equal(res.headers['expires'],'Thu, 01 Dec 1994 16:00:00 GMT');
assert.equal(res.headers['x-amz-meta-hello'],'world');
}
}
}).addBatch({
'COPY container/testcopyfile-2.txt if-unmodified-since past': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-copy-source-if-unmodified-since': new Date(new Date().valueOf()-500000).toUTCString()
}),
'should respond with a 412 code': assertStatus(412),
'should respond with an error message': function (err,res) {
assert.isObject(res.resp_body.Error);
}
},
'COPY container/testcopyfile-2.txt if-modified-since future': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-copy-source-if-modified-since': new Date(new Date().valueOf()+500000).toUTCString()
}),
'should respond with a 200 code': assertStatus(200)
},
'COPY container/testcopyfile-2.txt if-match': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-copy-source-if-match': 'f4cfe1ebcc06dc5629e824fc99457aae'
}),
'should respond with a 200 code': assertStatus(200)
},
'COPY container/testcopyfile-2.txt if-none-match': {
topic: api.put(container_name+'/testcopyfile-2.txt',{
'content-length' : 0,
'x-amz-copy-source': container_name+'/testcopyfile-1.txt',
'x-amz-copy-source-if-none-match': 'f4cfe1ebcc06dc5629e824fc99457aae'
}),
'should respond with a 412 code': assertStatus(412),
'should respond with an error message': function (err,res) {
assert.isObject(res.resp_body.Error);
}
}
}).addBatch({
'DELETE container/testcopyfile-1.txt' : {
topic: api.del(container_name+'/testcopyfile-1.txt'),
'should respond with a 204 OK': assertStatus(204)
},
'DELETE container/testcopyfile-2.txt' : {
topic: api.del(container_name+'/testcopyfile-2.txt'),
'should respond with a 204 OK': assertStatus(204)
}
}).addBatch({
'DELETE container' : {
topic: api.del(container_name),
'should respond with a 204 OK': assertStatus(204)
}
});
suite.export(module);