vagrant-hmurca 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,96 @@
1
+ module Vagrant
2
+ module Hmurca
3
+ # Public: General error.
4
+ class Error
5
+ end
6
+
7
+ # Public: General parser error.
8
+ class ParserError < Booby::Error
9
+ end
10
+
11
+ # Public: Error raised when invalid domain name is being specified.
12
+ class InvalidDomainNameError < ParserError
13
+ def initialize(domain, line_no)
14
+ super("Invalid domain name (line #{line_no}): #{domain}")
15
+ end
16
+ end
17
+
18
+ # Public: Error raised when synced folder doesn't exist.
19
+ class SyncedFolderNotFoundError < ParserError
20
+ def initialize(folder, line_no)
21
+ super("Synced folder does not exist (line #{line_no}): #{folder}")
22
+ end
23
+ end
24
+
25
+ # Public: Error raised when invalid boolean value given.
26
+ class InvalidBooleanValueError < ParserError
27
+ def initialize(value, line_no)
28
+ super(
29
+ "Invalid boolean value (line #{line_no}): " +
30
+ "expected yes or no, got #{value}"
31
+ )
32
+ end
33
+ end
34
+
35
+ # Public: Error raised when invalid integer value given.
36
+ class InvalidIntegerValueError < ParserError
37
+ def initialize(value, line_no)
38
+ super("Invalid integer value (line #{line_no}): #{value}")
39
+ end
40
+ end
41
+
42
+ # Public: Error raised when given node name is invalid.
43
+ class InvalidNodeNameError < ParserError
44
+ def initialize(name, line_no)
45
+ super(
46
+ "Invalid node name (line #{line_no}): expected only letters, digits "+
47
+ "and dash symbols, got #{name}"
48
+ )
49
+ end
50
+ end
51
+
52
+ # Public: Error raised when no domain is specified in config file.
53
+ class NoDomainSpecifiedError < ParserError
54
+ def initialize
55
+ super("No `domain' option specified in config file.")
56
+ end
57
+ end
58
+
59
+ # Public: Error raised when name of node is not specified.
60
+ class NoNodeNameSpecifiedError < ParserError
61
+ def initialize
62
+ super("No `name' option specified for one of nodes in config file.")
63
+ end
64
+ end
65
+
66
+ # Public: Error raised when no cpus count of node is specified in
67
+ # config file.
68
+ class NoNodeCpusCountSpecifiedError < ParserError
69
+ def initialize(node)
70
+ super("No `cpus' option specified for node #{node} in config file.")
71
+ end
72
+ end
73
+
74
+ # Public: Error raised when no memory size of node is specified in
75
+ # config file.
76
+ class NoNodeMemorySizeSpecifiedError < ParserError
77
+ def initialize(node)
78
+ super("No `memory' option specified for node #{node} in config file.")
79
+ end
80
+ end
81
+
82
+ # Public: Error raised when node name is duplicated across the config file.
83
+ class NodeDuplicatedError < ParserError
84
+ def initialize(node)
85
+ super("Duplicated node #{node} in config file.")
86
+ end
87
+ end
88
+
89
+ # Public: Error raised when node name is duplicated across the config file.
90
+ class NodeForwardPortDuplicatedError < ParserError
91
+ def initialize(port)
92
+ super("Duplicated host's port #{port} in one of `forward-port` options.")
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,15 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # WARNING: Never ever edit this file if you want Hmurca Kit to work properly!
5
+
6
+ ui = Vagrant::UI::Colored.new
7
+
8
+ begin
9
+ require 'vagrant-hmurca'
10
+ Vagrant::Hmurca.configure!
11
+ rescue LoadError => err
12
+ ui.error("Oops! Looks like `vagrant-hmurca' plugin is not installed!")
13
+ ui.error("Execute `vagrant plugin install vagrant-hmurca` to fix this error...")
14
+ exit(1)
15
+ end
@@ -0,0 +1,2 @@
1
+ .vagrant
2
+ *.conf.sample
@@ -0,0 +1,32 @@
1
+ # hmurca.conf - The Hmurca Vagrant Kit configuration file.
2
+ #
3
+ # If this file is named `hmurca.conf.sample`, copy it to `hmurca.conf`
4
+ # and adjust settings specific for your host machine or your own preferences.
5
+
6
+ # General setup
7
+ #-------------------------------------------------------------------------------
8
+
9
+ # Domain name used by this formation.
10
+ domain <%= domain %>
11
+
12
+ # Name of the base box from Vagrant Cloud.
13
+ base-box hmurca/debian75-x64
14
+
15
+ # Configure synchronized folders from host to guests...
16
+ sync-folder . /vagrant
17
+
18
+ # Use Network File System to share folders?
19
+ use-nfs yes
20
+
21
+ # Nodes configuration...
22
+ #-------------------------------------------------------------------------------
23
+
24
+ node
25
+ # Short host name of the node.
26
+ name all-in-one
27
+ # The number of virtual processors.
28
+ cpus 2
29
+ # The number of virtual memory limit.
30
+ memory 1024
31
+ # Configure which ports to forward from guest to host...
32
+ forward-port 80 8080
@@ -0,0 +1,36 @@
1
+ Vagrant.configure("2") do |config|
2
+ sync_folder_opts = {}
3
+ sync_folder_opts.merge({:type => "nfs", :udp => true}) if $CONF.use_nfs
4
+
5
+ config.vm.box = $CONF.base_box
6
+ config.vm.synced_folder ".", "/vagrant", sync_folder_opts
7
+
8
+ config.ssh.forward_agent = true
9
+
10
+ $CONF.sync_folders.each do |(host, guest)|
11
+ config.vm.synced_folder host, guest, sync_folder_opts
12
+ end
13
+
14
+ $CONF.nodes.each_with_index do |node, i|
15
+ config.vm.define node.name do |node_config|
16
+ node_config.vm.network :private_network, ip: "172.16.0.#{20 + i + 1}"
17
+ node_config.vm.hostname = "#{node.name}.#{$CONF.domain}"
18
+
19
+ node.forward_ports.each do |host, guest|
20
+ node_config.vm.network("forwarded_port", {
21
+ :guest => guest.to_i,
22
+ :host => host.to_i
23
+ })
24
+ end
25
+
26
+ node_config.vm.provider :virtualbox do |vm|
27
+ vm.name = [ $CONF.name_as_prefix, node.name ].join('.')
28
+
29
+ vm.customize([ "modifyvm", :id, "--memory", node.memory ])
30
+ vm.customize([ "modifyvm", :id, "--cpus", node.cpus ])
31
+ vm.customize([ "modifyvm", :id, "--natdnshostresolver1", "on" ])
32
+ vm.customize([ "modifyvm", :id, "--natdnsproxy1", "on" ])
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Hmurca
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,590 @@
1
+ require File.expand_path("../helper.rb", __FILE__)
2
+
3
+ include Vagrant::Hmurca
4
+
5
+ INVALID_DOMAIN_FILE = <<END
6
+ domain inv$li%
7
+ END
8
+
9
+ EMPTY_DOMAIN_FILE = <<END
10
+ domain
11
+ END
12
+
13
+ MISSING_DOMAIN_FILE = <<END
14
+ base-box foo/bar
15
+ sync-folder . /vagrant
16
+ END
17
+
18
+ VALID_DOMAIN_FILE_1 = <<END
19
+ domain sub.hello.com
20
+ END
21
+
22
+ VALID_DOMAIN_FILE_2 = <<END
23
+ domain hello.com
24
+ END
25
+
26
+ MULTI_DOMAIN_FILE = <<END
27
+ domain hello.com sub.hello.com
28
+ END
29
+
30
+ EMPTY_BASE_BOX_FILE = <<END
31
+ domain hello.com
32
+ base-box
33
+ END
34
+
35
+ VALID_BASE_BOX_FILE = <<END
36
+ domain hello.com
37
+ base-box test/test
38
+ END
39
+
40
+ EMPTY_SYNC_FOLDER_FILE = <<END
41
+ domain hello.com
42
+ base-box test/test
43
+ sync-folder
44
+ END
45
+
46
+ INVALID_SYNC_FOLDER_FILE = <<END
47
+ domain hello.com
48
+ base-box test/test
49
+ sync-folder /tmp /foo /bar
50
+ END
51
+
52
+ NOT_FOUND_SYNC_FOLDER_FILE = <<END
53
+ domain hello.com
54
+ base-box test/test
55
+ sync-folder not-found-folder /vagrant
56
+ END
57
+
58
+ VALID_SYNC_FOLDER_FILE = <<END
59
+ domain hello.com
60
+ base-box test/test
61
+ sync-folder . /vagrant
62
+ END
63
+
64
+ VALID_MULTI_SYNC_FOLDER_FILE = <<END
65
+ domain hello.com
66
+ base-box test/test
67
+ sync-folder . /vagrant
68
+ sync-folder ./lib /tmp/lib
69
+ END
70
+
71
+ EMPTY_USE_NFS_FILE = <<END
72
+ domain hello.com
73
+ base-box test/test
74
+ use-nfs
75
+ END
76
+
77
+ INVALID_USE_NFS_FILE = <<END
78
+ domain hello.com
79
+ base-box test/test
80
+ use-nfs foobar
81
+ END
82
+
83
+ YES_USE_NFS_FILE = <<END
84
+ domain hello.com
85
+ base-box test/test
86
+ use-nfs yes
87
+ END
88
+
89
+ NO_USE_NFS_FILE = <<END
90
+ domain hello.com
91
+ base-box test/test
92
+ use-nfs no
93
+ END
94
+
95
+ NODE_GROUP_MISSING_NAME_FILE = <<END
96
+ domain hello.com
97
+ base-box test/test
98
+
99
+ node
100
+ cpus 1
101
+ memory 512
102
+ END
103
+
104
+ NODE_GROUP_MISSING_CPUS_FILE = <<END
105
+ domain hello.com
106
+ base-box test/test
107
+
108
+ node
109
+ name test
110
+ memory 512
111
+ END
112
+
113
+ NODE_GROUP_MISSING_MEMORY_FILE = <<END
114
+ domain hello.com
115
+ base-box test/test
116
+
117
+ node
118
+ name test
119
+ cpus 1
120
+ END
121
+
122
+ NODE_GROUP_EMPTY_NAME_FILE = <<END
123
+ domain hello.com
124
+ base-box test/test
125
+
126
+ node
127
+ name
128
+ cpus 1
129
+ memory 512
130
+ END
131
+
132
+ NODE_GROUP_INVALID_NAME_FILE = <<END
133
+ domain hello.com
134
+ base-box test/test
135
+
136
+ node
137
+ name inv%li$
138
+ cpus 1
139
+ memory 512
140
+ END
141
+
142
+ NODE_GROUP_VALID_FILE = <<END
143
+ domain hello.com
144
+ base-box test/test
145
+
146
+ node
147
+ name test
148
+ cpus 1
149
+ memory 512
150
+ END
151
+
152
+ NODE_GROUP_VALID_SHORTCUT_NAME_FILE = <<END
153
+ domain hello.com
154
+ base-box test/test
155
+
156
+ node test
157
+ cpus 1
158
+ memory 512
159
+ END
160
+
161
+ NODE_GROUP_INVALID_SHORTCUT_NAME_FILE = <<END
162
+ domain hello.com
163
+ base-box test/test
164
+
165
+ node inv%li$
166
+ cpus 1
167
+ memory 512
168
+ END
169
+
170
+ NODE_GROUP_INVALID_SHORTCUT_NAME_PARAMS_FILE = <<END
171
+ domain hello.com
172
+ base-box test/test
173
+
174
+ node foo bar baz
175
+ cpus 1
176
+ memory 512
177
+ END
178
+
179
+ NODE_GROUP_EMPTY_CPUS_FILE = <<END
180
+ domain hello.com
181
+ base-box test/test
182
+
183
+ node
184
+ name test
185
+ cpus
186
+ memory 512
187
+ END
188
+
189
+ NODE_GROUP_INVALID_CPUS_FILE = <<END
190
+ domain hello.com
191
+ base-box test/test
192
+
193
+ node
194
+ name test
195
+ cpus invalid
196
+ memory 512
197
+ END
198
+
199
+ NODE_GROUP_EMPTY_MEMORY_FILE = <<END
200
+ domain hello.com
201
+ base-box test/test
202
+
203
+ node
204
+ name test
205
+ cpus 1
206
+ memory
207
+ END
208
+
209
+ NODE_GROUP_INVALID_MEMORY_FILE = <<END
210
+ domain hello.com
211
+ base-box test/test
212
+
213
+ node
214
+ name test
215
+ cpus 1
216
+ memory invalid
217
+ END
218
+
219
+ NODE_GROUP_VALID_MULTIPLE_FILE = <<END
220
+ domain hello.com
221
+ base-box test/test
222
+
223
+ node
224
+ name test1
225
+ cpus 1
226
+ memory 512
227
+
228
+ node test2
229
+ cpus 2
230
+ memory 512
231
+ END
232
+
233
+ NODE_GROUP_VALID_MULTIPLE_DUPLICATES_FILE = <<END
234
+ domain hello.com
235
+ base-box test/test
236
+
237
+ node
238
+ name test1
239
+ cpus 1
240
+ memory 512
241
+
242
+ node test1
243
+ cpus 2
244
+ memory 512
245
+ END
246
+
247
+ NODE_GROUP_EMPTY_FORWARD_PORT_FILE = <<END
248
+ domain hello.com
249
+ base-box test/test
250
+
251
+ node
252
+ name test
253
+ cpus 1
254
+ memory 512
255
+ forward-port
256
+ END
257
+
258
+ NODE_GROUP_INVALID_FORWARD_PORT_FILE_1 = <<END
259
+ domain hello.com
260
+ base-box test/test
261
+
262
+ node
263
+ name test
264
+ cpus 1
265
+ memory 512
266
+ forward-port 1000
267
+ END
268
+
269
+ NODE_GROUP_INVALID_FORWARD_PORT_FILE_2 = <<END
270
+ domain hello.com
271
+ base-box test/test
272
+
273
+ node
274
+ name test
275
+ cpus 1
276
+ memory 512
277
+ forward-port 1000 3000 4000
278
+ END
279
+
280
+ NODE_GROUP_INVALID_FORWARD_PORT_FILE_3 = <<END
281
+ domain hello.com
282
+ base-box test/test
283
+
284
+ node
285
+ name test
286
+ cpus 1
287
+ memory 512
288
+ forward-port 1000 invalid
289
+ END
290
+
291
+ NODE_GROUP_VALID_FORWARD_PORT_FILE = <<END
292
+ domain hello.com
293
+ base-box test/test
294
+
295
+ node
296
+ name test
297
+ cpus 1
298
+ memory 512
299
+ forward-port 3000 13000
300
+ END
301
+
302
+ NODE_GROUP_VALID_FORWARD_PORT_MULTIPLE_FILE = <<END
303
+ domain hello.com
304
+ base-box test/test
305
+
306
+ node
307
+ name test
308
+ cpus 1
309
+ memory 512
310
+ forward-port 3000 13000
311
+ forward-port 4000 14000
312
+ END
313
+
314
+ NODE_GROUP_VALID_FORWARD_PORT_DUPLICATES_FILE_1 = <<END
315
+ domain hello.com
316
+ base-box test/test
317
+
318
+ node
319
+ name test
320
+ cpus 1
321
+ memory 512
322
+ forward-port 3000 13000
323
+ forward-port 4000 13000
324
+ END
325
+
326
+ NODE_GROUP_VALID_FORWARD_PORT_DUPLICATES_FILE_2 = <<END
327
+ domain hello.com
328
+ base-box test/test
329
+
330
+ node
331
+ name test1
332
+ cpus 1
333
+ memory 512
334
+ forward-port 3000 13000
335
+ forward-port 4000 14000
336
+
337
+ node test2
338
+ cpus 2
339
+ memory 512
340
+ forward-port 4000 13000
341
+ END
342
+
343
+ class TestConfigParser < Minitest::Test
344
+ def test_invalid_domain_option
345
+ assert_raises InvalidDomainNameError do
346
+ ConfigParser.parse_string(INVALID_DOMAIN_FILE)
347
+ end
348
+ end
349
+
350
+ def test_empty_domain_option
351
+ assert_raises Booby::InvalidNumberOfParametersError do
352
+ ConfigParser.parse_string(EMPTY_DOMAIN_FILE)
353
+ end
354
+ end
355
+
356
+ def test_missing_domain_option
357
+ assert_raises NoDomainSpecifiedError do
358
+ ConfigParser.parse_string(MISSING_DOMAIN_FILE)
359
+ end
360
+ end
361
+
362
+ def test_too_many_domain_args
363
+ assert_raises Booby::InvalidNumberOfParametersError do
364
+ ConfigParser.parse_string(MULTI_DOMAIN_FILE)
365
+ end
366
+ end
367
+
368
+ def test_valid_domain_option
369
+ res = ConfigParser.parse_string(VALID_DOMAIN_FILE_1)
370
+ assert_equal "sub.hello.com", res.domain
371
+ res = ConfigParser.parse_string(VALID_DOMAIN_FILE_2)
372
+ assert_equal "hello.com", res.domain
373
+ end
374
+
375
+ def test_empty_base_box
376
+ assert_raises Booby::InvalidNumberOfParametersError do
377
+ ConfigParser.parse_string(EMPTY_BASE_BOX_FILE)
378
+ end
379
+ end
380
+
381
+ def test_valid_base_box
382
+ res = ConfigParser.parse_string(VALID_BASE_BOX_FILE)
383
+ assert_equal "test/test", res.base_box
384
+ end
385
+
386
+ def test_invalid_sync_folder
387
+ assert_raises Booby::InvalidNumberOfParametersError do
388
+ ConfigParser.parse_string(EMPTY_SYNC_FOLDER_FILE)
389
+ end
390
+ assert_raises Booby::InvalidNumberOfParametersError do
391
+ ConfigParser.parse_string(INVALID_SYNC_FOLDER_FILE)
392
+ end
393
+ end
394
+
395
+ def test_not_found_sync_folder
396
+ assert_raises SyncedFolderNotFoundError do
397
+ ConfigParser.parse_string(NOT_FOUND_SYNC_FOLDER_FILE)
398
+ end
399
+ end
400
+
401
+ def test_valid_sync_folder
402
+ res = ConfigParser.parse_string(VALID_SYNC_FOLDER_FILE)
403
+ assert_equal 1, res.sync_folders.size
404
+ assert_equal %w{. /vagrant}, res.sync_folders.first
405
+ end
406
+
407
+ def test_multiple_valid_sync_folder
408
+ res = ConfigParser.parse_string(VALID_MULTI_SYNC_FOLDER_FILE)
409
+ assert_equal 2, res.sync_folders.size
410
+ assert_equal %w{. /vagrant}, res.sync_folders[0]
411
+ assert_equal %w{./lib /tmp/lib}, res.sync_folders[1]
412
+ end
413
+
414
+ def test_empty_use_nfs
415
+ assert_raises Booby::InvalidNumberOfParametersError do
416
+ ConfigParser.parse_string(EMPTY_USE_NFS_FILE)
417
+ end
418
+ end
419
+
420
+ def test_invalid_use_nfs
421
+ assert_raises InvalidBooleanValueError do
422
+ ConfigParser.parse_string(INVALID_USE_NFS_FILE)
423
+ end
424
+ end
425
+
426
+ def test_use_nfs_yes
427
+ res = ConfigParser.parse_string(YES_USE_NFS_FILE)
428
+ assert_equal true, res.use_nfs
429
+ end
430
+
431
+ def test_use_nfs_no
432
+ res = ConfigParser.parse_string(NO_USE_NFS_FILE)
433
+ assert_equal false, res.use_nfs
434
+ end
435
+
436
+ def test_missing_node_name_option
437
+ assert_raises NoNodeNameSpecifiedError do
438
+ ConfigParser.parse_string(NODE_GROUP_MISSING_NAME_FILE)
439
+ end
440
+ end
441
+
442
+ def test_node_group_missing_cpus_option
443
+ assert_raises NoNodeCpusCountSpecifiedError do
444
+ ConfigParser.parse_string(NODE_GROUP_MISSING_CPUS_FILE)
445
+ end
446
+ end
447
+
448
+ def test_node_group_missing_memory_option
449
+ assert_raises NoNodeMemorySizeSpecifiedError do
450
+ ConfigParser.parse_string(NODE_GROUP_MISSING_MEMORY_FILE)
451
+ end
452
+ end
453
+
454
+ def test_node_group_empty_name
455
+ assert_raises Booby::InvalidNumberOfParametersError do
456
+ ConfigParser.parse_string(NODE_GROUP_EMPTY_NAME_FILE)
457
+ end
458
+ end
459
+
460
+ def test_node_group_invalid_name
461
+ assert_raises InvalidNodeNameError do
462
+ ConfigParser.parse_string(NODE_GROUP_INVALID_NAME_FILE)
463
+ end
464
+ end
465
+
466
+ def test_node_group_valid_name
467
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_FILE)
468
+ assert_equal "test", res.nodes[0].name
469
+ end
470
+
471
+ def test_node_group_empty_cpus
472
+ assert_raises Booby::InvalidNumberOfParametersError do
473
+ ConfigParser.parse_string(NODE_GROUP_EMPTY_CPUS_FILE)
474
+ end
475
+ end
476
+
477
+ def test_node_group_invalid_cpus
478
+ assert_raises InvalidIntegerValueError do
479
+ ConfigParser.parse_string(NODE_GROUP_INVALID_CPUS_FILE)
480
+ end
481
+ end
482
+
483
+ def test_node_group_valid_cpus
484
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_FILE)
485
+ assert_equal 1, res.nodes[0].cpus
486
+ end
487
+
488
+ def test_node_group_empty_memory
489
+ assert_raises Booby::InvalidNumberOfParametersError do
490
+ ConfigParser.parse_string(NODE_GROUP_EMPTY_MEMORY_FILE)
491
+ end
492
+ end
493
+
494
+ def test_node_group_invalid_memory
495
+ assert_raises InvalidIntegerValueError do
496
+ ConfigParser.parse_string(NODE_GROUP_INVALID_MEMORY_FILE)
497
+ end
498
+ end
499
+
500
+ def test_node_group_valid_memory
501
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_FILE)
502
+ assert_equal 512, res.nodes[0].memory
503
+ end
504
+
505
+
506
+ def test_node_group_invalid_shortcut_name
507
+ assert_raises InvalidNodeNameError do
508
+ ConfigParser.parse_string(NODE_GROUP_INVALID_SHORTCUT_NAME_FILE)
509
+ end
510
+ end
511
+
512
+ def test_node_group_invalid_shortcut_name_params
513
+ assert_raises Booby::InvalidNumberOfParametersError do
514
+ ConfigParser.parse_string(NODE_GROUP_INVALID_SHORTCUT_NAME_PARAMS_FILE)
515
+ end
516
+ end
517
+
518
+ def test_node_group_valid_shortcut_name
519
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_SHORTCUT_NAME_FILE)
520
+ assert_equal "test", res.nodes[0].name
521
+ end
522
+
523
+ def test_node_group_valid_multiple
524
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_MULTIPLE_FILE)
525
+ assert_equal "test1", res.nodes[0].name
526
+ assert_equal "test2", res.nodes[1].name
527
+ end
528
+
529
+ def test_node_group_multiple_duplicates
530
+ assert_raises NodeDuplicatedError do
531
+ ConfigParser.parse_string(NODE_GROUP_VALID_MULTIPLE_DUPLICATES_FILE)
532
+ end
533
+ end
534
+
535
+ def test_node_group_empty_forward_port
536
+ assert_raises Booby::InvalidNumberOfParametersError do
537
+ ConfigParser.parse_string(NODE_GROUP_EMPTY_FORWARD_PORT_FILE)
538
+ end
539
+ end
540
+
541
+ def test_node_group_invalid_forward_port_params
542
+ assert_raises Booby::InvalidNumberOfParametersError do
543
+ ConfigParser.parse_string(NODE_GROUP_INVALID_FORWARD_PORT_FILE_1)
544
+ end
545
+ assert_raises Booby::InvalidNumberOfParametersError do
546
+ ConfigParser.parse_string(NODE_GROUP_INVALID_FORWARD_PORT_FILE_2)
547
+ end
548
+ end
549
+
550
+ def test_node_group_invalid_forward_port
551
+ assert_raises InvalidIntegerValueError do
552
+ ConfigParser.parse_string(NODE_GROUP_INVALID_FORWARD_PORT_FILE_3)
553
+ end
554
+ end
555
+
556
+ def test_node_group_valid_forward_port
557
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_FORWARD_PORT_FILE)
558
+ assert_equal 3000, res.nodes[0].forward_ports[13000]
559
+ end
560
+
561
+ def test_node_group_valid_multiple_forward_port
562
+ res = ConfigParser.parse_string(NODE_GROUP_VALID_FORWARD_PORT_MULTIPLE_FILE)
563
+ assert_equal 3000, res.nodes[0].forward_ports[13000]
564
+ assert_equal 4000, res.nodes[0].forward_ports[14000]
565
+ end
566
+
567
+ def test_node_group_duplidated_forward_port
568
+ assert_raises NodeForwardPortDuplicatedError do
569
+ ConfigParser.parse_string(NODE_GROUP_VALID_FORWARD_PORT_DUPLICATES_FILE_1)
570
+ end
571
+ assert_raises NodeForwardPortDuplicatedError do
572
+ ConfigParser.parse_string(NODE_GROUP_VALID_FORWARD_PORT_DUPLICATES_FILE_2)
573
+ end
574
+ end
575
+
576
+ def test_parse_file
577
+ testfile = File.join($test_tmp_dir, "test.conf")
578
+ File.open(testfile, "w+") { |f| f.puts(NODE_GROUP_VALID_FILE) }
579
+ res = ConfigParser.parse_file(testfile)
580
+ assert_equal "test", res.nodes[0].name
581
+ end
582
+
583
+ def test_name_as_prefix
584
+ p = GeneralProcessor.new
585
+ p.process(0, "domain", "domain.com")
586
+ assert_equal "com.domain", p.name_as_prefix
587
+ p.process(0, "domain", "sub.domain.com")
588
+ assert_equal "com.domain.sub", p.name_as_prefix
589
+ end
590
+ end