forked from dotnwat/lua-rados
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
296 lines (248 loc) · 7.93 KB
/
test.lua
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
local rados = require "rados"
describe("version", function()
local major, minor, extra
setup(function()
major, minor, extra = rados.version()
end)
it("returns three numeric values", function()
assert.is.number(major)
assert.is.number(minor)
assert.is.number(extra)
end)
it("returns a non-zero version part", function()
assert.is_true(major > 0 or minor > 0 or extra > 0)
end)
end)
describe("create", function()
it("excepts no id paraemter", function()
cluster = rados.create()
assert.is_userdata(cluster)
end)
it("excepts nil id paraemter", function()
cluster = rados.create(nil)
assert.is_userdata(cluster)
end)
it("excepts string id paraemter", function()
cluster = rados.create('admin')
assert.is_userdata(cluster)
end)
it("throws error on numeric parameter", function()
assert.error(function() rados.create(0) end)
end)
it("throws error on non string id paraemter", function()
assert.error(function() rados.create({}) end)
end)
end)
describe("cluster object", function()
local cluster_new, cluster_conn, cluster_down
before_each(function()
cluster_new = rados.create()
cluster_conn = rados.create()
cluster_conn:conf_read_file()
cluster_conn:connect()
cluster_down = rados.create()
cluster_down:conf_read_file()
cluster_down:connect()
cluster_down:shutdown()
end)
describe("connect method", function()
it("throws error if connected", function()
assert.error(function() cluster_conn:connect() end)
end)
it("throws error if shutdown", function()
assert.error(function() cluster_down:connect() end)
end)
end)
describe("shutdown method", function()
it("succeeds if connected", function()
cluster_conn:shutdown()
end)
it("throws error if not connected", function()
assert.error(function() cluster_new:shutdown() end)
end)
it("throws error if shutdown", function()
assert.error(function() cluster_down:shutdown() end)
end)
end)
describe("open_ioctx method", function()
it("returns a userdata object", function()
assert.is_userdata(cluster_conn:open_ioctx('data'))
end)
it("throws error without pool name", function()
assert.error(function() cluster_conn:open_ioctx() end)
end)
it("throws error with non-string param", function()
assert.error(function() cluster_conn:open_ioctx({}) end)
end)
it("returns nil for non-existent pools", function()
assert.is_nil(cluster_conn:open_ioctx(23423432))
assert.is_nil(cluster_conn:open_ioctx('asdlfk'))
end)
it("throws error if not connected", function()
assert.error(function() cluster_new:open_ioctx('data') end)
end)
it("throws error if shutdown", function()
assert.error(function() cluster_down:open_ioctx('data') end)
end)
end)
end)
describe("ioctx object", function()
local cluster, ioctx
before_each(function()
cluster = rados.create()
cluster:conf_read_file()
cluster:connect()
ioctx = cluster:open_ioctx('data')
end)
it("is usable if cluster ref disappears", function()
cluster = nil
collectgarbage()
local data = 'wkjeflkwjelfkjwelfkjwef'
assert.is_equal(#data, ioctx:write('oid', data, #data, 0))
end)
describe("write method", function()
it("returns number of bytes written", function()
local data = 'wkjeflkwjelfkjwelfkjwef'
assert.is_equal(#data, ioctx:write('oid', data, #data, 0))
end)
end)
describe("read method", function()
it("will read what has been written", function()
local data = 'whoopie doo'
ioctx:write('oid', data, #data, 0);
assert.is_equal(data, ioctx:read('oid', #data, 0))
end)
end)
describe("stat method", function()
it("returns size and last modify time of object", function()
local data = 'wkjeflkwjelfkjwelfkjwef'
local length, mtime
ioctx:write('oid', data, #data, 0);
length, mtime = ioctx:stat('oid')
assert.is_equal(#data, length)
end)
end)
describe("setxattr method", function()
it("throws error with non-string object name", function()
assert.error(function()
ioctx:setxattr({}, 'name', 'data', #'data')
end)
assert.error(function()
ioctx:setxattr(nil, 'name', 'data', #'data')
end)
end)
it("throws error with non-string xattr name", function()
assert.error(function()
ioctx:setxattr('oid', {}, 'data', #'data')
end)
assert.error(function()
ioctx:setxattr('oid', nil, 'data', #'data')
end)
end)
it("throws error with non-string buffer", function()
assert.error(function()
ioctx:setxattr('oid', 'name', {}, 0)
end)
end)
it("throws error with nil buffer", function()
assert.error(function()
ioctx:setxattr('oid', 'name', nil, 0)
end)
end)
it("throws error if length is negative", function()
assert.error(function()
ioctx:setxattr('oid', 'name', 'data', -1)
end)
end)
it("throws error if length is larger than buffer", function()
assert.error(function()
local data = 'data'
ioctx:setxattr('oid', 'name', data, #data+1)
end)
end)
it("returns number of bytes written to xattr", function()
local data = 'wkjeflkwjelfkjwelfkjwef'
local name = 'xattrset'
local length
length = ioctx:setxattr('oid', name, data, #data)
assert.is_equal(0, length)
end)
end)
describe("getxattr method", function()
it("throws error with non-string object name", function()
assert.error(function()
ioctx:getxattr({}, 'name', 'data', #'data')
end)
assert.error(function()
ioctx:getxattr(nil, 'name', 'data', #'data')
end)
end)
it("throws error with non-string xattr name", function()
assert.error(function()
ioctx:getxattr('oid', {}, 'data', #'data')
end)
assert.error(function()
ioctx:getxattr('oid', nil, 'data', #'data')
end)
end)
it("will read xattr", function()
local data = 'wkjeflkwjelfkjwelfkjwef'
local name = 'xattrget'
ioctx:setxattr('oid', name, data, #data)
assert.is_equal(data, ioctx:getxattr('oid',name))
end)
end)
describe("exec", function()
it("throws error if length is negative", function()
assert.error(function()
ioctx:exec('oid', 'cls', 'method', 'data', -1)
end)
end)
it("throws error if length is larger than buffer", function()
assert.error(function()
local data = 'data'
ioctx:exec('oid', 'cls', 'method', data, #data+1)
end)
end)
it("throws error with non-string object name", function()
assert.error(function()
ioctx:exec({}, 'cls', 'method', 'data', #'data')
end)
assert.error(function()
ioctx:exec(nil, 'cls', 'method', 'data', #'data')
end)
end)
it("throws error with non-string class name", function()
assert.error(function()
ioctx:exec('oid', {}, 'method', 'data', #'data')
end)
assert.error(function()
ioctx:exec('oid', nil, 'method', 'data', #'data')
end)
end)
it("throws error with non-string method name", function()
assert.error(function()
ioctx:exec('oid', 'cls', {}, 'data', #'data')
end)
assert.error(function()
ioctx:exec('oid', 'cls', nil, 'data', #'data')
end)
end)
it("throws error with non-string buffer", function()
assert.error(function()
ioctx:exec('oid', 'cls', 'method', {}, #'data')
end)
end)
it("throws error if nil buf and positive length", function()
assert.error(function()
ioctx:exec('oid', 'cls', 'method', nil, 1)
end)
end)
pending("pass the echo test", function()
local indata = 'asldjflkasjdlfkjasdf'
ret, outdata = ioctx:exec('oid', 'echo', 'echo', indata, #indata)
assert.is_equal(ret, #indata)
assert.is_equal(outdata, indata)
end)
end)
end)