hammer_cli_katello 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_katello/foreman_search_options_creators.rb +0 -12
  3. data/lib/hammer_cli_katello/host_collection.rb +6 -0
  4. data/lib/hammer_cli_katello/host_errata.rb +1 -1
  5. data/lib/hammer_cli_katello/repository.rb +0 -27
  6. data/lib/hammer_cli_katello/version.rb +1 -1
  7. data/test/data/2.5/foreman_api.json +1 -0
  8. data/test/data/3.0/foreman_api.json +1 -0
  9. data/test/data/3.10/foreman_api.json +1 -0
  10. data/test/data/3.11/foreman_api.json +1 -0
  11. data/test/data/3.12/foreman_api.json +1 -0
  12. data/test/data/3.13/foreman_api.json +1 -0
  13. data/test/data/3.14/foreman_api.json +1 -0
  14. data/test/data/3.15/foreman_api.json +1 -0
  15. data/test/data/3.16/foreman_api.json +1 -0
  16. data/test/data/3.17/foreman_api.json +1 -0
  17. data/test/data/3.18/foreman_api.json +1 -0
  18. data/test/data/3.19/foreman_api.json +1 -0
  19. data/test/data/3.2/foreman_api.json +1 -0
  20. data/test/data/3.4/foreman_api.json +1 -0
  21. data/test/data/3.5/foreman_api.json +1 -0
  22. data/test/data/3.6/foreman_api.json +1 -0
  23. data/test/data/3.7/foreman_api.json +1 -0
  24. data/test/data/3.8/foreman_api.json +1 -0
  25. data/test/data/3.9/foreman_api.json +1 -0
  26. data/test/data/4.0/foreman_api.json +1 -0
  27. data/test/data/4.1/foreman_api.json +1 -0
  28. data/test/data/Readme.md +5 -0
  29. data/test/functional/activation_key/add_host_collection_test.rb +62 -0
  30. data/test/functional/activation_key/content_override_test.rb +92 -0
  31. data/test/functional/activation_key/create_test.rb +33 -0
  32. data/test/functional/activation_key/data/activation_key.json +17 -0
  33. data/test/functional/activation_key/info_test.rb +29 -0
  34. data/test/functional/activation_key/list_test.rb +68 -0
  35. data/test/functional/activation_key/product_content_test.rb +23 -0
  36. data/test/functional/activation_key/remove_host_collection_test.rb +62 -0
  37. data/test/functional/activation_key/subscriptions_test.rb +74 -0
  38. data/test/functional/activation_key/update_test.rb +26 -0
  39. data/test/functional/apipie_helper_test.rb +31 -0
  40. data/test/functional/capsule/capsule_helpers.rb +13 -0
  41. data/test/functional/capsule/content/add_lifecycle_environment_test.rb +40 -0
  42. data/test/functional/capsule/content/cancel_synchronization_test.rb +42 -0
  43. data/test/functional/capsule/content/capsule_content_helpers.rb +24 -0
  44. data/test/functional/capsule/content/data/library_env.json +47 -0
  45. data/test/functional/capsule/content/data/sync_status.json +6 -0
  46. data/test/functional/capsule/content/data/sync_tasks.json +62 -0
  47. data/test/functional/capsule/content/info_test.rb +61 -0
  48. data/test/functional/capsule/content/lifecycle_environments_test.rb +19 -0
  49. data/test/functional/capsule/content/remove_lifecycle_environment_test.rb +40 -0
  50. data/test/functional/capsule/content/synchronization_status_test.rb +107 -0
  51. data/test/functional/capsule/info_test.rb +25 -0
  52. data/test/functional/capsule/list_test.rb +24 -0
  53. data/test/functional/content_credentials/create_test.rb +32 -0
  54. data/test/functional/content_credentials/data/test_cert.json +43 -0
  55. data/test/functional/content_credentials/info_test.rb +50 -0
  56. data/test/functional/content_credentials/list_test.rb +66 -0
  57. data/test/functional/content_export/complete/library_test.rb +155 -0
  58. data/test/functional/content_export/complete/version_test.rb +252 -0
  59. data/test/functional/content_export/content_export_helpers.rb +26 -0
  60. data/test/functional/content_export/generate_metadata_test.rb +64 -0
  61. data/test/functional/content_export/incremental/library_test.rb +172 -0
  62. data/test/functional/content_export/incremental/version_test.rb +268 -0
  63. data/test/functional/content_export/list_test.rb +64 -0
  64. data/test/functional/content_import/library_test.rb +85 -0
  65. data/test/functional/content_import/list_test.rb +65 -0
  66. data/test/functional/content_import/metadata.json +1 -0
  67. data/test/functional/content_import/version_test.rb +85 -0
  68. data/test/functional/content_view/add_content_view_version_test.rb +88 -0
  69. data/test/functional/content_view/add_repository_test.rb +21 -0
  70. data/test/functional/content_view/component/add_test.rb +177 -0
  71. data/test/functional/content_view/component/list_test.rb +55 -0
  72. data/test/functional/content_view/component/remove_test.rb +107 -0
  73. data/test/functional/content_view/component/update_test.rb +134 -0
  74. data/test/functional/content_view/content_view_helpers.rb +20 -0
  75. data/test/functional/content_view/copy_test.rb +53 -0
  76. data/test/functional/content_view/create_test.rb +34 -0
  77. data/test/functional/content_view/delete_test.rb +62 -0
  78. data/test/functional/content_view/filter/create_test.rb +57 -0
  79. data/test/functional/content_view/filter/delete_test.rb +90 -0
  80. data/test/functional/content_view/filter/info_test.rb +89 -0
  81. data/test/functional/content_view/filter/list_test.rb +98 -0
  82. data/test/functional/content_view/filter/update_test.rb +91 -0
  83. data/test/functional/content_view/list_test.rb +68 -0
  84. data/test/functional/content_view/publish_test.rb +24 -0
  85. data/test/functional/content_view/purge_test.rb +97 -0
  86. data/test/functional/content_view/remove_content_view_version_test.rb +88 -0
  87. data/test/functional/content_view/remove_test.rb +79 -0
  88. data/test/functional/content_view/update_test.rb +53 -0
  89. data/test/functional/content_view/version/incremental_update_test.rb +108 -0
  90. data/test/functional/content_view/version/list_test.rb +44 -0
  91. data/test/functional/content_view/version/promote_test.rb +34 -0
  92. data/test/functional/content_view/version/republish_repositories_test.rb +34 -0
  93. data/test/functional/content_view/version/update_test.rb +48 -0
  94. data/test/functional/erratum/erratum_helpers.rb +91 -0
  95. data/test/functional/erratum/info_test.rb +29 -0
  96. data/test/functional/erratum/list_test.rb +108 -0
  97. data/test/functional/file/file_helpers.rb +13 -0
  98. data/test/functional/file/info_test.rb +162 -0
  99. data/test/functional/file/list_test.rb +112 -0
  100. data/test/functional/filter_rule/create_test.rb +99 -0
  101. data/test/functional/filter_rule/delete_test.rb +104 -0
  102. data/test/functional/filter_rule/filter_rule_helpers.rb +12 -0
  103. data/test/functional/filter_rule/info_test.rb +104 -0
  104. data/test/functional/filter_rule/list_test.rb +91 -0
  105. data/test/functional/filter_rule/update_test.rb +104 -0
  106. data/test/functional/host/errata/apply_test.rb +45 -0
  107. data/test/functional/host/errata/info_test.rb +27 -0
  108. data/test/functional/host/errata/list_test.rb +49 -0
  109. data/test/functional/host/errata/recalculate_test.rb +40 -0
  110. data/test/functional/host/extensions/create_test.rb +95 -0
  111. data/test/functional/host/extensions/data/host.json +320 -0
  112. data/test/functional/host/extensions/data/host_list.json +117 -0
  113. data/test/functional/host/extensions/info_test.rb +35 -0
  114. data/test/functional/host/extensions/list_test.rb +21 -0
  115. data/test/functional/host/extensions/update_test.rb +70 -0
  116. data/test/functional/host/host_helpers.rb +8 -0
  117. data/test/functional/host/subscription/attach_test.rb +54 -0
  118. data/test/functional/host/subscription/auto_attach_test.rb +35 -0
  119. data/test/functional/host/subscription/content_override_test.rb +96 -0
  120. data/test/functional/host/subscription/product_content_test.rb +27 -0
  121. data/test/functional/host/subscription/register_test.rb +53 -0
  122. data/test/functional/host/subscription/remove_test.rb +52 -0
  123. data/test/functional/host/subscription/unregister_test.rb +37 -0
  124. data/test/functional/host/traces/list_test.rb +37 -0
  125. data/test/functional/host/traces/resolve_test.rb +31 -0
  126. data/test/functional/host_collection/add_host_test.rb +90 -0
  127. data/test/functional/host_collection/content_api_expectations.rb +35 -0
  128. data/test/functional/host_collection/content_install_test.rb +62 -0
  129. data/test/functional/host_collection/content_remove_test.rb +37 -0
  130. data/test/functional/host_collection/content_update_test.rb +37 -0
  131. data/test/functional/host_collection/copy_test.rb +64 -0
  132. data/test/functional/host_collection/create_test.rb +54 -0
  133. data/test/functional/host_collection/delete_test.rb +57 -0
  134. data/test/functional/host_collection/hosts_test.rb +39 -0
  135. data/test/functional/host_collection/info_test.rb +57 -0
  136. data/test/functional/host_collection/list_test.rb +63 -0
  137. data/test/functional/host_collection/remove_host_test.rb +90 -0
  138. data/test/functional/host_collection/update_test.rb +57 -0
  139. data/test/functional/hostgroup/create_test.rb +112 -0
  140. data/test/functional/hostgroup/data/hostgroup.json +50 -0
  141. data/test/functional/hostgroup/info_test.rb +33 -0
  142. data/test/functional/hostgroup/update_test.rb +120 -0
  143. data/test/functional/lifecycle_environment/create_test.rb +14 -0
  144. data/test/functional/lifecycle_environment/lifecycle_environment_helpers.rb +18 -0
  145. data/test/functional/lifecycle_environment/list_test.rb +38 -0
  146. data/test/functional/lifecycle_environment/update_test.rb +14 -0
  147. data/test/functional/local_helper_test.rb +30 -0
  148. data/test/functional/module_stream/info_test.rb +58 -0
  149. data/test/functional/module_stream/list_test.rb +53 -0
  150. data/test/functional/organization/delete_test.rb +26 -0
  151. data/test/functional/organization/info_test.rb +22 -0
  152. data/test/functional/organization/organization_helpers.rb +10 -0
  153. data/test/functional/package/list_test.rb +158 -0
  154. data/test/functional/package_group/list_test.rb +38 -0
  155. data/test/functional/ping_test.rb +59 -0
  156. data/test/functional/product/create_test.rb +54 -0
  157. data/test/functional/product/delete_test.rb +41 -0
  158. data/test/functional/product/info_test.rb +33 -0
  159. data/test/functional/product/list_test.rb +58 -0
  160. data/test/functional/product/product_helpers.rb +24 -0
  161. data/test/functional/product/remove_sync_plan_test.rb +35 -0
  162. data/test/functional/product/set_sync_plan_test.rb +49 -0
  163. data/test/functional/product/update_proxy.rb +48 -0
  164. data/test/functional/product/update_test.rb +46 -0
  165. data/test/functional/repository/create_test.rb +21 -0
  166. data/test/functional/repository/delete_test.rb +95 -0
  167. data/test/functional/repository/info_test.rb +156 -0
  168. data/test/functional/repository/list_test.rb +68 -0
  169. data/test/functional/repository/remove_content_test.rb +108 -0
  170. data/test/functional/repository/repository_helpers.rb +18 -0
  171. data/test/functional/repository/synchronize_test.rb +57 -0
  172. data/test/functional/repository/update_test.rb +149 -0
  173. data/test/functional/repository/upload_test.rb +345 -0
  174. data/test/functional/repository_set/available_repositories_test.rb +18 -0
  175. data/test/functional/repository_set/disable_test.rb +42 -0
  176. data/test/functional/repository_set/enable_test.rb +42 -0
  177. data/test/functional/repository_set/info_test.rb +17 -0
  178. data/test/functional/repository_set/list_test.rb +18 -0
  179. data/test/functional/repository_set/repository_set_helpers.rb +20 -0
  180. data/test/functional/search_helpers.rb +17 -0
  181. data/test/functional/simple_content_access/disable_test.rb +48 -0
  182. data/test/functional/simple_content_access/enable_test.rb +46 -0
  183. data/test/functional/srpm/list_test.rb +92 -0
  184. data/test/functional/subscription/list_test.rb +86 -0
  185. data/test/functional/sync_plan/create_test.rb +60 -0
  186. data/test/functional/sync_plan/delete_test.rb +46 -0
  187. data/test/functional/sync_plan/info_test.rb +37 -0
  188. data/test/functional/sync_plan/list_test.rb +31 -0
  189. data/test/functional/sync_plan/sync_plan_helpers.rb +8 -0
  190. data/test/functional/sync_plan/update_test.rb +44 -0
  191. data/test/functional/test_helper.rb +24 -0
  192. data/test/task_helper.rb +7 -0
  193. data/test/test_helper.rb +38 -0
  194. data/test/unit/id_name_options_validator_test.rb +96 -0
  195. data/test/unit/id_resolver_test.rb +58 -0
  196. data/test/unit/messages_test.rb +7 -0
  197. data/test/unit/search_options_creators_test.rb +145 -0
  198. metadata +388 -6
