Project

General

Profile

Download (2.1 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / test / resources / settings_test.rb @ a2c97209

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
 --search SEARCH               Only export search results
24
 -h, --help                    print help
25
 -v, --verbose                 be verbose
26
HELP
27
      stop_vcr
28
    end
29

    
30
    def test_update_settings
31
      start_vcr
32
      set_user 'admin'
33

    
34
      name = "settings#{rand(10000)}"
35

    
36
      file = Tempfile.new('settings_test')
37
      # rubocop:disable LineLength
38
      file.write <<-FILE
39
Name,Count,Value
40
idle_timeout,1,60000
41
FILE
42
      file.rewind
43

    
44
      stdout,stderr = capture {
45
        hammer.run(%W{--reload-cache csv settings --verbose --file #{file.path}})
46
      }
47
      stderr.must_equal ''
48
      lines = stdout.split("\n")
49
      assert_equal "Updating setting 'idle_timeout'...done", lines[0]
50
      file.unlink
51
      stop_vcr
52
    end
53

    
54
    def test_update_settings_continue
55
      start_vcr
56
      set_user 'admin'
57

    
58
      name = "settings#{rand(10000)}"
59

    
60
      file = Tempfile.new('settings_test')
61
      # rubocop:disable LineLength
62
      file.write <<-FILE
63
Name,Count,Value
64
badsetting,1,1234
65
idle_timeout,1,60000
66
FILE
67
      file.rewind
68

    
69
      stdout,stderr = capture {
70
        hammer.run(%W{--reload-cache csv settings --verbose --continue-on-error --file #{file.path}})
71
      }
72
      stderr.must_equal "Error: Setting 'badsetting' not found\nbadsetting,1,1234\n"
73
      lines = stdout.split("\n")
74
      assert_equal lines[0], "Updating setting 'idle_timeout'...done"
75
      file.unlink
76
      stop_vcr
77
    end
78
  end
79

    
80
end