artifactory 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,30 +3,343 @@ require 'spec_helper'
3
3
  module Artifactory
4
4
  describe Resource::Build do
5
5
  let(:client) { double(:client) }
6
+ let(:time) { Time.now.utc.round }
6
7
 
7
8
  before(:each) do
8
9
  allow(Artifactory).to receive(:client).and_return(client)
9
10
  allow(client).to receive(:get).and_return(response) if defined?(response)
11
+
12
+ subject.name = 'wicket'
13
+ subject.number = '51'
10
14
  end
11
15
 
12
16
  describe '.all' do
13
- let(:response) { ['a', 'b', 'c'] }
17
+ let(:response) do
18
+ {
19
+ 'uri' => "#{Artifactory.endpoint}/api/build/wicket",
20
+ 'buildsNumbers' => [
21
+ {
22
+ 'uri' => "/51",
23
+ 'started' => '2014-01-01 12:00:00',
24
+ },
25
+ {
26
+ 'uri' => "/52",
27
+ 'started' => '2015-01-05 12:00:00',
28
+ },
29
+ ]
30
+ }
31
+ end
14
32
 
15
- it 'gets /api/build' do
16
- expect(client).to receive(:get).with('/api/build').once
17
- described_class.all
33
+ before do
34
+ allow(described_class).to receive(:find).with('wicket', '51', client: client).and_return('51')
35
+ allow(described_class).to receive(:find).with('wicket', '52', client: client).and_return('52')
36
+ end
37
+
38
+ it 'GETS /api/build/#{name}' do
39
+ expect(client).to receive(:get).with('/api/build/wicket').once
40
+ described_class.all('wicket')
18
41
  end
19
42
 
20
43
  context 'when there are builds' do
21
44
  it 'returns the builds' do
22
- expect(described_class.all).to eq(['a', 'b', 'c'])
45
+ expect(described_class.all('wicket')).to eq(['51', '52'])
23
46
  end
24
47
  end
25
48
 
26
49
  context 'when the system has no builds' do
27
50
  it 'returns an empty array' do
28
51
  allow(client).to receive(:get).and_raise(Error::HTTPError.new('status' => 404))
