hammer_cli_katello 1.1.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (225) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/command_extensions/content_source.rb +32 -0
  3. data/lib/hammer_cli_katello/command_extensions/kickstart_repository.rb +50 -0
  4. data/lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb +12 -0
  5. data/lib/hammer_cli_katello/command_extensions.rb +2 -0
  6. data/lib/hammer_cli_katello/commands.rb +1 -1
  7. data/lib/hammer_cli_katello/content_export_helper.rb +6 -2
  8. data/lib/hammer_cli_katello/content_units.rb +66 -0
  9. data/lib/hammer_cli_katello/content_view.rb +11 -0
  10. data/lib/hammer_cli_katello/content_view_component.rb +4 -3
  11. data/lib/hammer_cli_katello/content_view_version.rb +3 -3
  12. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  13. data/lib/hammer_cli_katello/host_collection.rb +6 -0
  14. data/lib/hammer_cli_katello/host_errata.rb +2 -3
  15. data/lib/hammer_cli_katello/host_extensions.rb +8 -6
  16. data/lib/hammer_cli_katello/hostgroup_extensions.rb +19 -12
  17. data/lib/hammer_cli_katello/id_resolver.rb +5 -2
  18. data/lib/hammer_cli_katello/option_sources/lifecycle_environment_params.rb +40 -3
  19. data/lib/hammer_cli_katello/organization.rb +28 -3
  20. data/lib/hammer_cli_katello/package.rb +2 -1
  21. data/lib/hammer_cli_katello/ping.rb +7 -0
  22. data/lib/hammer_cli_katello/repository.rb +50 -60
  23. data/lib/hammer_cli_katello/search_options_creators.rb +2 -1
  24. data/lib/hammer_cli_katello/srpm.rb +2 -0
  25. data/lib/hammer_cli_katello/version.rb +1 -1
  26. data/lib/hammer_cli_katello.rb +5 -5
  27. data/test/data/2.5/foreman_api.json +1 -0
  28. data/test/data/3.0/foreman_api.json +1 -0
  29. data/test/data/3.10/foreman_api.json +1 -0
  30. data/test/data/3.11/foreman_api.json +1 -0
  31. data/test/data/3.12/foreman_api.json +1 -0
  32. data/test/data/3.13/foreman_api.json +1 -0
  33. data/test/data/3.14/foreman_api.json +1 -0
  34. data/test/data/3.15/foreman_api.json +1 -0
  35. data/test/data/3.16/foreman_api.json +1 -0
  36. data/test/data/3.17/foreman_api.json +1 -0
  37. data/test/data/3.18/foreman_api.json +1 -0
  38. data/test/data/3.19/foreman_api.json +1 -0
  39. data/test/data/3.2/foreman_api.json +1 -0
  40. data/test/data/3.4/foreman_api.json +1 -0
  41. data/test/data/3.5/foreman_api.json +1 -0
  42. data/test/data/3.6/foreman_api.json +1 -0
  43. data/test/data/3.7/foreman_api.json +1 -0
  44. data/test/data/3.8/foreman_api.json +1 -0
  45. data/test/data/3.9/foreman_api.json +1 -0
  46. data/test/data/4.0/foreman_api.json +1 -0
  47. data/test/data/4.1/foreman_api.json +1 -0
  48. data/test/data/4.3/foreman_api.json +1 -0
  49. data/test/data/Readme.md +5 -0
  50. data/test/functional/activation_key/add_host_collection_test.rb +62 -0
  51. data/test/functional/activation_key/content_override_test.rb +92 -0
  52. data/test/functional/activation_key/create_test.rb +33 -0
  53. data/test/functional/activation_key/data/activation_key.json +17 -0
  54. data/test/functional/activation_key/info_test.rb +29 -0
  55. data/test/functional/activation_key/list_test.rb +68 -0
  56. data/test/functional/activation_key/product_content_test.rb +23 -0
  57. data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
  58. data/test/functional/activation_key/subscriptions_test.rb +74 -0
  59. data/test/functional/activation_key/update_test.rb +26 -0
  60. data/test/functional/apipie_helper_test.rb +31 -0
  61. data/test/functional/capsule/capsule_helpers.rb +13 -0
  62. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
  63. data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
  64. data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
  65. data/test/functional/capsule/content/data/library_env.json +47 -0
  66. data/test/functional/capsule/content/data/sync_status.json +6 -0
  67. data/test/functional/capsule/content/data/sync_tasks.json +62 -0
  68. data/test/functional/capsule/content/info_test.rb +61 -0
  69. data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
  70. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
  71. data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
  72. data/test/functional/capsule/info_test.rb +25 -0
  73. data/test/functional/capsule/list_test.rb +24 -0
  74. data/test/functional/content_credentials/create_test.rb +32 -0
  75. data/test/functional/content_credentials/data/test_cert.json +43 -0
  76. data/test/functional/content_credentials/info_test.rb +50 -0
  77. data/test/functional/content_credentials/list_test.rb +66 -0
  78. data/test/functional/content_export/complete/library_test.rb +155 -0
  79. data/test/functional/content_export/complete/version_test.rb +252 -0
  80. data/test/functional/content_export/content_export_helpers.rb +26 -0
  81. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  82. data/test/functional/content_export/incremental/library_test.rb +172 -0
  83. data/test/functional/content_export/incremental/version_test.rb +268 -0
  84. data/test/functional/content_export/list_test.rb +64 -0
  85. data/test/functional/content_import/library_test.rb +85 -0
  86. data/test/functional/content_import/list_test.rb +65 -0
  87. data/test/functional/content_import/metadata.json +1 -0
  88. data/test/functional/content_import/version_test.rb +85 -0
  89. data/test/functional/content_units/info_test.rb +29 -0
  90. data/test/functional/content_units/list_test.rb +106 -0
  91. data/test/functional/content_view/add_content_view_version_test.rb +88 -0
  92. data/test/functional/content_view/add_repository_test.rb +21 -0
  93. data/test/functional/content_view/component/add_test.rb +177 -0
  94. data/test/functional/content_view/component/list_test.rb +55 -0
  95. data/test/functional/content_view/component/remove_test.rb +107 -0
  96. data/test/functional/content_view/component/update_test.rb +134 -0
  97. data/test/functional/content_view/content_view_helpers.rb +20 -0
  98. data/test/functional/content_view/copy_test.rb +53 -0
  99. data/test/functional/content_view/create_test.rb +34 -0
  100. data/test/functional/content_view/delete_test.rb +62 -0
  101. data/test/functional/content_view/filter/create_test.rb +57 -0
  102. data/test/functional/content_view/filter/delete_test.rb +90 -0
  103. data/test/functional/content_view/filter/info_test.rb +89 -0
  104. data/test/functional/content_view/filter/list_test.rb +98 -0
  105. data/test/functional/content_view/filter/update_test.rb +91 -0
  106. data/test/functional/content_view/list_test.rb +68 -0
  107. data/test/functional/content_view/publish_test.rb +24 -0
  108. data/test/functional/content_view/purge_test.rb +97 -0
  109. data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
  110. data/test/functional/content_view/remove_test.rb +79 -0
  111. data/test/functional/content_view/update_test.rb +53 -0
  112. data/test/functional/content_view/version/incremental_update_test.rb +108 -0
  113. data/test/functional/content_view/version/list_test.rb +44 -0
  114. data/test/functional/content_view/version/promote_test.rb +75 -0
  115. data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
  116. data/test/functional/content_view/version/update_test.rb +48 -0
  117. data/test/functional/erratum/erratum_helpers.rb +91 -0
  118. data/test/functional/erratum/info_test.rb +29 -0
  119. data/test/functional/erratum/list_test.rb +108 -0
  120. data/test/functional/file/file_helpers.rb +13 -0
  121. data/test/functional/file/info_test.rb +162 -0
  122. data/test/functional/file/list_test.rb +112 -0
  123. data/test/functional/filter_rule/create_test.rb +99 -0
  124. data/test/functional/filter_rule/delete_test.rb +104 -0
  125. data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
  126. data/test/functional/filter_rule/info_test.rb +104 -0
  127. data/test/functional/filter_rule/list_test.rb +91 -0
  128. data/test/functional/filter_rule/update_test.rb +104 -0
  129. data/test/functional/host/errata/apply_test.rb +45 -0
  130. data/test/functional/host/errata/info_test.rb +27 -0
  131. data/test/functional/host/errata/list_test.rb +49 -0
  132. data/test/functional/host/errata/recalculate_test.rb +26 -0
  133. data/test/functional/host/extensions/create_test.rb +95 -0
  134. data/test/functional/host/extensions/data/host.json +320 -0
  135. data/test/functional/host/extensions/data/host_list.json +117 -0
  136. data/test/functional/host/extensions/info_test.rb +35 -0
  137. data/test/functional/host/extensions/list_test.rb +21 -0
  138. data/test/functional/host/extensions/update_test.rb +70 -0
  139. data/test/functional/host/host_helpers.rb +8 -0
  140. data/test/functional/host/subscription/attach_test.rb +54 -0
  141. data/test/functional/host/subscription/auto_attach_test.rb +35 -0
  142. data/test/functional/host/subscription/content_override_test.rb +96 -0
  143. data/test/functional/host/subscription/product_content_test.rb +27 -0
  144. data/test/functional/host/subscription/register_test.rb +53 -0
  145. data/test/functional/host/subscription/remove_test.rb +52 -0
  146. data/test/functional/host/subscription/unregister_test.rb +37 -0
  147. data/test/functional/host/traces/list_test.rb +37 -0
  148. data/test/functional/host/traces/resolve_test.rb +31 -0
  149. data/test/functional/host_collection/add_host_test.rb +90 -0
  150. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  151. data/test/functional/host_collection/content_install_test.rb +62 -0
  152. data/test/functional/host_collection/content_remove_test.rb +37 -0
  153. data/test/functional/host_collection/content_update_test.rb +37 -0
  154. data/test/functional/host_collection/copy_test.rb +64 -0
  155. data/test/functional/host_collection/create_test.rb +54 -0
  156. data/test/functional/host_collection/delete_test.rb +57 -0
  157. data/test/functional/host_collection/hosts_test.rb +39 -0
  158. data/test/functional/host_collection/info_test.rb +57 -0
  159. data/test/functional/host_collection/list_test.rb +63 -0
  160. data/test/functional/host_collection/remove_host_test.rb +90 -0
  161. data/test/functional/host_collection/update_test.rb +57 -0
  162. data/test/functional/hostgroup/create_test.rb +112 -0
  163. data/test/functional/hostgroup/data/hostgroup.json +50 -0
  164. data/test/functional/hostgroup/info_test.rb +33 -0
  165. data/test/functional/hostgroup/update_test.rb +120 -0
  166. data/test/functional/lifecycle_environment/create_test.rb +14 -0
  167. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
  168. data/test/functional/lifecycle_environment/list_test.rb +38 -0
  169. data/test/functional/lifecycle_environment/update_test.rb +14 -0
  170. data/test/functional/local_helper_test.rb +30 -0
  171. data/test/functional/module_stream/info_test.rb +58 -0
  172. data/test/functional/module_stream/list_test.rb +53 -0
  173. data/test/functional/organization/cdn_configuration_test.rb +42 -0
  174. data/test/functional/organization/delete_test.rb +26 -0
  175. data/test/functional/organization/info_test.rb +39 -0
  176. data/test/functional/organization/organization_helpers.rb +10 -0
  177. data/test/functional/package/list_test.rb +160 -0
  178. data/test/functional/package_group/list_test.rb +38 -0
  179. data/test/functional/ping_test.rb +61 -0
  180. data/test/functional/product/create_test.rb +54 -0
  181. data/test/functional/product/delete_test.rb +41 -0
  182. data/test/functional/product/info_test.rb +33 -0
  183. data/test/functional/product/list_test.rb +58 -0
  184. data/test/functional/product/product_helpers.rb +24 -0
  185. data/test/functional/product/remove_sync_plan_test.rb +35 -0
  186. data/test/functional/product/set_sync_plan_test.rb +49 -0
  187. data/test/functional/product/update_proxy.rb +48 -0
  188. data/test/functional/product/update_test.rb +46 -0
  189. data/test/functional/repository/create_test.rb +21 -0
  190. data/test/functional/repository/delete_test.rb +95 -0
  191. data/test/functional/repository/info_test.rb +156 -0
  192. data/test/functional/repository/list_test.rb +68 -0
  193. data/test/functional/repository/remove_content_test.rb +108 -0
  194. data/test/functional/repository/repository_helpers.rb +18 -0
  195. data/test/functional/repository/synchronize_test.rb +57 -0
  196. data/test/functional/repository/update_test.rb +149 -0
  197. data/test/functional/repository/upload_test.rb +368 -0
  198. data/test/functional/repository_set/available_repositories_test.rb +18 -0
  199. data/test/functional/repository_set/disable_test.rb +42 -0
  200. data/test/functional/repository_set/enable_test.rb +42 -0
  201. data/test/functional/repository_set/info_test.rb +17 -0
  202. data/test/functional/repository_set/list_test.rb +18 -0
  203. data/test/functional/repository_set/repository_set_helpers.rb +20 -0
  204. data/test/functional/search_helpers.rb +17 -0
  205. data/test/functional/simple_content_access/disable_test.rb +48 -0
  206. data/test/functional/simple_content_access/enable_test.rb +46 -0
  207. data/test/functional/srpm/list_test.rb +92 -0
  208. data/test/functional/subscription/list_test.rb +86 -0
  209. data/test/functional/sync_plan/create_test.rb +60 -0
  210. data/test/functional/sync_plan/delete_test.rb +46 -0
  211. data/test/functional/sync_plan/info_test.rb +37 -0
  212. data/test/functional/sync_plan/list_test.rb +31 -0
  213. data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
  214. data/test/functional/sync_plan/update_test.rb +44 -0
  215. data/test/functional/test_helper.rb +24 -0
  216. data/test/task_helper.rb +7 -0
  217. data/test/test_helper.rb +38 -0
  218. data/test/unit/id_name_options_validator_test.rb +96 -0
  219. data/test/unit/id_resolver_test.rb +58 -0
  220. data/test/unit/messages_test.rb +7 -0
  221. data/test/unit/search_options_creators_test.rb +145 -0
  222. metadata +396 -6
  223. data/lib/hammer_cli_katello/host_content_source_options.rb +0 -28
  224. data/lib/hammer_cli_katello/host_kickstart_repository_options.rb +0 -49
  225. data/lib/hammer_cli_katello/ostree_branch.rb +0 -34
