hammer_cli_csv 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -13
  2. data/config/cli_config.yml +9 -24
  3. data/lib/hammer_cli_csv/activation_keys.rb +220 -95
  4. data/lib/hammer_cli_csv/architectures.rb +7 -11
  5. data/lib/hammer_cli_csv/base.rb +67 -41
  6. data/lib/hammer_cli_csv/compute_profiles.rb +11 -15
  7. data/lib/hammer_cli_csv/compute_resources.rb +11 -15
  8. data/lib/hammer_cli_csv/containers.rb +10 -12
  9. data/lib/hammer_cli_csv/content_hosts.rb +285 -203
  10. data/lib/hammer_cli_csv/content_view_filters.rb +32 -36
  11. data/lib/hammer_cli_csv/content_views.rb +33 -37
  12. data/lib/hammer_cli_csv/csv.rb +17 -1
  13. data/lib/hammer_cli_csv/domains.rb +15 -19
  14. data/lib/hammer_cli_csv/export.rb +13 -5
  15. data/lib/hammer_cli_csv/host_collections.rb +20 -22
  16. data/lib/hammer_cli_csv/host_groups.rb +73 -65
  17. data/lib/hammer_cli_csv/hosts.rb +30 -34
  18. data/lib/hammer_cli_csv/import.rb +24 -10
  19. data/lib/hammer_cli_csv/installation_media.rb +74 -0
  20. data/lib/hammer_cli_csv/job_templates.rb +37 -41
  21. data/lib/hammer_cli_csv/lifecycle_environments.rb +15 -19
  22. data/lib/hammer_cli_csv/locations.rb +4 -6
  23. data/lib/hammer_cli_csv/operating_systems.rb +17 -21
  24. data/lib/hammer_cli_csv/organizations.rb +11 -13
  25. data/lib/hammer_cli_csv/partition_tables.rb +17 -21
  26. data/lib/hammer_cli_csv/products.rb +200 -92
  27. data/lib/hammer_cli_csv/provisioning_templates.rb +19 -23
  28. data/lib/hammer_cli_csv/puppet_environments.rb +8 -12
  29. data/lib/hammer_cli_csv/puppet_facts.rb +20 -24
  30. data/lib/hammer_cli_csv/puppet_reports.rb +47 -51
  31. data/lib/hammer_cli_csv/reports.rb +6 -10
  32. data/lib/hammer_cli_csv/roles.rb +12 -16
  33. data/lib/hammer_cli_csv/settings.rb +8 -6
  34. data/lib/hammer_cli_csv/smart_proxies.rb +9 -13
  35. data/lib/hammer_cli_csv/splice.rb +1 -3
  36. data/lib/hammer_cli_csv/subnets.rb +24 -28
  37. data/lib/hammer_cli_csv/subscriptions.rb +39 -91
  38. data/lib/hammer_cli_csv/sync_plans.rb +20 -24
  39. data/lib/hammer_cli_csv/users.rb +25 -29
  40. data/lib/hammer_cli_csv/utils/subscriptions.rb +130 -0
  41. data/lib/hammer_cli_csv/version.rb +1 -1
  42. data/lib/hammer_cli_csv.rb +2 -2
  43. data/test/csv_test.rb +32 -0
  44. data/test/csv_test_helper.rb +17 -2
  45. data/test/data/content-hosts.csv +3 -2
  46. data/test/data/hosts.csv +0 -11
  47. data/test/data/settings.csv +1 -0
  48. data/test/data/setup/content-hosts.csv +1 -0
  49. data/test/data/setup/content-views.csv +2 -0
  50. data/test/data/setup/lifecycle-environments.csv +5 -0
  51. data/test/data/setup/locations.csv +6 -0
  52. data/test/data/setup/organizations.csv +2 -0
  53. data/test/data/setup/subscriptions.csv +5 -0
  54. data/test/data/subscriptions.csv +15 -17
  55. data/test/export_test.rb +27 -0
  56. data/test/fixtures/vcr_cassettes/apipie.yml +18528 -0
  57. data/test/fixtures/vcr_cassettes/resources/activation_keys_import/create_and_update.yml +38033 -0
  58. data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export.yml +18846 -0
  59. data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export_subscriptions.yml +323 -0
  60. data/test/fixtures/vcr_cassettes/resources/content_hosts_import/create_and_update.yml +41884 -0
  61. data/test/fixtures/vcr_cassettes/resources/content_hosts_import/import_single_line.yml +38248 -0
  62. data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings.yml +18832 -0
  63. data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings_continue.yml +316 -0
  64. data/test/fixtures/vcr_cassettes/resources/subscriptions_import/manifest_does_not_exist.yml +18785 -0
  65. data/test/fixtures/vcr_cassettes/setup/setup_content_views/setup.yml +19090 -0
  66. data/test/fixtures/vcr_cassettes/setup/setup_lifecycle_environments/setup.yml +924 -0
  67. data/test/fixtures/vcr_cassettes/setup/setup_locations/setup.yml +21102 -0
  68. data/test/fixtures/vcr_cassettes/setup/setup_organizations/setup.yml +19278 -0
  69. data/test/fixtures/vcr_cassettes/setup/setup_subscriptions/setup.yml +419 -0
  70. data/test/import_test.rb +20 -25
  71. data/test/resources/activation_keys_test.rb +72 -0
  72. data/test/resources/content_hosts_test.rb +132 -0
  73. data/test/resources/settings_test.rb +81 -0
  74. data/test/resources/subscriptions_test.rb +56 -0
  75. data/test/setup/setup_content_views.rb +17 -0
  76. data/test/setup/setup_lifecycle_environments.rb +17 -0
  77. data/test/setup/setup_locations.rb +17 -0
  78. data/test/setup/setup_organizations.rb +17 -0
  79. data/test/setup/setup_subscriptions.rb +20 -0
  80. data/test/setup/setup_test.rb +10 -0
  81. data/test/test_runner.rb +175 -0
  82. data/test/vcr_setup.rb +54 -0
  83. metadata +77 -13
  84. data/lib/hammer_cli_csv/exception_handler.rb +0 -42
  85. data/lib/hammer_cli_csv/installation_medias.rb +0 -77
  86. data/test/content_hosts_test.rb +0 -61
  87. data/test/settings_test.rb +0 -30
