1 | const chai = require('chai'),
|
2 | chaiHttp = require('chai-http'),
|
3 | should = chai.should(),
|
4 | BbPromise = require('bluebird'),
|
5 | fs = BbPromise.promisifyAll(require("fs-extra")),
|
6 | Azurite = require('./../lib/AzuriteBlob'),
|
7 | rp = require('request-promise'),
|
8 | path = require('path');
|
9 |
|
10 | chai.use(chaiHttp);
|
11 |
|
12 | const containerName = 'containertestcontainer';
|
13 | const propContainer = 'propTestcontainer';
|
14 | const url = 'http://localhost:10000';
|
15 | const urlPath = '/devstoreaccount1';
|
16 |
|
17 | describe('Container HTTP API', () => {
|
18 | const azurite = new Azurite();
|
19 |
|
20 | before(() => {
|
21 | const location = path.join('.', process.env.AZURITE_LOCATION, 'CONTAINER');
|
22 | return azurite.init({ l: location, silent: 'true', overwrite: 'true' })
|
23 | .then(() => {
|
24 |
|
25 | const optionsContainer = {
|
26 | method: 'PUT',
|
27 | uri: `http://localhost:10000/devstoreaccount1/${propContainer}?restype=container`,
|
28 | body: ''
|
29 | };
|
30 | return rp(optionsContainer);
|
31 | });
|
32 | });
|
33 |
|
34 | after(() => {
|
35 | return azurite.close();
|
36 | });
|
37 |
|
38 |
|
39 |
|
40 | describe('PUT Simple Container', () => {
|
41 | it('should create a container', () => {
|
42 | return chai.request(url)
|
43 | .put(`${urlPath}/${containerName}`)
|
44 | .query({ restype: 'container' })
|
45 | .then((res) => {
|
46 | res.should.have.status(201);
|
47 | });
|
48 | });
|
49 | it('and a second with the same name that fails', () => {
|
50 | return chai.request(url)
|
51 | .put(`${urlPath}/${containerName}`)
|
52 | .query({ restype: 'container' })
|
53 | .catch((e) => {
|
54 | e.should.have.status(409);
|
55 | })
|
56 | });
|
57 | });
|
58 | describe('DELETE Simple Container', () => {
|
59 | it('successfully deletes the container', () => {
|
60 | return chai.request(url)
|
61 | .delete(`${urlPath}/${containerName}`)
|
62 | .query({ restype: 'container' })
|
63 | .then((res) => {
|
64 | res.should.have.status(202);
|
65 | });
|
66 | });
|
67 | it('deleting a non-existant container fails', () => {
|
68 | return chai.request(url)
|
69 | .delete(`${urlPath}/DOESNOTEXIST`)
|
70 | .query({ restype: 'container' })
|
71 | .catch((e) => {
|
72 | e.should.have.status(404);
|
73 | });
|
74 | });
|
75 | });
|
76 | describe('Container Metadata', () => {
|
77 | it('should update an existing container with metadata.', () => {
|
78 | return chai.request(url)
|
79 | .put(`${urlPath}/${propContainer}`)
|
80 | .query({ restype: 'container', comp: 'metadata' })
|
81 | .set('x-ms-meta-test1', 'value1')
|
82 | .set('x-ms-meta-test2', 'value2')
|
83 | .set('x-ms-meta-meta1', 'meta1Value')
|
84 | .then((res) => {
|
85 | res.should.have.status(200);
|
86 | });
|
87 | });
|
88 | it('should get the correct metadata. (GET)', () => {
|
89 | return chai.request(url)
|
90 | .get(`${urlPath}/${propContainer}`)
|
91 | .query({ restype: 'container', comp: 'metadata' })
|
92 | .then((res) => {
|
93 | res.should.have.status(200);
|
94 | res.should.have.header('x-ms-meta-test1', 'value1');
|
95 | res.should.have.header('x-ms-meta-test2', 'value2');
|
96 | res.should.have.header('x-ms-meta-meta1', 'meta1Value');
|
97 | res.should.have.header('Last-Modified');
|
98 | res.should.have.header('ETag');
|
99 | });
|
100 | });
|
101 | it('should get the correct metadata. (HEAD)', () => {
|
102 | return chai.request(url)
|
103 | .head(`${urlPath}/${propContainer}`)
|
104 | .query({ restype: 'container', comp: 'metadata' })
|
105 | .then((res) => {
|
106 | res.should.have.status(200);
|
107 | res.should.have.header('x-ms-meta-test1', 'value1');
|
108 | res.should.have.header('x-ms-meta-test2', 'value2');
|
109 | res.should.have.header('x-ms-meta-meta1', 'meta1Value');
|
110 | res.should.have.header('Last-Modified');
|
111 | res.should.have.header('ETag');
|
112 | });
|
113 | });
|
114 | it('should fail to get metadata of a non-existant container (GET)', () => {
|
115 | return chai.request(url)
|
116 | .get(`${urlPath}/CONTAINER_DOESNOTEXIST`)
|
117 | .query({ restype: 'container', comp: 'metadata' })
|
118 | .catch((e) => {
|
119 | e.should.have.status(404);
|
120 | });
|
121 | });
|
122 | it('should fail to get metadata of a non-existant container (HEAD)', () => {
|
123 | return chai.request(url)
|
124 | .head(`${urlPath}/CONTAINER_DOESNOTEXIST`)
|
125 | .query({ restype: 'container', comp: 'metadata' })
|
126 | .catch((e) => {
|
127 | e.should.have.status(404);
|
128 | });
|
129 | });
|
130 | });
|
131 | describe('Container System Properties', () => {
|
132 | it('should update an existing container with metadata.', () => {
|
133 | return chai.request(url)
|
134 | .put(`${urlPath}/${propContainer}`)
|
135 | .query({ restype: 'container', comp: 'metadata' })
|
136 | .set('x-ms-meta-test1', 'value1')
|
137 | .set('x-ms-meta-test2', 'value2')
|
138 | .set('x-ms-meta-meta1', 'meta1Value')
|
139 | .then((res) => {
|
140 | res.should.have.status(200);
|
141 | });
|
142 | });
|
143 | it('should get the correct metadata. (GET)', () => {
|
144 | return chai.request(url)
|
145 | .get(`${urlPath}/${propContainer}`)
|
146 | .query({ restype: 'container' })
|
147 | .then((res) => {
|
148 | res.should.have.status(200);
|
149 | res.should.have.header('x-ms-meta-test1', 'value1');
|
150 | res.should.have.header('x-ms-meta-test2', 'value2');
|
151 | res.should.have.header('x-ms-meta-meta1', 'meta1Value');
|
152 | res.should.have.header('Last-Modified');
|
153 | res.should.have.header('ETag');
|
154 | });
|
155 | });
|
156 | it('should get the correct metadata. (HEAD)', () => {
|
157 | return chai.request(url)
|
158 | .head(`${urlPath}/${propContainer}`)
|
159 | .query({ restype: 'container' })
|
160 | .then((res) => {
|
161 | res.should.have.status(200);
|
162 | res.should.have.header('x-ms-meta-test1', 'value1');
|
163 | res.should.have.header('x-ms-meta-test2', 'value2');
|
164 | res.should.have.header('x-ms-meta-meta1', 'meta1Value');
|
165 | res.should.have.header('Last-Modified');
|
166 | res.should.have.header('ETag');
|
167 | });
|
168 | });
|
169 | it('should fail to get metadata of a non-existant container (GET)', () => {
|
170 | return chai.request(url)
|
171 | .get(`${urlPath}/CONTAINER_DOESNOTEXIST`)
|
172 | .query({ restype: 'container' })
|
173 | .catch((e) => {
|
174 | e.should.have.status(404);
|
175 | });
|
176 | });
|
177 | it('should fail to get metadata of a non-existant container (HEAD)', () => {
|
178 | return chai.request(url)
|
179 | .head(`${urlPath}/CONTAINER_DOESNOTEXIST`)
|
180 | .query({ restype: 'container' })
|
181 | .catch((e) => {
|
182 | e.should.have.status(404);
|
183 | });
|
184 | });
|
185 | });
|
186 | }); |
\ | No newline at end of file |