@@ -0,0 +1,368 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper')
2
+ require File.join(File.dirname(__FILE__), '../product/product_helpers')
3
+ require File.join(File.dirname(__FILE__), './repository_helpers')
4
+
5
+ describe 'upload repository' do
6
+ include ProductHelpers
7
+ include RepositoryHelpers
8
+ include ForemanTaskHelpers
9
+
10
+ before do
11
+ @cmd = %w(repository upload-content)
12
+ end
13
+
14
+ let(:org_id) { 1 }
15
+ let(:product_id) { 2 }
16
+ let(:repo_id) { 3 }
17
+ let(:path) { "./test.rpm" }
18
+ let(:upload_id) { "1234" }
19
+ let(:_href) { "/pulp/api/v2/content/uploads/#{upload_id}" }
20
+ let(:task_id) { "2ea4f" }
21
+ let(:upload_response) do
22
+ {
23
+ "upload_id" => upload_id,
24
+ "href" => _href
25
+ }
26
+ end
27
+ let(:import_uploads_response) do
28
+ {
29
+ "id" => task_id
30
+ }
31
+ end
32
+
33
+ it "uploads a package" do
34
+ file = File.new("test.rpm", "w")
35
+
36
+ params = ["--id=#{repo_id}", "--path=#{path}"]
37
+
38
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
39
+ .with_params('repository_id' => repo_id, :size => file.size)
40
+
41
+ ex.returns(upload_response)
42
+
43
+ # rubocop:disable LineLength
44
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
45
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
46
+ :uploads => [{
47
+ :id => '1234',
48
+ :name => 'test.rpm',
49
+ :size => 0,
50
+ :content_unit_id => nil,
51
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
52
+ }]
53
+ )
54
+ # rubocop:enable LineLength
55
+
56
+ ex2.returns(import_uploads_response)
57
+ expect_foreman_task(task_id)
58
+ expect_foreman_task(task_id)
59
+
60
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
61
+ .with_params('id' => upload_id, 'repository_id' => repo_id)
62
+
63
+ ex3.returns("")
64
+ result = run_cmd(@cmd + params)
65
+
66
+ assert_equal(result.exit_code, 0)
67
+ File.delete("test.rpm")
68
+ end
69
+
70
+ it "uploads srpm with content-type" do
71
+ file = File.new("test.src.rpm", "w")
72
+ params = ["--id=#{repo_id}", '--path=./test.src.rpm', '--content-type=srpm']
73
+
74
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
75
+ .with_params('repository_id' => repo_id, :content_type => 'srpm', :size => file.size)
76
+
77
+ ex.returns(upload_response)
78
+
79
+ # rubocop:disable LineLength
80
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
81
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :content_type => 'srpm', :async => true,
82
+ :uploads => [{
83
+ :id => '1234',
84
+ :name => 'test.src.rpm',
85
+ :size => 0,
86
+ :content_unit_id => nil,
87
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
88
+ }]
89
+ )
90
+ # rubocop:enable LineLength
91
+
92
+ ex2.returns(import_uploads_response)
93
+ expect_foreman_task(task_id)
94
+ expect_foreman_task(task_id)
95
+
96
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
97
+ .with_params(:id => upload_id, :repository_id => repo_id)
98
+
99
+ ex3.returns("")
100
+
101
+ result = run_cmd(@cmd + params)
102
+ assert_equal(result.exit_code, 0)
103
+ File.delete("test.src.rpm")
104
+ end
105
+
106
+ it 'fails upload of srpm with no content-type' do
107
+ file = File.new("test.src.rpm", "w")
108
+
109
+ params = ["--id=#{repo_id}", '--path=./test.src.rpm']
110
+
111
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
112
+ .with_params('repository_id' => repo_id, :size => file.size)
113
+
114
+ ex.returns(upload_response)
115
+
116
+ # rubocop:disable LineLength
117
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
118
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
119
+ :uploads => [{
120
+ :id => '1234',
121
+ :name => 'test.src.rpm',
122
+ :size => 0,
123
+ :content_unit_id => nil,
124
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
125
+ }]
126
+ )
127
+ # rubocop:enable LineLength
128
+
129
+ ex2.returns(400)
130
+
131
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
132
+ .with_params(:id => upload_id, :repository_id => repo_id)
133
+
134
+ ex3.returns("")
135
+
136
+ result = run_cmd(@cmd + params)
137
+ assert_equal(result.exit_code, 70)
138
+ File.delete("test.src.rpm")
139
+ end
140
+
141
+ it "uploads a docker image" do
142
+ file = File.new("test.rpm", "w")
143
+
144
+ params = ["--id=#{repo_id}", "--path=#{path}"]
145
+
146
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
147
+ .with_params(:repository_id => repo_id, :size => file.size)
148
+
149
+ ex.returns(upload_response)
150
+
151
+ # rubocop:disable LineLength
152
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
153
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
154
+ :uploads => [{
155
+ :id => '1234',
156
+ :name => 'test.rpm',
157
+ :size => 0,
158
+ :content_unit_id => nil,
159
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
160
+ }]
161
+ )
162
+ # rubocop:enable LineLength
163
+
164
+ ex2.returns(import_uploads_response)
165
+ expect_foreman_task(task_id)
166
+
167
+ ex3 = api_expects(:foreman_tasks, :show, 'Show task')
168
+ ex3.returns('id' => task_id, 'state' => 'stopped', 'progress' => 1,
169
+ 'humanized' => {'output' => {'upload_results' => [{'type' => 'docker_manifest',
170
+ 'digest' => 'sha256:1234'}]},
171
+ 'errors' => ''})
172
+
173
+ ex4 = api_expects(:content_uploads, :destroy, "Delete the upload")
174
+ .with_params(:id => upload_id, :repository_id => repo_id)
175
+
176
+ ex4.returns("")
177
+
178
+ result = run_cmd(@cmd + params)
179
+ assert_equal(result.exit_code, 0)
180
+ File.delete("test.rpm")
181
+ end
182
+
183
+ it "uploads a package with an organization-id" do
184
+ file = File.new("test.rpm", "w")
185
+
186
+ params = ["--name=test_repo", "--product=test_product", "--organization-id=#{org_id}",
187
+ "--path=#{path}"]
188
+
189
+ expect_product_search(org_id, 'test_product', product_id)
190
+
191
+ expect_repository_search(product_id, 'test_repo', repo_id)
192
+
193
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
194
+ .with_params(:repository_id => repo_id, :size => file.size)
195
+
196
+ ex.returns(upload_response)
197
+
198
+ # rubocop:disable LineLength
199
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
200
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
201
+ :uploads => [{
202
+ :id => '1234',
203
+ :name => 'test.rpm',
204
+ :size => 0,
205
+ :content_unit_id => nil,
206
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
207
+ }]
208
+ )
209
+ # rubocop:enable LineLength
210
+
211
+ ex2.returns(import_uploads_response)
212
+ expect_foreman_task(task_id)
213
+ expect_foreman_task(task_id)
214
+
215
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
216
+ .with_params(:id => upload_id, :repository_id => repo_id)
217
+
218
+ ex3.returns("")
219
+
220
+ result = run_cmd(@cmd + params)
221
+ assert_equal(result.exit_code, 0)
222
+ File.delete("test.rpm")
223
+ end
224
+
225
+ it "supports globs" do
226
+ file = File.new("test.rpm", "w")
227
+
228
+ params = ["--id=#{repo_id}", "--path={test}.[r{1}]pm"]
229
+
230
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
231
+ .with_params(:repository_id => repo_id, :size => file.size)
232
+
233
+ ex.returns(upload_response)
234
+ # rubocop:disable LineLength
235
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
236
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
237
+ :uploads => [{
238
+ :id => '1234',
239
+ :name => 'test.rpm',
240
+ :size => 0,
241
+ :content_unit_id => nil,
242
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
243
+ }]
244
+ )
245
+ # rubocop:enable LineLength
246
+ ex2.returns(import_uploads_response)
247
+ expect_foreman_task(task_id)
248
+ expect_foreman_task(task_id)
249
+
250
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
251
+ .with_params(:id => upload_id, :repository_id => repo_id)
252
+
253
+ ex3.returns("")
254
+
255
+ result = run_cmd(@cmd + params)
256
+ assert_equal(result.exit_code, 0)
257
+ File.delete("test.rpm")
258
+ end
259
+
260
+ it "only syncs the capsule on the last file import" do
261
+ File.new("test1.rpm", "w")
262
+ File.new("test2.rpm", "w")
263
+
264
+ params = ["--id=#{repo_id}", "--path=test*.rpm"]
265
+
266
+ # Begin first upload cycle
267
+
268
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
269
+ .with_params(:repository_id => repo_id)
270
+
271
+ ex.returns(upload_response)
272
+
273
+ # rubocop:disable LineLength
274
+ ex = api_expects(:repositories, :import_uploads, 'Take in an upload')
275
+ .with_params(:id => repo_id, :sync_capsule => false, :publish_repository => false, :async => true,
276
+ :uploads => [{
277
+ :id => '1234',
278
+ :name => 'test1.rpm',
279
+ :size => 0,
280
+ :content_unit_id => nil,
281
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
282
+ }]
283
+ )
284
+ # rubocop:enable LineLength
285
+
286
+ ex.returns(import_uploads_response)
287
+ expect_foreman_task(task_id)
288
+ expect_foreman_task(task_id)
289
+
290
+ ex = api_expects(:content_uploads, :destroy, "Delete the upload")
291
+ .with_params(:id => upload_id, :repository_id => repo_id)
292
+
293
+ ex.returns("")
294
+
295
+ # Begin second upload cycle
296
+
297
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
298
+ .with_params(:repository_id => repo_id)
299
+
300
+ ex.returns(upload_response)
301
+
302
+ # rubocop:disable LineLength
303
+ ex = api_expects(:repositories, :import_uploads, 'Take in an upload')
304
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :async => true,
305
+ :uploads => [{
306
+ :id => '1234',
307
+ :name => 'test2.rpm',
308
+ :size => 0,
309
+ :content_unit_id => nil,
310
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
311
+ }]
312
+ )
313
+ # rubocop:enable LineLength
314
+
315
+ ex.returns(import_uploads_response)
316
+ expect_foreman_task(task_id)
317
+ expect_foreman_task(task_id)
318
+
319
+ ex = api_expects(:content_uploads, :destroy, "Delete the upload")
320
+ .with_params(:id => upload_id, :repository_id => repo_id)
321
+
322
+ ex.returns("")
323
+
324
+ result = run_cmd(@cmd + params)
325
+ assert_equal(result.exit_code, 0)
326
+ File.delete("test1.rpm")
327
+ File.delete("test2.rpm")
328
+ end
329
+
330
+ it "errors if there are no matching files" do
331
+ params = ["--id=#{repo_id}", "--path=#{path}"]
332
+
333
+ result = run_cmd(@cmd + params)
334
+
335
+ assert_equal "Could not find any files matching PATH\n", result.err
336
+ assert_equal HammerCLI::EX_NOINPUT, result.exit_code
337
+ end
338
+
339
+ describe 'requires' do
340
+ it 'repository options' do
341
+ api_expects_no_call
342
+ error = run_cmd(@cmd + %W(--path #{path})).err
343
+ assert error.include?('--id, --name is required'), "Actual result: #{error}"
344
+ end
345
+
346
+ it 'product options when repository name is specified' do
347
+ api_expects_no_call
348
+ error = run_cmd(@cmd + %W(--name repo1 --path #{path})).err
349
+ assert(error.include?('--product, --product-id is required'), "Actual result: #{error}")
350
+ end
351
+
352
+ it 'organization options when product name is specified' do
353
+ api_expects_no_call
354
+ error = run_cmd(@cmd + %W(--name repo1 --product product2 --path #{path})).err
355
+ assert(error.include?('--organization-id, --organization, --organization-label is required'),
356
+ "Actual result: #{error}")
357
+ end
358
+ end
359
+
360
+ describe 'disallows' do
361
+ it 'product options when repository ID is specified' do
362
+ api_expects_no_call
363
+ error = run_cmd(@cmd + %W(--id 1 --product product2 --path #{path})).err
364
+ assert(error.include?('Cannot specify both product options and repository ID'),
365
+ "Actual result: #{error}")
366
+ end
367
+ end
368
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/repository_set'
3
+
4
+ module HammerCLIKatello
5
+ describe RepositorySetCommand::AvailableRepositoriesCommand do
6
+ it 'allows minimal options' do
7
+ api_expects(:repository_sets, :available_repositories)
8
+ .with_params('id' => 1)
9
+ .returns(index_response([]))
10
+ assert_success run_cmd(%w(repository-set available-repositories --id 1))
11
+ end
12
+
13
+ it 'requires repository set options' do
14
+ api_expects_no_call
15
+ assert_failure run_cmd(%w(repository-set available-repositories)), /id.*name.*required/
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../test_helper'
2
+ require_relative './repository_set_helpers'
3
+ require 'hammer_cli_katello/repository_set'
4
+
5
+ module HammerCLIKatello
6
+ describe RepositorySetCommand::DisableCommand do
7
+ include RepositorySetHelpers
8
+
9
+ it 'allows minimal options' do
10
+ api_expects(:repository_sets, :disable)
11
+ .with_params('id' => 1)
12
+ assert_success run_cmd(%w(repository-set disable --id 1))
13
+ end
14
+
15
+ it 'requires repository set options' do
16
+ api_expects_no_call
17
+ assert_failure run_cmd(%w(repository-set disable)), /id.*name.*required/
18
+ end
19
+
20
+ describe 'resolves repository set ID' do
21
+ it 'by requiring organization or product options' do
22
+ api_expects_no_call
23
+ assert_failure run_cmd(%w(repository-set disable --name reposet1)),
24
+ /organization.*product.*required/
25
+ end
26
+
27
+ it 'from organization options' do
28
+ expect_repository_set_search('reposet1', 1, organization_id: 2)
29
+ api_expects(:repository_sets, :disable)
30
+ .with_params('id' => 1)
31
+ assert_success run_cmd(%w(repository-set disable --name reposet1 --organization-id 2))
32
+ end
33
+
34
+ it 'from product options' do
35
+ expect_repository_set_search('reposet1', 1, product_id: 3)
36
+ api_expects(:repository_sets, :disable)
37
+ .with_params('id' => 1)
38
+ assert_success run_cmd(%w(repository-set disable --name reposet1 --product-id 3))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ require_relative '../test_helper'
2
+ require_relative './repository_set_helpers'
3
+ require 'hammer_cli_katello/repository_set'
4
+
5
+ module HammerCLIKatello
6
+ describe RepositorySetCommand::EnableCommand do
7
+ include RepositorySetHelpers
8
+
9
+ it 'allows minimal options' do
10
+ api_expects(:repository_sets, :enable)
11
+ .with_params('id' => 1)
12
+ assert_success run_cmd(%w(repository-set enable --id 1))
13
+ end
14
+
15
+ it 'requires repository set options' do
16
+ api_expects_no_call
17
+ assert_failure run_cmd(%w(repository-set enable)), /id.*name.*required/
18
+ end
19
+
20
+ describe 'resolves repository set ID' do
21
+ it 'by requiring organization or product options' do
22
+ api_expects_no_call
23
+ assert_failure run_cmd(%w(repository-set enable --name reposet1)),
24
+ /organization.*product.*required/
25
+ end
26
+
27
+ it 'from organization options' do
28
+ expect_repository_set_search('reposet1', 1, organization_id: 2)
29
+ api_expects(:repository_sets, :enable)
30
+ .with_params('id' => 1)
31
+ assert_success run_cmd(%w(repository-set enable --name reposet1 --organization-id 2))
32
+ end
33
+
34
+ it 'from product options' do
35
+ expect_repository_set_search('reposet1', 1, product_id: 3)
36
+ api_expects(:repository_sets, :enable)
37
+ .with_params('id' => 1)
38
+ assert_success run_cmd(%w(repository-set enable --name reposet1 --product-id 3))
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/repository_set'
3
+
4
+ module HammerCLIKatello
5
+ describe RepositorySetCommand::InfoCommand do
6
+ it 'allows minimal options' do
7
+ api_expects(:repository_sets, :show)
8
+ .with_params('id' => 1)
9
+ assert_success run_cmd(%w(repository-set info --id 1))
10
+ end
11
+
12
+ it 'requires repository set options' do
13
+ api_expects_no_call
14
+ assert_failure run_cmd(%w(repository-set info)), /id.*name.*required/
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../test_helper'
2
+ require 'hammer_cli_katello/repository_set'
3
+
4
+ module HammerCLIKatello
5
+ describe RepositorySetCommand::ListCommand do
6
+ it 'allows minimal options' do
7
+ api_expects(:repository_sets, :index)
8
+ .with_params('organization_id' => 1)
9
+ .returns(index_response([]))
10
+ assert_success run_cmd(%w(repository-set list --organization-id 1))
11
+ end
12
+
13
+ it 'requires organization options' do
14
+ api_expects_no_call
15
+ assert_failure run_cmd(%w(repository-set list)), /organization.*required/
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require_relative '../search_helpers'
2
+
3
+ module RepositorySetHelpers
4
+ include SearchHelpers
5
+
6
+ def expect_repository_set_search(name, id, organization_id: nil, product_id: nil)
7
+ params = {'name' => name}
8
+ params.merge(organization_id: organization_id) if organization_id.nil?
9
+ params.merge(product_id: product_id) if product_id.nil?
10
+ expect_generic_repository_sets_search(
11
+ params: params,
12
+ returns: {'id' => id})
13
+ end
14
+
15
+ def expect_generic_repository_sets_search(params: {}, returns: [])
16
+ api_expects(:repository_sets, :index, 'Find repository sets')
17
+ .with_params(params)
18
+ .returns(index_response(returns))
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module SearchHelpers
2
+ def expect_generic_search(resource, args)
3
+ ex = api_expects(resource, :index, "Find the #{resource}").with_params(args[:params])
4
+ ex.returns(index_response([args[:returns]]))
5
+ end
6
+
7
+ def expect_lenient_search(resource, params:, returns:)
8
+ ex = api_expects(resource, :index, "Find the #{resource}") do |p|
9
+ params.each do |key, expected|
10
+ actual = p[key] || p[key.to_sym] || p[key.to_s]
11
+ assert_equal expected.to_s, actual.to_s, "key: '#{key}', resource: #{resource}"
12
+ end
13
+ end
14
+ returns = [returns] unless returns.is_a? Array
15
+ ex.returns(index_response(returns))
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+
3
+ describe 'simple-content-access disable' do
4
+ before do
5
+ @cmd = %w(simple-content-access disable)
6
+ end
7
+
8
+ let(:organization_id) { 3 }
9
+
10
+ it "disables with required options" do
11
+ params = ["--organization-id=#{organization_id}"]
12
+
13
+ api_expects(:simple_content_access, :eligible).
14
+ with_params('organization_id' => organization_id).
15
+ returns("simple_content_access_eligible" => true)
16
+
17
+ api_expects(:simple_content_access, :disable)
18
+ .with_params('organization_id' => organization_id)
19
+ run_cmd(@cmd + params)
20
+ end
21
+
22
+ it 'fails on missing required params' do
23
+ params = []
24
+
25
+ result = run_cmd(@cmd + params)
26
+ expected_error = "Could not disable Simple Content Access for this organization"
27
+
28
+ assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
29
+ assert_equal(result.err[/#{expected_error}/], expected_error)
30
+ end
31
+
32
+ it 'fails on non eligible org' do
33
+ params = ["--organization-id=#{organization_id}"]
34
+
35
+ api_expects(:simple_content_access, :eligible).
36
+ with_params('organization_id' => organization_id).
37
+ returns("simple_content_access_eligible" => false)
38
+
39
+ api_expects(:simple_content_access, :disable)
40
+ .with_params('organization_id' => organization_id).never
41
+ result = run_cmd(@cmd + params)
42
+
43
+ expected_error = "Could not disable Simple Content Access for this organization"
44
+
45
+ assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
46
+ assert_equal(result.err[/#{expected_error}/], expected_error)
47
+ end
48
+ end
@@ -0,0 +1,46 @@
1
+ require File.join(File.dirname(__FILE__), '../../test_helper')
2
+
3
+ describe 'simple-content-access enable' do
4
+ before do
5
+ @cmd = %w(simple-content-access enable)
6
+ end
7
+
8
+ let(:organization_id) { 3 }
9
+
10
+ it "enables with required options" do
11
+ params = ["--organization-id=#{organization_id}"]
12
+ api_expects(:simple_content_access, :eligible).
13
+ with_params('organization_id' => organization_id).
14
+ returns("simple_content_access_eligible" => true)
15
+
16
+ api_expects(:simple_content_access, :enable)
17
+ .with_params('organization_id' => organization_id)
18
+ run_cmd(@cmd + params)
19
+ end
20
+
21
+ it 'fails on missing required params' do
22
+ params = []
23
+ result = run_cmd(@cmd + params)
24
+ expected_error = "Could not enable Simple Content Access for this organization"
25
+
26
+ assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
27
+ assert_equal(result.err[/#{expected_error}/], expected_error)
28
+ end
29
+
30
+ it 'fails on non eligible org' do
31
+ params = ["--organization-id=#{organization_id}"]
32
+
33
+ api_expects(:simple_content_access, :eligible).
34
+ with_params('organization_id' => organization_id).
35
+ returns("simple_content_access_eligible" => false)
36
+
37
+ api_expects(:simple_content_access, :enable)
38
+ .with_params('organization_id' => organization_id).never
39
+ result = run_cmd(@cmd + params)
40
+
41
+ expected_error = "Could not enable Simple Content Access for this organization"
42
+
43
+ assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE)
44
+ assert_equal(result.err[/#{expected_error}/], expected_error)
45
+ end
46
+ end