@@ -0,0 +1,132 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Resources
5
+ class TestContentHostsUsage < MiniTest::Unit::TestCase
6
+ def test_usage
7
+ start_vcr
8
+ set_user 'admin'
9
+
10
+ stdout,stderr = capture {
11
+ hammer.run(%W{csv content-hosts --help})
12
+ }
13
+ assert_equal '', stderr
14
+ assert_equal stdout, <<-HELP
15
+ Usage:
16
+ csv content-hosts [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
+ --itemized-subscriptions Export one subscription per row, only process update subscriptions on import
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
+ end
30
+
31
+ class TestContentHostsImport < MiniTest::Unit::TestCase
32
+ def test_create_and_update
33
+ start_vcr
34
+ set_user 'admin'
35
+
36
+ @hostname = "testhost1"
37
+
38
+ file = Tempfile.new('content_hosts_test')
39
+ file.write("Name,Count,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
40
+ file.write("#{@hostname},1,Test Corporation,Library,Default Organization View,,No,,RHEL 6.4,x86_64,1,4,1,,,\n")
41
+ file.rewind
42
+
43
+ stdout,stderr = capture {
44
+ hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
45
+ }
46
+ assert_equal '', stderr
47
+ assert_equal stdout[0..-2], "Creating content host '#{@hostname}'...done"
48
+
49
+ file.rewind
50
+
51
+ stdout,stderr = capture {
52
+ hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
53
+ }
54
+ assert_equal '', stderr
55
+ assert_equal stdout[0..-2], "Updating content host '#{@hostname}'...done"
56
+ file.unlink
57
+
58
+ stdout,stderr = capture {
59
+ hammer.run(%W(host list --search name=#{@hostname}))
60
+ }
61
+ assert_equal '', stderr
62
+ assert_equal stdout.split("\n").length, 5
63
+ host_delete(@hostname)
64
+
65
+ stop_vcr
66
+ end
67
+ end
68
+
69
+ class TestContentHostsExport < MiniTest::Unit::TestCase
70
+ def test_export
71
+ start_vcr
72
+ set_user 'admin'
73
+
74
+ stdout,stderr = capture {
75
+ hammer.run(%W{csv content-hosts --export --organization Test\ Corporation})
76
+ }
77
+ assert_equal '', stderr
78
+ assert_equal stdout.split("\n")[0], "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions"
79
+ stop_vcr
80
+ end
81
+
82
+ def test_export_subscriptions
83
+ start_vcr
84
+ set_user 'admin'
85
+
86
+ stdout,stderr = capture {
87
+ hammer.run(%W{csv content-hosts --export --itemized-subscriptions --organization Test\ Corporation})
88
+ }
89
+ assert_equal '', stderr
90
+
91
+ # rubocop:disable LineLength
92
+ assert_equal stdout.split("\n")[0], "Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscription Name,Subscription Type,Subscription Quantity,Subscription SKU,Subscription Contract,Subscription Account,Subscription Start,Subscription End"
93
+ # rubocop:enable LineLength
94
+ stop_vcr
95
+ end
96
+ end
97
+
98
+ class TestContentHostsImport < MiniTest::Unit::TestCase
99
+ # import a single line, testing that subscription is added
100
+ def test_import_single_line
101
+ start_vcr
102
+ set_user 'admin'
103
+
104
+ @hostname = 'testhypervisor1'
105
+
106
+ file = Tempfile.new('content_hosts_test')
107
+ # rubocop:disable LineLength
108
+ file.write("Name,Organization,Environment,Content View,Host Collections,Virtual,Host,OS,Arch,Sockets,RAM,Cores,SLA,Products,Subscriptions\n")
109
+ file.write("#{@hostname},Test Corporation,Library,Default Organization View,\"\",Yes,,RHEL 7.2,x86_64,2,3882752,1,\"\",\"69|Red Hat Enterprise Linux Server,290|Red Hat OpenShift Enterprise\",\"\"\"1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium\"\"\"\n")
110
+ # rubocop:enable LineLength
111
+ file.rewind
112
+
113
+ stdout,stderr = capture {
114
+ hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
115
+ }
116
+ assert_equal '', stderr
117
+ assert_equal "Creating content host '#{@hostname}'...done\n", stdout
118
+
119
+ stdout,stderr = capture {
120
+ hammer.run(%W{csv content-hosts --export --organization Test\ Corporation})
121
+ }
122
+ assert_equal '', stderr
123
+ lines = stdout.split("\n")
124
+ assert_equal 2, lines.count
125
+ assert_match(/.*Test Corporation,Library,Default Organization View,"",Yes,,RHEL 7.2,x86_64,2,3882752,1.*/, lines[1])
126
+ assert_match(/.*1|RH00001|Red Hat Enterprise Linux for Virtual Datacenters, Premium.*/, lines[1])
127
+ host_delete(@hostname)
128
+
129
+ stop_vcr
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,81 @@
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{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{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{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
@@ -0,0 +1,56 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Resources
5
+ class TestSubscriptionsUsage < MiniTest::Unit::TestCase
6
+ def test_usage
7
+ start_vcr
8
+ set_user 'admin'
9
+
10
+ stdout,stderr = capture {
11
+ hammer.run(%W{csv subscriptions --help})
12
+ }
13
+ assert_equal '', stderr
14
+ assert_equal stdout, <<-HELP
15
+ Usage:
16
+ csv subscriptions [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 TestSubscriptionsImport < MiniTest::Unit::TestCase
31
+ def test_manifest_does_not_exist
32
+ start_vcr
33
+ set_user 'admin'
34
+
35
+ file = Tempfile.new('subscriptions_test')
36
+ # rubocop:disable LineLength
37
+ file.write <<-FILE
38
+ Name,Organization,Manifest File,Subscription Name,Quantity,Product SKU,Contract Number,Account Number
39
+ Manifest,Test Corporation,./test/data/doesnotexist.zip
40
+ # Manifest Name,Test Corporation,ExampleCorp
41
+ # Manifest URL,Test Corporation,https://access.stage.redhat.com/management/distributors/1234
42
+ FILE
43
+ file.rewind
44
+
45
+ stdout,stderr = capture {
46
+ hammer.run(%W{csv subscriptions --verbose --file #{file.path}})
47
+ }
48
+ assert_equal '', stdout
49
+ lines = stderr.split("\n")
50
+ assert_equal "Manifest upload failed:", lines[0]
51
+ assert_match(/.*Error: No such file or directory.*/, lines[1])
52
+ file.unlink
53
+ stop_vcr
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ class SetupContentViews < MiniTest::Unit::TestCase
6
+ def test_setup
7
+ start_vcr
8
+
9
+ stdout,stderr = capture {
10
+ hammer.run(%W{csv content-views --verbose --file test/data/setup/content-views.csv})
11
+ }
12
+ assert_equal stderr, ''
13
+
14
+ stop_vcr
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ class SetupLifecycleEnvironments < MiniTest::Unit::TestCase
6
+ def test_setup
7
+ start_vcr
8
+
9
+ stdout,stderr = capture {
10
+ hammer.run(%W{csv lifecycle-environments --verbose --file test/data/setup/lifecycle-environments.csv})
11
+ }
12
+ assert_equal stderr, ''
13
+
14
+ stop_vcr
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ class SetupLocations < MiniTest::Unit::TestCase
6
+ def test_setup
7
+ start_vcr
8
+
9
+ stdout,stderr = capture {
10
+ hammer.run(%W{csv locations --verbose --file test/data/setup/locations.csv})
11
+ }
12
+ assert_equal stderr, ''
13
+
14
+ stop_vcr
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ class SetupOrganizations < MiniTest::Unit::TestCase
6
+ def test_setup
7
+ start_vcr
8
+
9
+ stdout,stderr = capture {
10
+ hammer.run(%W{csv organizations --verbose --file test/data/setup/organizations.csv})
11
+ }
12
+ assert_equal stderr, ''
13
+
14
+ stop_vcr
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ class SetupSubscriptions < MiniTest::Unit::TestCase
6
+ def test_setup
7
+ start_vcr
8
+
9
+ stdout,stderr = capture {
10
+ hammer.run(%W{csv subscriptions --export --organization Test\ Corporation})
11
+ }
12
+ assert_equal stderr, ''
13
+ assert_equal 5, stdout.split("\n").length
14
+ assert_match(/.*"Red Hat Enterprise Linux for Virtual Datacenters, Premium",1,RH00001.*/, stdout)
15
+ assert_match(/.*"Red Hat Enterprise Linux for Virtual Datacenters, Standard",1,RH00002.*/, stdout)
16
+
17
+ stop_vcr
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require './test/csv_test_helper'
2
+ require './lib/hammer_cli_csv'
3
+
4
+ module Setup
5
+ require './test/setup/setup_organizations'
6
+ require './test/setup/setup_subscriptions'
7
+ require './test/setup/setup_locations'
8
+ require './test/setup/setup_lifecycle_environments'
9
+ require './test/setup/setup_content_views'
10
+ end
@@ -0,0 +1,175 @@
1
+ if RUBY_VERSION > "2.2"
2
+ # Coverage - Keep these two lines at the top of this file
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+
6
+ SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter]
8
+ SimpleCov.start do
9
+ minimum_coverage 36
10
+ maximum_coverage_drop 0.1
11
+ refuse_coverage_drop
12
+ track_files "lib/**/*.rb"
13
+ add_filter '/test/'
14
+ end
15
+ end
16
+
17
+ require 'rubygems'
18
+ require 'logger'
19
+ require 'minitest/unit'
20
+ require 'minitest/autorun'
21
+ require 'mocha/setup'
22
+
23
+ require './test/vcr_setup'
24
+
25
+ begin
26
+ require 'debugger'
27
+ rescue LoadError
28
+ puts 'Debugging not enabled.'
29
+ end
30
+
31
+ module MiniTest
32
+ class Unit
33
+ class TestCase
34
+ def cassette_name
35
+ test_name = self.__name__.gsub('test_', '')
36
+ parent = (self.class.name.split('::')[-2] || '').underscore
37
+ self_class = self.class.name.split('::')[-1].underscore.gsub('test_', '')
38
+ "#{parent}/#{self_class}/#{test_name}"
39
+ end
40
+
41
+ def start_vcr
42
+ options = self.class.respond_to?(:cassette_options) ? self.class.cassette_options : {}
43
+ VCR.insert_cassette(cassette_name, options)
44
+ end
45
+
46
+ def stop_vcr
47
+ VCR.eject_cassette
48
+ end
49
+
50
+ class << self
51
+ attr_accessor :support
52
+
53
+ def suite_cassette_name
54
+ parent = (self.name.split('::')[-2] || '').underscore
55
+ self_class = self.name.split('::')[-1].underscore.gsub('test_', '')
56
+ "#{parent}/#{self_class}/suite"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ class CustomMiniTestRunner
64
+ class Unit < MiniTest::Unit
65
+ def before_suites
66
+ # code to run before the first test
67
+ end
68
+
69
+ def after_suites
70
+ # code to run after the last test
71
+ end
72
+
73
+ def _run_suites(suites, type)
74
+ if ENV['suite']
75
+ suites = suites.select do |suite|
76
+ suite.name == ENV['suite']
77
+ end
78
+ end
79
+ before_suites
80
+ super(suites, type)
81
+ ensure
82
+ after_suites
83
+ end
84
+
85
+ def _run_suite(suite, type)
86
+ options = suite.respond_to?(:cassette_options) ? suite.cassette_options : {}
87
+ if logging?
88
+ puts "Running Suite #{suite.inspect} - #{type.inspect} "
89
+ end
90
+ if suite.respond_to?(:before_suite)
91
+ VCR.use_cassette(suite.suite_cassette_name, options) do
92
+ suite.before_suite
93
+ end
94
+ end
95
+ super(suite, type)
96
+ ensure
97
+ if suite.respond_to?(:after_suite)
98
+ VCR.use_cassette(suite.suite_cassette_name, options) do
99
+ suite.after_suite
100
+ end
101
+ end
102
+ if logging?
103
+ puts "Completed Running Suite #{suite.inspect} - #{type.inspect} "
104
+ end
105
+ end
106
+
107
+ def logging?
108
+ ENV['logging']
109
+ end
110
+ end
111
+ end
112
+
113
+ class CsvMiniTestRunner
114
+ def run_tests(suite, options = {})
115
+ mode = options[:mode] || 'none'
116
+ test_name = options[:test_name] || nil
117
+ logging = options[:logging] || false
118
+
119
+ MiniTest::Unit.runner = CustomMiniTestRunner::Unit.new
120
+
121
+ vcr_config(mode)
122
+
123
+ if test_name && File.exist?(test_name)
124
+ require test_name
125
+ elsif test_name
126
+ require "./test/#{test_name}_test.rb"
127
+ else
128
+ Dir["./test/#{suite}/*_test.rb"].each { |file| require file }
129
+ end
130
+ end
131
+
132
+ def vcr_config(mode)
133
+ load_config_settings
134
+ if mode == 'all'
135
+ configure_vcr(:all)
136
+ elsif mode == 'new_episodes'
137
+ configure_vcr(:new_episodes)
138
+ elsif mode == 'once'
139
+ configure_vcr(:once)
140
+ else
141
+ configure_vcr(:none)
142
+ end
143
+ end
144
+
145
+ def load_config_settings
146
+ if File.exists? 'test/config.yml'
147
+ HammerCLI::Settings.load_from_file 'test/config.yml'
148
+ else
149
+ HammerCLI::Settings.load({
150
+ :ui => {
151
+ :interactive => true,
152
+ :per_page => 20,
153
+ :history_file => './log/history'
154
+ },
155
+ :watch_plain => true,
156
+ :log_dir => './log',
157
+ :log_level => 'error',
158
+ :log_api_calls => false,
159
+ :log_size => 5,
160
+ :csv => {
161
+ :enable_module => true
162
+ },
163
+ :foreman => {
164
+ :enable_module => true,
165
+ :host => 'https://localhost',
166
+ :username => 'admin',
167
+ :password => 'changeme'
168
+ },
169
+ :katello => {
170
+ :enable_module => true
171
+ }
172
+ })
173
+ end
174
+ end
175
+ end
data/test/vcr_setup.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'vcr'
3
+ require 'hammer_cli'
4
+
5
+ def configure_vcr(mode = :none)
6
+ if ENV['record'] == 'false' && mode == :none
7
+ fail "Record flag is not applicable for mode 'none', please use with 'mode=all'"
8
+ end
9
+
10
+ VCR.configure do |c|
11
+ c.cassette_library_dir = 'test/fixtures/vcr_cassettes'
12
+ c.hook_into :webmock
13
+
14
+ if ENV['record'] == 'false' && mode != :none
15
+ server = HammerCLI::Settings.get(:csv, :host) ||
16
+ HammerCLI::Settings.get(:katello, :host) ||
17
+ HammerCLI::Settings.get(:foreman, :host)
18
+ uri = URI.parse(server)
19
+ c.ignore_hosts uri.host
20
+ end
21
+
22
+ c.default_cassette_options = {
23
+ :record => mode,
24
+ :match_requests_on => [:method, :path, :params, :body_json],
25
+ :decode_compressed_response => true
26
+ }
27
+
28
+ # rubocop:disable HandleExceptions
29
+ begin
30
+ c.register_request_matcher :body_json do |request_1, request_2|
31
+ begin
32
+ json_1 = JSON.parse(request_1.body)
33
+ json_2 = JSON.parse(request_2.body)
34
+
35
+ json_1 == json_2
36
+ rescue
37
+ #fallback incase there is a JSON parse error
38
+ request_1.body == request_2.body
39
+ end
40
+ end
41
+ rescue
42
+ #ignore the warning thrown about this matcher already being resgistered
43
+ end
44
+
45
+ begin
46
+ c.register_request_matcher :params do |request_1, request_2|
47
+ URI(request_1.uri).query == URI(request_2.uri).query
48
+ end
49
+ rescue
50
+ #ignore the warning thrown about this matcher already being resgistered
51
+ end
52
+ # rubocop:enable HandleExceptions
53
+ end
54
+ end