staf4ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +58 -0
- data/ext/extconf.rb +19 -0
- data/ext/staf4ruby_ext.c +270 -0
- data/lib/staf4ruby.rb +564 -0
- data/test/test.rb +662 -0
- data/test/test_helper.rb +12 -0
- metadata +52 -0
data/test/test.rb
ADDED
@@ -0,0 +1,662 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
##############################################################################
|
3
|
+
# Copyright (c) 2013 Spectra Logic corp
|
4
|
+
# All rights reserved. This program and the accompanying materials
|
5
|
+
# are made available under the terms of the Eclipse Public License v1.0
|
6
|
+
# which accompanies this distribution, and is available at
|
7
|
+
# http://www.eclipse.org/legal/epl-v10.html
|
8
|
+
##############################################################################
|
9
|
+
|
10
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
11
|
+
require 'rbconfig'
|
12
|
+
require 'test/unit'
|
13
|
+
|
14
|
+
require 'staf4ruby'
|
15
|
+
|
16
|
+
module Staf
|
17
|
+
|
18
|
+
class TestHandleRegister < Test::Unit::TestCase
|
19
|
+
def setup
|
20
|
+
@handle = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
if @handle
|
25
|
+
@handle.unregister
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_ConstructWithStandardHandle_neg1
|
30
|
+
# Should get an error when passing an integer as a Standard handle
|
31
|
+
assert_raises(TypeError) do
|
32
|
+
@handle = STAFHandle.new(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_ConstructWithStaticHandle_neg1
|
37
|
+
# Should get an error when passing a string as a static handle
|
38
|
+
assert_raises(TypeError) do
|
39
|
+
@handle = STAFHandle.new("MyHandle", STAFHandle::Static)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_ConstructWithStandardHandle_pos1
|
44
|
+
assert_nothing_raised() do
|
45
|
+
@handle = STAFHandle.new("test_ConstructWithStandardHandle_pos1")
|
46
|
+
assert @handle.is_a? STAFHandle
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class TestSubmitWithStandardHandle < Test::Unit::TestCase
|
52
|
+
def setup
|
53
|
+
@handle = STAFHandle.new("TestSubmitWithStandardHandle")
|
54
|
+
end
|
55
|
+
|
56
|
+
def teardown
|
57
|
+
if @handle
|
58
|
+
@handle.unregister
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_doUnmarshallingResultDefault
|
63
|
+
assert @handle.doUnmarshallResult
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_ping
|
67
|
+
result = @handle.submit("local", "ping", "ping")
|
68
|
+
assert_equal(STAFResult::Ok, result.rc)
|
69
|
+
assert_equal("PONG", result.result)
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_var_resolve_string
|
73
|
+
result = @handle.submit("local", "var", "resolve string {STAF/Config/MachineNickname}")
|
74
|
+
assert_equal(STAFResult::Ok, result.rc)
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_os_name
|
78
|
+
result = @handle.submit("local", "var", "resolve string {STAF/Config/OS/Name}")
|
79
|
+
assert_equal(STAFResult::Ok, result.rc)
|
80
|
+
known_os_names = ["FreeBSD", "Linux"]
|
81
|
+
assert known_os_names.include?(result.result)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class TestSubmitWithStaticHandle < Test::Unit::TestCase
|
86
|
+
def setup
|
87
|
+
@standard_handle = STAFHandle.new("TestSubmitWithStaticHandle1")
|
88
|
+
result = @standard_handle.submit("local", "HANDLE", "CREATE HANDLE NAME TestSubmitWithStaticHandle2");
|
89
|
+
assert_equal(STAFResult::Ok, result.rc)
|
90
|
+
@static_handle_number = result.result.to_i
|
91
|
+
assert @static_handle_number.is_a? Integer
|
92
|
+
@static_handle = STAFHandle.new(@static_handle_number, STAFHandle::Static)
|
93
|
+
assert_equal(STAFHandle::Static, @static_handle.handleType)
|
94
|
+
end
|
95
|
+
|
96
|
+
def teardown
|
97
|
+
if @static_handle
|
98
|
+
result = @static_handle.submit("local", "HANDLE", "DELETE HANDLE #{@static_handle_number}")
|
99
|
+
assert_equal STAFResult::Ok, result.rc
|
100
|
+
rc = @static_handle.unregister
|
101
|
+
assert_equal(STAFResult::Ok, rc)
|
102
|
+
@static_handle = nil
|
103
|
+
end
|
104
|
+
if @standard_handle
|
105
|
+
rc = @standard_handle.unregister
|
106
|
+
assert_equal(STAFResult::Ok, rc)
|
107
|
+
@standard_handle = nil
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_ping
|
112
|
+
result = @static_handle.submit("local", "ping", "ping")
|
113
|
+
assert_equal(STAFResult::Ok, result.rc)
|
114
|
+
assert_equal("PONG", result.result)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_doUnmarshallingResultDefault
|
118
|
+
assert @static_handle.doUnmarshallResult
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_query_after_delete
|
122
|
+
# Delete the static handle, then verify that requests that attempt to use
|
123
|
+
# it fail. We must then unregister the static_handle so the teardown
|
124
|
+
# method does not raise an exception.
|
125
|
+
result = @static_handle.submit("local", "HANDLE", "DELETE HANDLE #{@static_handle_number}")
|
126
|
+
assert_equal STAFResult::Ok, result.rc
|
127
|
+
result = @static_handle.submit("local", "HANDLE", "QUERY HANDLE #{@static_handle_number}")
|
128
|
+
assert_equal STAFResult::HandleDoesNotExist, result.rc
|
129
|
+
@static_handle.unregister
|
130
|
+
@static_handle = nil
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
class TestDoUnmarshallResult < Test::Unit::TestCase
|
135
|
+
def setup
|
136
|
+
@handle = STAFHandle.new("TestSubmitWithStandardHandle")
|
137
|
+
end
|
138
|
+
|
139
|
+
def teardown
|
140
|
+
if @handle
|
141
|
+
@handle.unregister
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def do_false
|
146
|
+
assert_equal @handle.doUnmarshallResult, false
|
147
|
+
result = @handle.submit("local", "MISC", "WHOAMI")
|
148
|
+
assert_equal STAFResult::Ok, result.rc
|
149
|
+
assert_equal nil, result.resultContext
|
150
|
+
assert_equal nil, result.resultObj
|
151
|
+
end
|
152
|
+
|
153
|
+
def do_true
|
154
|
+
assert_equal @handle.doUnmarshallResult, true
|
155
|
+
result = @handle.submit("local", "MISC", "WHOAMI")
|
156
|
+
assert_equal STAFResult::Ok, result.rc
|
157
|
+
assert_equal result.resultContext.rootObject, Staf::unmarshall(result.result).rootObject
|
158
|
+
assert_equal result.resultObj, Staf::unmarshall(result.result).rootObject()
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_blank
|
162
|
+
@handle.setDoUnmarshallResult ""
|
163
|
+
do_false
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_default
|
167
|
+
do_true
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_one
|
171
|
+
@handle.setDoUnmarshallResult 1
|
172
|
+
do_true
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_true
|
176
|
+
@handle.setDoUnmarshallResult true
|
177
|
+
do_true
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_zero
|
181
|
+
@handle.setDoUnmarshallResult 0
|
182
|
+
do_false
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
class TestLogService < Test::Unit::TestCase
|
188
|
+
#TODO: implement the STAFLog class for the bindings to be complete
|
189
|
+
#SpectraLogic doesn't need it, though.
|
190
|
+
end
|
191
|
+
|
192
|
+
class TestMarshall < Test::Unit::TestCase
|
193
|
+
# Test the marshall function
|
194
|
+
def test_array
|
195
|
+
expected = "@SDT/[3:33:@SDT/$S:1:1@SDT/$S:1:2@SDT/$S:1:3"
|
196
|
+
assert_equal expected, Staf.marshall([1,2,3])
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_hash1
|
200
|
+
assert_equal "@SDT/{:15::1:1@SDT/$S:1:2", Staf::marshall({1 => 2})
|
201
|
+
end
|
202
|
+
|
203
|
+
def test_hash2
|
204
|
+
data = {1 => 3, 33 => 789}
|
205
|
+
expected = "@SDT/{:33::1:1@SDT/$S:1:3:2:33@SDT/$S:3:789"
|
206
|
+
assert_equal expected, Staf::marshall(data)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_int
|
210
|
+
assert_equal "@SDT/$S:1:1", Staf::marshall(1)
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_nil
|
214
|
+
assert_equal '@SDT/$0:0:', Staf::marshall(nil)
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_string
|
218
|
+
assert_equal "@SDT/$S:3:abc", Staf::marshall("abc")
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_composite
|
222
|
+
# Note, this test relies on the ordered-hash feature of ruby 1.9 and
|
223
|
+
# later. It may fail on older versions of ruby.
|
224
|
+
myTestMap = {
|
225
|
+
'outputs' => ['TestA.out', 'TestA.err'],
|
226
|
+
'testType' => 'FVT',
|
227
|
+
'name' => 'TestA', 'exec' => '/tests/TestA.py',
|
228
|
+
}
|
229
|
+
marshalledResult = Staf::marshall(myTestMap)
|
230
|
+
expectedResult = (
|
231
|
+
"@SDT/{:138::7:outputs@SDT/[2:38:@SDT/$S:9:TestA.out" +
|
232
|
+
"@SDT/$S:9:TestA.err:8:testType@SDT/$S:3:FVT:4:name" +
|
233
|
+
"@SDT/$S:5:TestA:4:exec@SDT/$S:15:/tests/TestA.py")
|
234
|
+
assert_equal expectedResult, marshalledResult
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
class TestUnMarshall < Test::Unit::TestCase
|
239
|
+
def test_array
|
240
|
+
data = "@SDT/[3:33:@SDT/$S:1:1@SDT/$S:1:2@SDT/$S:1:3"
|
241
|
+
expected = ["1","2","3"]
|
242
|
+
assert_equal expected, Staf.unmarshall(data).rootObject
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_hash1
|
246
|
+
data = "@SDT/{:15::1:1@SDT/$S:1:2"
|
247
|
+
expected = {"1" => "2"}
|
248
|
+
assert_equal expected, Staf.unmarshall(data).rootObject
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_hash2
|
252
|
+
expected = {"1" => "3", "33" => "789"}
|
253
|
+
data = "@SDT/{:33::1:1@SDT/$S:1:3:2:33@SDT/$S:3:789"
|
254
|
+
assert_equal expected, Staf.unmarshall(data).rootObject
|
255
|
+
end
|
256
|
+
|
257
|
+
def test_int
|
258
|
+
assert_equal 1.to_s, Staf::unmarshall("@SDT/$S:1:1").rootObject
|
259
|
+
end
|
260
|
+
|
261
|
+
def test_nil
|
262
|
+
assert_equal nil.to_s, Staf::unmarshall('@SDT/$0:0:').rootObject
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_string
|
266
|
+
data = "@SDT/$S:3:abc"
|
267
|
+
expected = "abc"
|
268
|
+
assert_equal expected, Staf::unmarshall(data).rootObject
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_composite
|
272
|
+
# Note, this test relies on the ordered-hash feature of ruby 1.9 and
|
273
|
+
# later. It may fail on older versions of ruby.
|
274
|
+
expected = {
|
275
|
+
'outputs' => ['TestA.out', 'TestA.err'],
|
276
|
+
'testType' => 'FVT',
|
277
|
+
'name' => 'TestA', 'exec' => '/tests/TestA.py',
|
278
|
+
}
|
279
|
+
data = (
|
280
|
+
"@SDT/{:138::7:outputs@SDT/[2:38:@SDT/$S:9:TestA.out" +
|
281
|
+
"@SDT/$S:9:TestA.err:8:testType@SDT/$S:3:FVT:4:name" +
|
282
|
+
"@SDT/$S:5:TestA:4:exec@SDT/$S:15:/tests/TestA.py")
|
283
|
+
assert_equal expected, Staf::unmarshall(data).rootObject
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_context
|
287
|
+
myMapClassDef = STAFMapClassDefinition.new('Test/MyMap')
|
288
|
+
myMapClassDef.addKey('name', 'Name')
|
289
|
+
myMapClassDef.addKey('exec', 'Executable')
|
290
|
+
|
291
|
+
testList = [
|
292
|
+
{'name' => 'TestA', 'exec' => '/tests/TestA.py'},
|
293
|
+
{'name' => 'TestB', 'exec' => '/tests/TestB.sh'},
|
294
|
+
{'name' => 'TestC', 'exec' => '/tests/TestC.cmd'}
|
295
|
+
]
|
296
|
+
|
297
|
+
mc = STAFMarshallingContext.new()
|
298
|
+
mc.setMapClassDefinition(myMapClassDef)
|
299
|
+
|
300
|
+
myTestList = []
|
301
|
+
|
302
|
+
for test in testList
|
303
|
+
testMap = myMapClassDef.createInstance()
|
304
|
+
testMap['name'] = test['name']
|
305
|
+
testMap['exec'] = test['exec']
|
306
|
+
myTestList << testMap
|
307
|
+
end
|
308
|
+
|
309
|
+
mc.rootObject = myTestList
|
310
|
+
message = Staf::marshall(mc)
|
311
|
+
mc2 = Staf::unmarshall(message)
|
312
|
+
mc2.rootObject
|
313
|
+
|
314
|
+
assert_equal mc.mapClassMap, mc2.mapClassMap
|
315
|
+
assert_equal mc.rootObject, mc2.rootObject
|
316
|
+
end
|
317
|
+
|
318
|
+
# Test unmarshalling the output of
|
319
|
+
# "staf local process start command whoami wait returnresult returnstderr"
|
320
|
+
def test_process_whoami
|
321
|
+
data = "@SDT/*:826:@SDT/{:587::13:map-class-map@SDT/{:559::35:STAF/Service/Process/CompletionInfo@SDT/{:261::4:keys@SDT/[3:189:@SDT/{:56::12:display-name@SDT/$S:11:Return Code:3:key@SDT/$S:2:rc@SDT/{:48::12:display-name@SDT/$S:3:Key:3:key@SDT/$S:3:key@SDT/{:55::12:display-name@SDT/$S:5:Files:3:key@SDT/$S:8:fileList:4:name@SDT/$S:35:STAF/Service/Process/CompletionInfo:35:STAF/Service/Process/ReturnFileInfo@SDT/{:198::4:keys@SDT/[2:126:@SDT/{:56::12:display-name@SDT/$S:11:Return Code:3:key@SDT/$S:2:rc@SDT/{:50::12:display-name@SDT/$S:4:Data:3:key@SDT/$S:4:data:4:name@SDT/$S:35:STAF/Service/Process/ReturnFileInfo@SDT/%:217::35:STAF/Service/Process/CompletionInfo@SDT/$S:1:0@SDT/$0:0:@SDT/[2:145:@SDT/%:65::35:STAF/Service/Process/ReturnFileInfo@SDT/$S:1:0@SDT/$S:5:root\n@SDT/%:60::35:STAF/Service/Process/ReturnFileInfo@SDT/$S:1:0@SDT/$S:0:"
|
322
|
+
assert_equal "root\n", Staf::unmarshall(data).rootObject["fileList"][0]["data"]
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
class TestUnMarshallQuery < Test::Unit::TestCase
|
327
|
+
def setup
|
328
|
+
@handle = STAFHandle.new("TestSubmitWithStandardHandle")
|
329
|
+
@myTestMap = {'name' => 'TestA', 'exec' => '/tests/TestA.py',
|
330
|
+
'testType' => 'FVT',
|
331
|
+
'outputs' => ['TestA.out', 'TestA.err']}
|
332
|
+
end
|
333
|
+
|
334
|
+
def teardown
|
335
|
+
if @handle
|
336
|
+
@handle.unregister
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_fs_query
|
341
|
+
filename = "{STAF/Config/ConfigFile}"
|
342
|
+
result = @handle.submit("local", "FS", "query entry #{filename}")
|
343
|
+
assert_equal STAFResult::Ok, result.rc
|
344
|
+
mc = Staf::unmarshall(result.result)
|
345
|
+
entryMap = mc.rootObject
|
346
|
+
assert_equal "F", entryMap['type']
|
347
|
+
assert (entryMap["lowerSize"].to_i > 0)
|
348
|
+
assert entryMap.has_key?('lastModifiedTimestamp')
|
349
|
+
end
|
350
|
+
|
351
|
+
# TODO: add a test for the IGNORE_INDIRECT_OBJECTS thing from TestPython.py
|
352
|
+
# at around lines 790 - 841. I didn't add it because I can't understand
|
353
|
+
# what the test is doing
|
354
|
+
|
355
|
+
def test_invalid_queue
|
356
|
+
# Create some invalid marshalling data and queue it; Get it off the
|
357
|
+
# queue (auto-unmarshalling will be done) and verify results in the
|
358
|
+
# invalid marshalling data string in the message
|
359
|
+
message = (
|
360
|
+
"@SDT/{:177::2:RC@SDT/$S:1:0:6:IPInfo@SDT/$S:36:" +
|
361
|
+
"9.42.126.76|255.255.252.0|9.42.124.1:3:Msg@SDT/$S:46:Static IP " +
|
362
|
+
"arguments are processed " +
|
363
|
+
"successfully:9:Timestamp@SDT/$S:19:2009-01-16 14:41:45" +
|
364
|
+
"Connecting to: http://9.42.106.28:8080")
|
365
|
+
result = @handle.submit('local', 'queue', "queue message #{message}")
|
366
|
+
assert_equal STAFResult::Ok, result.rc
|
367
|
+
result = @handle.submit("local", "queue", "get wait 5000")
|
368
|
+
assert_equal STAFResult::Ok, result.rc
|
369
|
+
messageMap = result.resultObj
|
370
|
+
assert_equal message, messageMap['message']
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_valid_queue
|
374
|
+
#XXX: this test uses the public STAF queue. Other running processes could
|
375
|
+
#interfere with this test. It really ought to be using a private STAF
|
376
|
+
#instance name
|
377
|
+
msg = Staf::marshall(@myTestMap)
|
378
|
+
result = @handle.submit("local", "queue", "queue message #{msg}")
|
379
|
+
assert_equal STAFResult::Ok, result.rc
|
380
|
+
result = @handle.submit("local", "queue", "get wait 5000")
|
381
|
+
assert_equal STAFResult::Ok, result.rc
|
382
|
+
mc = Staf::unmarshall(result.result)
|
383
|
+
yourTestMap = mc.rootObject["message"]
|
384
|
+
assert_equal @myTestMap, yourTestMap
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
module MapClassHelper
|
389
|
+
def mapClassHelperSetup
|
390
|
+
@mapClassDefName = "Test/MyMap"
|
391
|
+
@mapClassDef = STAFMapClassDefinition.new(@mapClassDefName)
|
392
|
+
@mapClassDef.addKey("name", "Name")
|
393
|
+
@mapClassDef.addKey("exec", "Executable")
|
394
|
+
@mapClassDef.addKey("testType", "Test Type")
|
395
|
+
@mapClassDef.setKeyProperty("testType", "display-short-name", "test")
|
396
|
+
@mapClassDef.addKey("outputs", "Outputs")
|
397
|
+
@expectedKeyMap = [
|
398
|
+
{'display-name' => 'Name', 'key' => 'name'},
|
399
|
+
{'display-name' => 'Executable', 'key' => 'exec'},
|
400
|
+
{'display-name' => 'Test Type', 'key' => 'testType',
|
401
|
+
'display-short-name' => 'test'},
|
402
|
+
{'display-name' => 'Outputs', 'key' => 'outputs'}
|
403
|
+
]
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
class TestMapClass < Test::Unit::TestCase
|
408
|
+
include MapClassHelper
|
409
|
+
def setup
|
410
|
+
mapClassHelperSetup
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_keys
|
414
|
+
assert_equal @expectedKeyMap, @mapClassDef.keys
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_mapClass
|
418
|
+
expectedMapClass = {
|
419
|
+
'keys' => @expectedKeyMap,
|
420
|
+
'name' => @mapClassDefName
|
421
|
+
}
|
422
|
+
assert_equal expectedMapClass, @mapClassDef.mapClassDef
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_mapClassDefName
|
426
|
+
assert_equal @mapClassDefName, @mapClassDef.name
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
class TestStafMarshallingContext < Test::Unit::TestCase
|
431
|
+
include MapClassHelper
|
432
|
+
def setup
|
433
|
+
mapClassHelperSetup
|
434
|
+
@mc = STAFMarshallingContext.new
|
435
|
+
@mc.setMapClassDefinition(@mapClassDef)
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_hasMapClassDefinition
|
439
|
+
assert @mc.hasMapClassDefinition('Test/MyMap')
|
440
|
+
end
|
441
|
+
|
442
|
+
def test_keys
|
443
|
+
assert_equal @expectedKeyMap, @mc.getMapClassDefinition('Test/MyMap').keys
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_mapClass
|
447
|
+
expectedMapClass = {
|
448
|
+
'keys' => @expectedKeyMap,
|
449
|
+
'name' => @mapClassDefName
|
450
|
+
}
|
451
|
+
assert_equal expectedMapClass, @mc.getMapClassDefinition('Test/MyMap').mapClassDef
|
452
|
+
end
|
453
|
+
|
454
|
+
def test_mapClassDefinitionIterator
|
455
|
+
assert_equal ['Test/MyMap'], @mc.mapClassDefinitionIterator
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
class TestStafMarshallingContextRootObject < Test::Unit::TestCase
|
460
|
+
include MapClassHelper
|
461
|
+
def setup
|
462
|
+
mapClassHelperSetup
|
463
|
+
@mc = STAFMarshallingContext.new
|
464
|
+
@mc.setMapClassDefinition(@mapClassDef)
|
465
|
+
@myTestMap = {
|
466
|
+
'name'=> 'TestA',
|
467
|
+
'outputs'=> ['TestA.out', 'TestA.err'],
|
468
|
+
'exec'=> '/tests/TestA.py',
|
469
|
+
'testType'=> 'FVT',
|
470
|
+
}
|
471
|
+
@marshalledResult = Staf::marshall(@myTestMap)
|
472
|
+
@mc.rootObject = @myTestMap
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_isMarshalledData_neg
|
476
|
+
assert (not Staf::isMarshalledData('xyz'))
|
477
|
+
assert (not @mc.isMarshalledData('xyz'))
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_isMarshalledData_pos
|
481
|
+
assert @mc.isMarshalledData(@marshalledResult)
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_marshall
|
485
|
+
expectedResult = (
|
486
|
+
"@SDT/*:558:" +
|
487
|
+
"@SDT/{:398:" +
|
488
|
+
":13:map-class-map" +
|
489
|
+
"@SDT/{:370:" +
|
490
|
+
":10:Test/MyMap" +
|
491
|
+
"@SDT/{:345:" +
|
492
|
+
":4:name" +
|
493
|
+
"@SDT/$S:10:Test/MyMap" +
|
494
|
+
":4:keys" +
|
495
|
+
"@SDT/[4:298:" +
|
496
|
+
"@SDT/{:50:" +
|
497
|
+
":3:key" +
|
498
|
+
"@SDT/$S:4:name" +
|
499
|
+
":12:display-name" +
|
500
|
+
"@SDT/$S:4:Name" +
|
501
|
+
"@SDT/{:57:" +
|
502
|
+
":3:key" +
|
503
|
+
"@SDT/$S:4:exec" +
|
504
|
+
":12:display-name" +
|
505
|
+
"@SDT/$S:10:Executable" +
|
506
|
+
"@SDT/{:95:" +
|
507
|
+
":3:key" +
|
508
|
+
"@SDT/$S:8:testType" +
|
509
|
+
":12:display-name" +
|
510
|
+
"@SDT/$S:9:Test Type" +
|
511
|
+
":18:display-short-name" +
|
512
|
+
"@SDT/$S:4:test" +
|
513
|
+
"@SDT/{:56:" +
|
514
|
+
":3:key" +
|
515
|
+
"@SDT/$S:7:outputs" +
|
516
|
+
":12:display-name" +
|
517
|
+
"@SDT/$S:7:Outputs" +
|
518
|
+
"@SDT/{:138:" +
|
519
|
+
":4:name" +
|
520
|
+
"@SDT/$S:5:TestA" +
|
521
|
+
":7:outputs" +
|
522
|
+
"@SDT/[2:38:" +
|
523
|
+
"@SDT/$S:9:TestA.out" +
|
524
|
+
"@SDT/$S:9:TestA.err" +
|
525
|
+
":4:exec" +
|
526
|
+
"@SDT/$S:15:/tests/TestA.py" +
|
527
|
+
":8:testType" +
|
528
|
+
"@SDT/$S:3:FVT")
|
529
|
+
assert_equal expectedResult, Staf::marshall(@mc, @mc)
|
530
|
+
assert_equal expectedResult, @mc.marshall
|
531
|
+
end
|
532
|
+
|
533
|
+
def test_primaryObject
|
534
|
+
assert_equal @mc, @mc.getPrimaryObject
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_rootObj
|
538
|
+
assert_equal @myTestMap, @mc.rootObject
|
539
|
+
end
|
540
|
+
|
541
|
+
def test_unmarshall
|
542
|
+
assert_equal @myTestMap, Staf::unmarshall(@mc.marshall).rootObject
|
543
|
+
end
|
544
|
+
|
545
|
+
# TODO: add tests for mc.to_s and mc.inspect
|
546
|
+
end
|
547
|
+
|
548
|
+
class TestStafMarshallingContextClone < Test::Unit::TestCase
|
549
|
+
include MapClassHelper
|
550
|
+
def setup
|
551
|
+
mapClassHelperSetup
|
552
|
+
@mc = STAFMarshallingContext.new
|
553
|
+
@mc.setMapClassDefinition(@mapClassDef)
|
554
|
+
@myTestMap = {
|
555
|
+
'name'=> 'TestA',
|
556
|
+
'outputs'=> ['TestA.out', 'TestA.err'],
|
557
|
+
'exec'=> '/tests/TestA.py',
|
558
|
+
'testType'=> 'FVT',
|
559
|
+
}
|
560
|
+
@marshalledResult = Staf::marshall(@myTestMap)
|
561
|
+
@mc.rootObject = @myTestMap
|
562
|
+
@mc2 = STAFMarshallingContext.new(@myTestMap, @mc.mapClassMap)
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_hasMapClassDefinition
|
566
|
+
assert @mc2.hasMapClassDefinition('Test/MyMap')
|
567
|
+
end
|
568
|
+
|
569
|
+
def test_rootObj
|
570
|
+
assert_equal @myTestMap, @mc2.rootObject
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
|
575
|
+
class TestMonitor < Test::Unit::TestCase
|
576
|
+
#TODO: implement the STAFMonitor class for the bindings to be complete
|
577
|
+
#SpectraLogic doesn't need it, though.
|
578
|
+
end
|
579
|
+
|
580
|
+
|
581
|
+
class TestPrivateData < Test::Unit::TestCase
|
582
|
+
def all_privacy_removed(data)
|
583
|
+
escapedData = Staf::escapePrivacyDelimiters(data)[1]
|
584
|
+
dataWithPrivacy = Staf::addPrivacyDelimiters(escapedData)[1]
|
585
|
+
dataWithAllPrivacyRemoved =
|
586
|
+
Staf::removePrivacyDelimiters(dataWithPrivacy, 0)[1]
|
587
|
+
assert_equal data, dataWithAllPrivacyRemoved
|
588
|
+
end
|
589
|
+
|
590
|
+
def privacy_removed(data)
|
591
|
+
escapedData = Staf::escapePrivacyDelimiters(data)[1]
|
592
|
+
dataWithPrivacy = Staf::addPrivacyDelimiters(escapedData)[1]
|
593
|
+
dataWithPrivacyRemoved =
|
594
|
+
Staf::removePrivacyDelimiters(dataWithPrivacy, 1)[1]
|
595
|
+
assert_equal data, dataWithPrivacyRemoved
|
596
|
+
end
|
597
|
+
|
598
|
+
def do_test(data)
|
599
|
+
# privacy_removed(data)
|
600
|
+
all_privacy_removed(data)
|
601
|
+
end
|
602
|
+
|
603
|
+
def test_secret
|
604
|
+
do_test("secret")
|
605
|
+
end
|
606
|
+
|
607
|
+
def test_privatesecret
|
608
|
+
do_test("!!@secret@!!")
|
609
|
+
end
|
610
|
+
|
611
|
+
def test_pw
|
612
|
+
do_test('Pw: !!@pw@!!')
|
613
|
+
end
|
614
|
+
|
615
|
+
def test_escaped_secret
|
616
|
+
do_test('^!!@secret@!!')
|
617
|
+
end
|
618
|
+
|
619
|
+
def test_escaped_secret2
|
620
|
+
do_test('^!!@secret^@!!')
|
621
|
+
end
|
622
|
+
|
623
|
+
def test_halfprivate_secret
|
624
|
+
do_test('!!@secret')
|
625
|
+
end
|
626
|
+
|
627
|
+
def test_halfprivate_secret2
|
628
|
+
do_test('!!@secret^@!!')
|
629
|
+
end
|
630
|
+
|
631
|
+
def test_pw2
|
632
|
+
do_test('Pw1=%s, Pw2=%s.' % [Staf::addPrivacyDelimiters('a')[1],
|
633
|
+
Staf::addPrivacyDelimiters('pw')[1]])
|
634
|
+
end
|
635
|
+
|
636
|
+
def test_caret_ab
|
637
|
+
do_test('^%s^%s' % [Staf::addPrivacyDelimiters('a')[1],
|
638
|
+
Staf::addPrivacyDelimiters('b')[1]])
|
639
|
+
end
|
640
|
+
|
641
|
+
def test_poorly_nested
|
642
|
+
do_test('Pw1=!!@secret, !!@pw@!!.')
|
643
|
+
end
|
644
|
+
|
645
|
+
def test_poorly_nested2
|
646
|
+
do_test('Pw1=!!@secret@!!, !!@pw.')
|
647
|
+
end
|
648
|
+
|
649
|
+
def test_nested
|
650
|
+
do_test('Msg: !!@Pw: ^!!@pw^@!!@!!')
|
651
|
+
end
|
652
|
+
|
653
|
+
def test_nested2
|
654
|
+
do_test('@!!a!!@b@!!')
|
655
|
+
end
|
656
|
+
|
657
|
+
def test_empty
|
658
|
+
do_test ''
|
659
|
+
end
|
660
|
+
|
661
|
+
end
|
662
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
##############################################################################
|
2
|
+
# Copyright (c) 2013 Spectra Logic corp
|
3
|
+
# All rights reserved. This program and the accompanying materials
|
4
|
+
# are made available under the terms of the Eclipse Public License v1.0
|
5
|
+
# which accompanies this distribution, and is available at
|
6
|
+
# http://www.eclipse.org/legal/epl-v10.html
|
7
|
+
##############################################################################
|
8
|
+
|
9
|
+
if ENV["COVERAGE"]
|
10
|
+
require 'simplecov'
|
11
|
+
SimpleCov.start
|
12
|
+
end
|