Project

General

Profile

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

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

1
require './test/csv_test_helper'
2
require './lib/hammer_cli_csv'
3

    
4
module Resources
5
  class TestSettingsUsage < 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
  end
29

    
30
  class TestSettingsImport < MiniTest::Unit::TestCase
31
    def test_update_settings
32
      start_vcr
33
      set_user 'admin'
34

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

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

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

    
55
    def test_update_settings_continue
56
      start_vcr
57
      set_user 'admin'
58

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

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

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

    
81
end