29
- expect(described_class.all).to be_empty
52
+ expect(described_class.all('wicket')).to be_empty
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '.find' do
58
+ let(:response) { {'buildInfo' => {}} }
59
+
60
+ it 'GETS /api/repositories/#{name}/#{number}' do
61
+ expect(client).to receive(:get).with("/api/build/wicket/51").once
62
+ described_class.find('wicket', 51)
63
+ end
64
+
65
+ context 'when the build does not exist' do
66
+ it 'returns nil' do
67
+ allow(client).to receive(:get).and_raise(Error::HTTPError.new('status' => 404))
68
+ expect(described_class.find('wicket', '4445')).to be_nil
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '.from_hash' do
74
+ let(:hash) do
75
+ {
76
+ "properties" => {
77
+ "buildInfo.env.JAVA_HOME" => "/usr/jdk/latest",
78
+ },
79
+ "version" => "1.0.1",
80
+ "name" => "Maven2-3",
81
+ "number" => "9",
82
+ "type" => "MAVEN",
83
+ "buildAgent" => {
84
+ "name" => "Maven",
85
+ "version" => "3.0.5"
86
+ },
87
+ "agent" => {
88
+ "name" => "Jenkins",
89
+ "version" => "1.565.2"
90
+ },
91
+ "started" => time.iso8601(3),
92
+ "durationMillis" => 8926,
93
+ "artifactoryPrincipal" => "admin",
94
+ "url" => "http://localhost:8080/job/Maven2-3/9/",
95
+ "vcsRevision" => "83049487ecc61bef3dce798838e7a9457e174a5a",
96
+ "vcsUrl" => "https://github.com/aseftel/project-examples",
97
+ "licenseControl" => {
98
+ "runChecks" => false,
99
+ "includePublishedArtifacts" => false,
100
+ "autoDiscover" => true,
101
+ "scopesList" => "",
102
+ "licenseViolationsRecipientsList" => ""
103
+ },
104
+ "buildRetention" => {
105
+ "count" => -1,
106
+ "deleteBuildArtifacts" => true,
107
+ "buildNumbersNotToBeDiscarded" => []
108
+ },
109
+ "modules" => modules,
110
+ "governance" => {
111
+ "blackDuckProperties" => {
112
+ "runChecks" => false,
113
+ "includePublishedArtifacts" => false,
114
+ "autoCreateMissingComponentRequests" => false,
115
+ "autoDiscardStaleComponentRequests" => false
116
+ }
117
+ }
118
+ }
119
+ end
120
+ let(:modules) do
121
+ [
122
+ {
123
+ "properties" => {
124
+ "project.build.sourceEncoding" => "UTF-8"
125
+ },
126
+ "id" => "org.jfrog.test:multi:2.19-SNAPSHOT",
127
+ "artifacts" => [
128
+ {
129
+ "type" => "pom",
130
+ "sha1" => "045b66ebbf8504002b626f592d087612aca36582",
131
+ "md5" => "c25542a353dab1089cd186465dc47a68",
132
+ "name" => "multi-2.19-SNAPSHOT.pom"
133
+ }
134
+ ]
135
+ },
136
+ {
137
+ "properties" => {
138
+ "project.build.sourceEncoding" => "UTF-8"
139
+ },
140
+ "id" => "org.jfrog.test:multi1:2.19-SNAPSHOT",
141
+ "artifacts"=> [
142
+ {
143
+ "type" => "jar",
144
+ "sha1" => "f4c5c9cb3091011ec2a895b3dedd7f10d847361c",
145
+ "md5" => "d1fd850a3582efba41092c624e0b46b8",
146
+ "name" => "multi1-2.19-SNAPSHOT.jar"
147
+ },
148
+ {
149
+ "type" => "pom",
150
+ "sha1" => "2ddbf9824676f548d637726d3bcbb494ba823090",
151
+ "md5" => "a64aa7f305f63a85e63a0155ff0fb404",
152
+ "name" => "multi1-2.19-SNAPSHOT.pom"
153
+ },
154
+ {
155
+ "type" => "jar",
156
+ "sha1" => "6fdd143a44cea3a2636660c5c266c95c27e50abc",
157
+ "md5" => "12a1e438f4bef8c4b740fe848a1704a4",
158
+ "id" => "org.slf4j:slf4j-simple:1.4.3",
159
+ "scopes" => [ "compile" ]
160
+ },
161
+ {
162
+ "type" => "jar",
163
+ "sha1" => "496e91f7df8a0417e00cecdba840cdf0e5f2472c",
164
+ "md5" => "76a412a37c9d18659d2dacccdb1c24ff",
165
+ "id" => "org.jenkins-ci.lib:dry-run-lib:0.1",
166
+ "scopes" => [ "compile" ]
167
+ }
168
+ ]
169
+ },
170
+ {
171
+ "properties" => {
172
+ "daversion" => "2.19-SNAPSHOT",
173
+ "project.build.sourceEncoding"=>"UTF-8"
174
+ },
175
+ "id" => "org.jfrog.test:multi2:2.19-SNAPSHOT",
176
+ "artifacts" => [
177
+ {
178
+ "type" => "txt",
179
+ "name" => "multi2-2.19-SNAPSHOT.txt"
180
+ },
181
+ {
182
+ "type" => "java-source-jar",
183
+ "sha1" => "49108b0c7db5fdb4efe3c29a5a9f54e806aecb62",
184
+ "md5" => "0e2c5473cf2a9b694afb4a2e8da34b53",
185
+ "name" => "multi2-2.19-SNAPSHOT-sources.jar"},
186
+ {
187
+ "type" => "jar",
188
+ "sha1" => "476e89d290ae36dabb38ff22f75f264ae019d542",
189
+ "md5" => "fa9b3df58ac040fffcff9310f261be80",
190
+ "name" => "multi2-2.19-SNAPSHOT.jar"
191
+ },
192
+ {
193
+ "type" => "pom",
194
+ "sha1" => "b719b90364e5ae38cda358072f61f821bdae5d5d",
195
+ "md5" => "8d5060005235d75907baca4490cf60bf",
196
+ "name" => "multi2-2.19-SNAPSHOT.pom"
197
+ }
198
+ ],
199
+ "dependencies"=> [
200
+ {
201
+ "type" => "jar",
202
+ "sha1" => "19d4e90b43059058f6e056f794f0ea4030d60b86",
203
+ "md5" => "dcd95bcb84b09897b2b66d4684c040da",
204
+ "id" => "xpp3:xpp3_min:1.1.4c",
205
+ "scopes" => [ "provided" ]
206
+ },
207
+ {
208
+ "type" => "jar",
209
+ "sha1" => "e2d866af5518e81282838301b49a1bd2452619d3",
210
+ "md5" => "e9e4b59c69305ba3698dd61c5dfc4fc8",
211
+ "id" => "org.jvnet.hudson.plugins:perforce:1.3.7",
212
+ "scopes" => [ "compile" ]
213
+ },
214
+ {
215
+ "type" => "jar",
216
+ "sha1" => "6fdd143a44cea3a2636660c5c266c95c27e50abc",
217
+ "md5" => "12a1e438f4bef8c4b740fe848a1704a4",
218
+ "id" => "org.slf4j:slf4j-simple:1.4.3",
219
+ "scopes" => [ "compile" ]
220
+ },
221
+ {
222
+ "type" => "jar",
223
+ "sha1" => "496e91f7df8a0417e00cecdba840cdf0e5f2472c",
224
+ "md5" => "76a412a37c9d18659d2dacccdb1c24ff",
225
+ "id" => "org.jenkins-ci.lib:dry-run-lib:0.1",
226
+ "scopes" => [ "compile" ]
227
+ }
228
+ ]
229
+ },
230
+ {
231
+ "properties" => {
232
+ "project.build.sourceEncoding" => "UTF-8"
233
+ },
234
+ "id" => "org.jfrog.test:multi3:2.19-SNAPSHOT",
235
+ "artifacts" => [
236
+ {
237
+ "type" => "java-source-jar",
238
+ "sha1" => "3cd104785167ac37ef999431f308ffef10810348",
239
+ "md5" => "c683276f8dda97078ae8eb5e26bb3ee5",
240
+ "name" => "multi3-2.19-SNAPSHOT-sources.jar"
241
+ },
242
+ {
243
+ "type" => "war",
244
+ "sha1" => "34aeebeb805b23922d9d05507404533518cf81e4",
245
+ "md5" => "55af06a2175cfb23cc6dc3931475b57c",
246
+ "name" => "multi3-2.19-SNAPSHOT.war"
247
+ },
248
+ {
249
+ "type" => "jar",
250
+ "sha1" => "496e91f7df8a0417e00cecdba840cdf0e5f2472c",
251
+ "md5" => "76a412a37c9d18659d2dacccdb1c24ff",
252
+ "id" => "org.jenkins-ci.lib:dry-run-lib:0.1",
253
+ "scopes" => [ "compile" ]
254
+ },
255
+ {
256
+ "type" => "jar",
257
+ "sha1" => "7e9978fdb754bce5fcd5161133e7734ecb683036",
258
+ "md5" => "7df83e09e41d742cc5fb20d16b80729c",
259
+ "id" => "hsqldb:hsqldb:1.8.0.10",
260
+ "scopes" => [ "runtime" ]
261
+ }
262
+ ]
263
+ }
264
+ ]
265
+ end
266
+
267
+ it 'creates a new instance' do
268
+ instance = described_class.from_hash(hash)
269
+ expect(instance.properties).to eq("buildInfo.env.JAVA_HOME" => "/usr/jdk/latest")
270
+ expect(instance.version).to eq('1.0.1')
271
+ expect(instance.name).to eq('Maven2-3')
272
+ expect(instance.number).to eq('9')
273
+ expect(instance.type).to eq('MAVEN')
274
+ expect(instance.build_agent).to eq(
275
+ "name" => "Maven",
276
+ "version" => "3.0.5",
277
+ )
278
+ expect(instance.agent).to eq(
279
+ "name" => "Jenkins",
280
+ "version" => "1.565.2"
281
+ )
282
+ expect(instance.started).to eq(time)
283
+ expect(instance.duration_millis).to eq(8926)
284
+ expect(instance.artifactory_principal).to eq('admin')
285
+ expect(instance.url).to eq('http://localhost:8080/job/Maven2-3/9/')
286
+ expect(instance.vcs_revision).to eq('83049487ecc61bef3dce798838e7a9457e174a5a')
287
+ expect(instance.vcs_url).to eq('https://github.com/aseftel/project-examples')
288
+ expect(instance.build_retention).to eq(
289
+ "count" => -1,
290
+ "deleteBuildArtifacts" => true,
291
+ "buildNumbersNotToBeDiscarded" => []
292
+ )
293
+ expect(instance.modules).to eq(
294
+ modules
295
+ )
296
+ expect(instance.governance).to eq(
297
+ "blackDuckProperties" => {
298
+ "runChecks" => false,
299
+ "includePublishedArtifacts" => false,
300
+ "autoCreateMissingComponentRequests" => false,
301
+ "autoDiscardStaleComponentRequests" => false
302
+ }
303
+ )
304
+ end
305
+ end
306
+
307
+ describe '#diff' do
308
+ it 'sends GET to the client with the correct param' do
309
+ expect(client).to receive(:get).with('/api/build/wicket/51?diff=53', {})
310
+ subject.diff('53')
311
+ end
312
+ end
313
+
314
+ describe '#promote' do
315
+ let(:to_repo) { 'omnibus-stable-local' }
316
+ before do
317
+ Artifactory.username = 'doge'
318
+ end
319
+
320
+ it 'sends POST to the client with promotion JSON' do
321
+ expect(client).to receive(:post).with('/api/build/promote/wicket/51', /"targetRepo"\:"omnibus-stable-local"/, kind_of(Hash))
322
+ subject.promote(to_repo)
323
+ end
324
+
325
+ it 'Uses the configured Artifactory.username as the default value for `ciUser`' do
326
+ expect(client).to receive(:post).with('/api/build/promote/wicket/51', /"ciUser"\:"doge"/, kind_of(Hash))
327
+ subject.promote(to_repo)
328
+ end
329
+ end
330
+
331
+ describe '#save' do
332
+
333
+ it 'PUTS the build JSON file to the server' do
334
+ expect(client).to receive(:put).with('/api/build', kind_of(Tempfile), 'Content-Type' => 'application/json')
335
+ subject.save
336
+ end
337
+
338
+ context 'an invalid build type is provided' do
339
+ before { subject.type = 'PIRATE' }
340
+
341
+ it 'raises an InvalidBuildType error' do
342
+ expect { subject.save }.to raise_error(Error::InvalidBuildType)
30
343
  end
