1
|
require './test/csv_test_helper'
|
2
|
require './lib/hammer_cli_csv'
|
3
|
|
4
|
module Resources
|
5
|
class TestSettings < 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 settings --help})
|
12
|
}
|
13
|
assert_equal '', stderr
|
14
|
assert_equal stdout, <<-HELP
|
15
|
Usage:
|
16
|
csv settings [OPTIONS]
|
17
|
|
18
|
Options:
|
19
|
--continue-on-error Continue processing even if individual resource error
|
20
|
--export Export current data instead of importing
|
21
|
--file FILE_NAME CSV file (default to /dev/stdout with --export, otherwise required)
|
22
|
--organization ORGANIZATION Only process organization matching this name
|
23
|
-h, --help print help
|
24
|
-v, --verbose be verbose
|
25
|
HELP
|
26
|
stop_vcr
|
27
|
end
|
28
|
|
29
|
def test_update_settings
|
30
|
start_vcr
|
31
|
set_user 'admin'
|
32
|
|
33
|
name = "settings#{rand(10000)}"
|
34
|
|
35
|
file = Tempfile.new('settings_test')
|
36
|
|
37
|
file.write <<-FILE
|
38
|
Name,Count,Value
|
39
|
idle_timeout,1,60000
|
40
|
FILE
|
41
|
file.rewind
|
42
|
|
43
|
stdout,stderr = capture {
|
44
|
hammer.run(%W{--reload-cache csv settings --verbose --file #{file.path}})
|
45
|
}
|
46
|
stderr.must_equal ''
|
47
|
lines = stdout.split("\n")
|
48
|
assert_equal "Updating setting 'idle_timeout'...done", lines[0]
|
49
|
file.unlink
|
50
|
stop_vcr
|
51
|
end
|
52
|
|
53
|
def test_update_settings_continue
|
54
|
start_vcr
|
55
|
set_user 'admin'
|
56
|
|
57
|
name = "settings#{rand(10000)}"
|
58
|
|
59
|
file = Tempfile.new('settings_test')
|
60
|
|
61
|
file.write <<-FILE
|
62
|
Name,Count,Value
|
63
|
badsetting,1,1234
|
64
|
idle_timeout,1,60000
|
65
|
FILE
|
66
|
file.rewind
|
67
|
|
68
|
stdout,stderr = capture {
|
69
|
hammer.run(%W{--reload-cache csv settings --verbose --continue-on-error --file #{file.path}})
|
70
|
}
|
71
|
stderr.must_equal "Error: Setting 'badsetting' not found\nbadsetting,1,1234\n"
|
72
|
lines = stdout.split("\n")
|
73
|
assert_equal lines[0], "Updating setting 'idle_timeout'...done"
|
74
|
file.unlink
|
75
|
stop_vcr
|
76
|
end
|
77
|
end
|
78
|
|
79
|
end
|