@@ -0,0 +1,345 @@
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(:upload_response) do
21
+ {
22
+ "upload_id" => upload_id,
23
+ "_href" => _href
24
+ }
25
+ end
26
+
27
+ it "uploads a package" do
28
+ file = File.new("test.rpm", "w")
29
+
30
+ params = ["--id=#{repo_id}", "--path=#{path}"]
31
+
32
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
33
+ .with_params('repository_id' => repo_id, :size => file.size)
34
+
35
+ ex.returns(upload_response)
36
+
37
+ # rubocop:disable LineLength
38
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
39
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
40
+ :uploads => [{
41
+ :id => '1234',
42
+ :name => 'test.rpm',
43
+ :size => 0,
44
+ :content_unit_id => nil,
45
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
46
+ }]
47
+ )
48
+ # rubocop:enable LineLength
49
+
50
+ ex2.returns("")
51
+
52
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
53
+ .with_params('id' => upload_id, 'repository_id' => repo_id)
54
+
55
+ ex3.returns("")
56
+
57
+ result = run_cmd(@cmd + params)
58
+ assert_equal(result.exit_code, 0)
59
+ File.delete("test.rpm")
60
+ end
61
+
62
+ it "uploads srpm with content-type" do
63
+ file = File.new("test.src.rpm", "w")
64
+ params = ["--id=#{repo_id}", '--path=./test.src.rpm', '--content-type=srpm']
65
+
66
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
67
+ .with_params('repository_id' => repo_id, :content_type => 'srpm', :size => file.size)
68
+
69
+ ex.returns(upload_response)
70
+
71
+ # rubocop:disable LineLength
72
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
73
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true, :content_type => 'srpm',
74
+ :uploads => [{
75
+ :id => '1234',
76
+ :name => 'test.src.rpm',
77
+ :size => 0,
78
+ :content_unit_id => nil,
79
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
80
+ }]
81
+ )
82
+
83
+ # rubocop:enable LineLength
84
+ ex2.returns("")
85
+
86
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
87
+ .with_params(:id => upload_id, :repository_id => repo_id)
88
+
89
+ ex3.returns("")
90
+
91
+ result = run_cmd(@cmd + params)
92
+ assert_equal(result.exit_code, 0)
93
+ File.delete("test.src.rpm")
94
+ end
95
+
96
+ it 'fails upload of srpm with no content-type' do
97
+ file = File.new("test.src.rpm", "w")
98
+
99
+ params = ["--id=#{repo_id}", '--path=./test.src.rpm']
100
+
101
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
102
+ .with_params('repository_id' => repo_id, :size => file.size)
103
+
104
+ ex.returns(upload_response)
105
+
106
+ # rubocop:disable LineLength
107
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
108
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
109
+ :uploads => [{
110
+ :id => '1234',
111
+ :name => 'test.src.rpm',
112
+ :size => 0,
113
+ :content_unit_id => nil,
114
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
115
+ }]
116
+ )
117
+ # rubocop:enable LineLength
118
+
119
+ ex2.returns(400)
120
+
121
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
122
+ .with_params(:id => upload_id, :repository_id => repo_id)
123
+
124
+ ex3.returns("")
125
+
126
+ result = run_cmd(@cmd + params)
127
+ assert_equal(result.exit_code, 70)
128
+ File.delete("test.src.rpm")
129
+ end
130
+
131
+ it "uploads a docker image" do
132
+ file = File.new("test.rpm", "w")
133
+
134
+ params = ["--id=#{repo_id}", "--path=#{path}"]
135
+
136
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
137
+ .with_params(:repository_id => repo_id, :size => file.size)
138
+
139
+ ex.returns(upload_response)
140
+
141
+ # rubocop:disable LineLength
142
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
143
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
144
+ :uploads => [{
145
+ :id => '1234',
146
+ :name => 'test.rpm',
147
+ :size => 0,
148
+ :content_unit_id => nil,
149
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
150
+ }]
151
+ )
152
+ # rubocop:enable LineLength
153
+ ex2.returns('output' => {'upload_results' => [{'type' => 'docker_manifest',
154
+ 'digest' => 'sha256:1234'}]})
155
+
156
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
157
+ .with_params(:id => upload_id, :repository_id => repo_id)
158
+
159
+ ex3.returns("")
160
+
161
+ result = run_cmd(@cmd + params)
162
+ assert_equal(result.exit_code, 0)
163
+ File.delete("test.rpm")
164
+ end
165
+
166
+ it "uploads a package with an organization-id" do
167
+ file = File.new("test.rpm", "w")
168
+
169
+ params = ["--name=test_repo", "--product=test_product", "--organization-id=#{org_id}",
170
+ "--path=#{path}"]
171
+
172
+ expect_product_search(org_id, 'test_product', product_id)
173
+
174
+ expect_repository_search(product_id, 'test_repo', repo_id)
175
+
176
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
177
+ .with_params(:repository_id => repo_id, :size => file.size)
178
+
179
+ ex.returns(upload_response)
180
+
181
+ # rubocop:disable LineLength
182
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
183
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
184
+ :uploads => [{
185
+ :id => '1234',
186
+ :name => 'test.rpm',
187
+ :size => 0,
188
+ :content_unit_id => nil,
189
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
190
+ }]
191
+ )
192
+ # rubocop:enable LineLength
193
+
194
+ ex2.returns("")
195
+
196
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
197
+ .with_params(:id => upload_id, :repository_id => repo_id)
198
+
199
+ ex3.returns("")
200
+
201
+ result = run_cmd(@cmd + params)
202
+ assert_equal(result.exit_code, 0)
203
+ File.delete("test.rpm")
204
+ end
205
+
206
+ it "supports globs" do
207
+ file = File.new("test.rpm", "w")
208
+
209
+ params = ["--id=#{repo_id}", "--path={test}.[r{1}]pm"]
210
+
211
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
212
+ .with_params(:repository_id => repo_id, :size => file.size)
213
+
214
+ ex.returns(upload_response)
215
+
216
+ # rubocop:disable LineLength
217
+ ex2 = api_expects(:repositories, :import_uploads, 'Take in an upload')
218
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
219
+ :uploads => [{
220
+ :id => '1234',
221
+ :name => 'test.rpm',
222
+ :size => 0,
223
+ :content_unit_id => nil,
224
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
225
+ }]
226
+ )
227
+ # rubocop:enable LineLength
228
+
229
+ ex2.returns("")
230
+
231
+ ex3 = api_expects(:content_uploads, :destroy, "Delete the upload")
232
+ .with_params(:id => upload_id, :repository_id => repo_id)
233
+
234
+ ex3.returns("")
235
+
236
+ result = run_cmd(@cmd + params)
237
+ assert_equal(result.exit_code, 0)
238
+ File.delete("test.rpm")
239
+ end
240
+
241
+ it "only syncs the capsule on the last file import" do
242
+ File.new("test1.rpm", "w")
243
+ File.new("test2.rpm", "w")
244
+
245
+ params = ["--id=#{repo_id}", "--path=test*.rpm"]
246
+
247
+ # Begin first upload cycle
248
+
249
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
250
+ .with_params(:repository_id => repo_id)
251
+
252
+ ex.returns(upload_response)
253
+
254
+ # rubocop:disable LineLength
255
+ ex = api_expects(:repositories, :import_uploads, 'Take in an upload')
256
+ .with_params(:id => repo_id, :sync_capsule => false, :publish_repository => false,
257
+ :uploads => [{
258
+ :id => '1234',
259
+ :name => 'test1.rpm',
260
+ :size => 0,
261
+ :content_unit_id => nil,
262
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
263
+ }]
264
+ )
265
+ # rubocop:enable LineLength
266
+
267
+ ex.returns("")
268
+
269
+ ex = api_expects(:content_uploads, :destroy, "Delete the upload")
270
+ .with_params(:id => upload_id, :repository_id => repo_id)
271
+
272
+ ex.returns("")
273
+
274
+ # Begin second upload cycle
275
+
276
+ ex = api_expects(:content_uploads, :create, "Create upload for content")
277
+ .with_params(:repository_id => repo_id)
278
+
279
+ ex.returns(upload_response)
280
+
281
+ # rubocop:disable LineLength
282
+ ex = api_expects(:repositories, :import_uploads, 'Take in an upload')
283
+ .with_params(:id => repo_id, :sync_capsule => true, :publish_repository => true,
284
+ :uploads => [{
285
+ :id => '1234',
286
+ :name => 'test2.rpm',
287
+ :size => 0,
288
+ :content_unit_id => nil,
289
+ :checksum => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
290
+ }]
291
+ )
292
+ # rubocop:enable LineLength
293
+
294
+ ex.returns("")
295
+
296
+ ex = api_expects(:content_uploads, :destroy, "Delete the upload")
297
+ .with_params(:id => upload_id, :repository_id => repo_id)
298
+
299
+ ex.returns("")
300
+
301
+ result = run_cmd(@cmd + params)
302
+ assert_equal(result.exit_code, 0)
303
+ File.delete("test1.rpm")
304
+ File.delete("test2.rpm")
305
+ end
306
+
307
+ it "errors if there are no matching files" do
308
+ params = ["--id=#{repo_id}", "--path=#{path}"]
309
+
310
+ result = run_cmd(@cmd + params)
311
+
312
+ assert_equal "Could not find any files matching PATH\n", result.err
313
+ assert_equal HammerCLI::EX_NOINPUT, result.exit_code
314
+ end
315
+
316
+ describe 'requires' do
317
+ it 'repository options' do
318
+ api_expects_no_call
319
+ error = run_cmd(@cmd + %W(--path #{path})).err
320
+ assert error.include?('--id, --name is required'), "Actual result: #{error}"
321
+ end
322
+
323
+ it 'product options when repository name is specified' do
324
+ api_expects_no_call
325
+ error = run_cmd(@cmd + %W(--name repo1 --path #{path})).err
326
+ assert(error.include?('--product, --product-id is required'), "Actual result: #{error}")
327
+ end
328
+
329
+ it 'organization options when product name is specified' do
330
+ api_expects_no_call
331
+ error = run_cmd(@cmd + %W(--name repo1 --product product2 --path #{path})).err
332
+ assert(error.include?('--organization-id, --organization, --organization-label is required'),
333
+ "Actual result: #{error}")
334
+ end
335
+ end
336
+
337
+ describe 'disallows' do
338
+ it 'product options when repository ID is specified' do
339
+ api_expects_no_call
340
+ error = run_cmd(@cmd + %W(--id 1 --product product2 --path #{path})).err
341
+ assert(error.include?('Cannot specify both product options and repository ID'),
342
+ "Actual result: #{error}")
343
+ end
344
+ end
345
+ 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