31
344
  end
32
345
  end
@@ -113,7 +113,7 @@ module Artifactory
113
113
 
114
114
  it 'PUTS the permission target to the server' do
115
115
  expect(client).to receive(:put).with("/api/security/permissions/TestRemote",
116
- "{\"name\":\"TestRemote\",\"includesPattern\":null,\"excludesPattern\":\"\",\"repositories\":[\"ANY\"],\"principals\":{\"users\":{\"anonymous_users\":[\"r\"]},\"groups\":{\"anonymous_readers\":[\"r\"]}}}",
116
+ "{\"name\":\"TestRemote\",\"includesPattern\":\"**\",\"excludesPattern\":\"\",\"repositories\":[\"ANY\"],\"principals\":{\"users\":{\"anonymous_users\":[\"r\"]},\"groups\":{\"anonymous_readers\":[\"r\"]}}}",
117
117
  { "Content-Type" => "application/vnd.org.jfrog.artifactory.security.PermissionTarget+json"})
118
118
  subject.save
119
119
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artifactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-16 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,6 +56,7 @@ files:
56
56
  - lib/artifactory/client.rb
57
57
  - lib/artifactory/collections/artifact.rb
58
58
  - lib/artifactory/collections/base.rb
59
+ - lib/artifactory/collections/build.rb
59
60
  - lib/artifactory/configurable.rb
