1
|
require './test/csv_test_helper'
|
2
|
require './lib/hammer_cli_csv'
|
3
|
|
4
|
module Resources
|
5
|
class TestSubnets < MiniTest::Unit::TestCase
|
6
|
def test_usage
|
7
|
start_vcr
|
8
|
set_user 'admin'
|
9
|
|
10
|
stdout,stderr = capture {
|
11
|
hammer.run(%W{--reload-cache csv subnets --help})
|
12
|
}
|
13
|
assert_equal '', stderr
|
14
|
assert_equal stdout, <<-HELP
|
15
|
**** This command is unsupported and is provided as tech preview. ****
|
16
|
Usage:
|
17
|
csv subnets [OPTIONS]
|
18
|
|
19
|
Options:
|
20
|
--continue-on-error Continue processing even if individual resource error
|
21
|
--export Export current data instead of importing
|
22
|
--file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required)
|
23
|
--organization ORGANIZATION Only process organization matching this name
|
24
|
-h, --help print help
|
25
|
-v, --verbose be verbose
|
26
|
HELP
|
27
|
stop_vcr
|
28
|
end
|
29
|
|
30
|
def test_update_subnets
|
31
|
start_vcr
|
32
|
set_user 'admin'
|
33
|
|
34
|
name = "settings#{rand(10000)}"
|
35
|
|
36
|
file = Tempfile.new('settings_test')
|
37
|
|
38
|
file.write <<-FILE
|
39
|
Name,Organizations,Locations,Network,Network Mask,Network Prefix,From,To,Domains,Gateway,DHCP Proxy,TFTP Proxy,DNS Proxy,DNS Primary,DNS Secondary,VLAN ID
|
40
|
Test Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,,"","",test.com,"","",,"","","",""
|
41
|
FILE
|
42
|
file.rewind
|
43
|
|
44
|
stdout,stderr = capture {
|
45
|
hammer.run(%W{--reload-cache csv subnets --verbose --file #{file.path}})
|
46
|
}
|
47
|
stderr.must_equal ''
|
48
|
lines = stdout.split("\n")
|
49
|
|
50
|
|
51
|
|
52
|
assert_match(/.*subnet 'Test Subnet'...done/, lines[0])
|
53
|
file.unlink
|
54
|
stop_vcr
|
55
|
end
|
56
|
|
57
|
def test_update_subnets_continue
|
58
|
start_vcr
|
59
|
set_user 'admin'
|
60
|
|
61
|
name = "settings#{rand(10000)}"
|
62
|
|
63
|
file = Tempfile.new('settings_test')
|
64
|
|
65
|
file.write <<-FILE
|
66
|
Name,Organizations,Locations,Network,Network Mask,Network Prefix,From,To,Domains,Gateway,DHCP Proxy,TFTP Proxy,DNS Proxy,DNS Primary,DNS Secondary,VLAN ID
|
67
|
Bad Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,24,bad,,test.com,"","",,"","","",""
|
68
|
Test Subnet,Test Corporation,Testing,192.168.100.1,255.255.255.0,24,"","",test.com,"","",,"","","",""
|
69
|
FILE
|
70
|
file.rewind
|
71
|
|
72
|
stdout,stderr = capture {
|
73
|
hammer.run(%W{--reload-cache csv subnets --verbose --continue-on-error --file #{file.path}})
|
74
|
}
|
75
|
lines = stderr.split("\n")
|
76
|
assert_equal "Error: 422 Unprocessable Entity", lines[0]
|
77
|
lines = stdout.split("\n")
|
78
|
assert_equal "Creating subnet 'Bad Subnet'...Updating subnet 'Test Subnet'...done", lines[0]
|
79
|
file.unlink
|
80
|
stop_vcr
|
81
|
end
|
82
|
end
|
83
|
end
|