60
61
  - lib/artifactory/defaults.rb
61
62
  - lib/artifactory/errors.rb
@@ -63,6 +64,7 @@ files:
63
64
  - lib/artifactory/resources/backup.rb
64
65
  - lib/artifactory/resources/base.rb
65
66
  - lib/artifactory/resources/build.rb
67
+ - lib/artifactory/resources/build_component.rb
66
68
  - lib/artifactory/resources/group.rb
67
69
  - lib/artifactory/resources/layout.rb
68
70
  - lib/artifactory/resources/ldap_setting.rb
@@ -77,6 +79,7 @@ files:
77
79
  - lib/artifactory/version.rb
78
80
  - spec/integration/resources/artifact_spec.rb
79
81
  - spec/integration/resources/backup.rb
82
+ - spec/integration/resources/build_component_spec.rb
80
83
  - spec/integration/resources/build_spec.rb
81
84
  - spec/integration/resources/group_spec.rb
82
85
  - spec/integration/resources/layout_spec.rb
@@ -90,6 +93,7 @@ files:
90
93
  - spec/spec_helper.rb
91
94
  - spec/support/api_server.rb
92
95
  - spec/support/api_server/artifact_endpoints.rb
96
+ - spec/support/api_server/build_component_endpoints.rb
93
97
  - spec/support/api_server/build_endpoints.rb
94
98
  - spec/support/api_server/group_endpoints.rb
95
99
  - spec/support/api_server/permission_target_endpoints.rb
@@ -102,6 +106,7 @@ files:
102
106
  - spec/unit/resources/artifact_spec.rb
103
107
  - spec/unit/resources/backup_spec.rb
104
108
  - spec/unit/resources/base_spec.rb
109
+ - spec/unit/resources/build_component_spec.rb
105
110
  - spec/unit/resources/build_spec.rb
106
111
  - spec/unit/resources/group_spec.rb
107
112
  - spec/unit/resources/layout_spec.rb
@@ -133,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
138
  version: '0'
134
139
  requirements: []
135
140
  rubyforge_project:
136
- rubygems_version: 2.4.5
141
+ rubygems_version: 2.2.2
137
142
  signing_key:
138
143
  specification_version: 4
139
144
  summary: Artifactory is a simple, lightweight Ruby client for interacting with the
@@ -141,6 +146,7 @@ summary: Artifactory is a simple, lightweight Ruby client for interacting with t
141
146
  test_files:
142
147
  - spec/integration/resources/artifact_spec.rb
143
148
  - spec/integration/resources/backup.rb
149
+ - spec/integration/resources/build_component_spec.rb
144
150
  - spec/integration/resources/build_spec.rb
145
151
  - spec/integration/resources/group_spec.rb
146
152
  - spec/integration/resources/layout_spec.rb
@@ -154,6 +160,7 @@ test_files:
154
160
  - spec/spec_helper.rb
155
161
  - spec/support/api_server.rb
156
162
  - spec/support/api_server/artifact_endpoints.rb
163
+ - spec/support/api_server/build_component_endpoints.rb
157
164
  - spec/support/api_server/build_endpoints.rb
158
165
  - spec/support/api_server/group_endpoints.rb
159
166
  - spec/support/api_server/permission_target_endpoints.rb
@@ -166,6 +173,7 @@ test_files:
166
173
  - spec/unit/resources/artifact_spec.rb
167
174
  - spec/unit/resources/backup_spec.rb
168
175
  - spec/unit/resources/base_spec.rb
176
+ - spec/unit/resources/build_component_spec.rb
169
177
  - spec/unit/resources/build_spec.rb
170
178
  - spec/unit/resources/group_spec.rb
171
179
  - spec/unit/resources/layout_spec.rb