nexus_client 0.3.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.
@@ -0,0 +1,45 @@
1
+ require "spec_helper"
2
+ require 'sqlite3'
3
+
4
+ describe "Real Integration Nexus::Analytics" do
5
+ before(:all) do
6
+ FileUtils.mkdir_p('/tmp/cache') if not File.exists?('/tmp/cache')
7
+ end
8
+ file = '/tmp/ant-4.0.pom'
9
+ shafile = '/tmp/ant-4.0.pom.sha1'
10
+
11
+ after(:all) do
12
+
13
+ end
14
+
15
+ before(:each) do
16
+ @gav = Nexus::Gav.new("org.apache.maven:maven:3.2.1:central::pom")
17
+ @gav.sha1 = 'e1451ce0ab53c5a7a319d55dd577b7ee97799956'
18
+
19
+ @analytics = Nexus::Analytics.new('/tmp', 'cache-analytics.db')
20
+ end
21
+
22
+ # it 'should do something' do
23
+ # @analytics.gavs.should eq(Array)
24
+ # @analytics.gavs.length should gt(2)
25
+ # end
26
+
27
+ # it 'should return old items' do
28
+ # @analytics.old_items.should eq([])
29
+ # end
30
+
31
+ it 'should not return old items' do
32
+ @analytics.old_items(2592000).length.should eq(0)
33
+ end
34
+
35
+ xit 'should return top_x' do
36
+ @analytics.top_x(3).should eq([])
37
+ @analytics.top_x(3).length.should eq(3)
38
+
39
+ end
40
+
41
+ xit 'should update totals hash correctly' do
42
+ @analytics.totals.should eq([])
43
+ @analytics.update_item(@gav)
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'nexus_client'
4
+ require 'fakefs/safe'
5
+ require 'fakefs/spec_helpers'
6
+
7
+ RSpec.configure do |config|
8
+ config.formatter = 'documentation'
9
+ config.color = true
10
+ end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+ require 'etc'
3
+ describe Nexus::Analytics do
4
+ include FakeFS::SpecHelpers::All
5
+
6
+ # puts Etc.getpwuid.dir
7
+ # @cache_data = File.open('fixtures/cache_analytics.json') { |file| file.read }
8
+ #
9
+ # before(:each) do
10
+ # pwuid = double('pwuid')
11
+ # allow(pwuid).to receive(:dir).and_return(Dir.new('/home/user1').path)
12
+ # allow(Etc).to receive(:getpwuid).and_return(pwuid)
13
+ #
14
+ #
15
+ # end
16
+ #
17
+ # before(:all) do
18
+ #
19
+ # end
20
+ #
21
+ # context '#self_hit_count' do
22
+ # FakeFS.activate!
23
+ #
24
+ # FileUtils.mkdir_p('/home/user1')
25
+ # File.open('/home/user1/.cache_analytics.json') { |file| file.write(@cache_data)}
26
+ # it 'returns 1' do
27
+ # expect(Nexus::Analytics.hit_count('365576f4c2876138765f40bf159304478d22d363') ).to == 1
28
+ # end
29
+ # FakeFS.deactivate!
30
+ #
31
+ # end
32
+ # it '#to_json' do
33
+ # FakeFS.activate!
34
+ # totals = [["896f6a67964939a62f6b29e3d6fa13139ee92f9a",
35
+ # "org.glassfish.main.external:ant:4.0:central::pom",
36
+ # 123837, 0.332, "2014-06-11 00:44:07 -0700",
37
+ # "/tmp/cache/org/glassfish/main/external/ant/387951c0aa333024b25085d76a8ad77441b9e55f.cache",
38
+ # 4, 495348, 1.328]]
39
+ #
40
+ # FileUtils.mkdir_p('/tmp/cache') if not File.exists?('/tmp/cache')
41
+ # db = double(SQLite3::Database)
42
+ # analytics = Nexus::Analytics.new('/tmp/cache', 'analytics.db')
43
+ # allow(SQLite3::Database).to receive(:new).and_return(db)
44
+ # allow(db).to receive(:execute).and_return(totals)
45
+ # allow(analytics).to receive(:db).and_return(db)
46
+ # expect(analytics.to_json).to eq('')
47
+ # FakeFS.deactivate!
48
+ #
49
+ # end
50
+
51
+ end
@@ -0,0 +1,110 @@
1
+ require "spec_helper"
2
+
3
+ describe Nexus::Cache do
4
+ let(:cache) do
5
+ Nexus::Cache.new
6
+ end
7
+ gav_str = 'org.glassfish.main.external:ant:4.0:central::pom'
8
+ let(:gav) do
9
+ Nexus::Gav.new(gav_str)
10
+ end
11
+
12
+
13
+ context '#cache_location' do
14
+ it { expect(cache.location(gav)).to eq('/tmp/cache/org/glassfish/main/external/ant')}
15
+ context 'custom cache base' do
16
+ let(:cache) do
17
+ Nexus::Cache.new('/tmp/cache')
18
+ end
19
+ it { expect(cache.location(gav)).to eq('/tmp/cache/org/glassfish/main/external/ant')}
20
+
21
+ end
22
+ end
23
+
24
+
25
+ context '#file_path' do
26
+ context 'should throw error when sha1 is missing' do
27
+ let(:gav) do
28
+ Nexus::Gav.new(gav_str)
29
+ end
30
+ it { expect{cache.file_path(gav)}.to raise_error(RuntimeError)}
31
+ end
32
+ context 'should return correctly' do
33
+ gav2 = Nexus::Gav.new(gav_str)
34
+ gav2.sha1 = '387951c0aa333024b25085d76a8ad77441b9e55f'
35
+
36
+ it { expect(cache.file_path(gav2)).to eq("/tmp/cache/org/glassfish/main/external/ant/387951c0aa333024b25085d76a8ad77441b9e55f.cache")}
37
+ end
38
+ end
39
+
40
+ context '#exists?' do
41
+ gav2 = Nexus::Gav.new(gav_str)
42
+ gav2.sha1 = '387951c0aa333024b25085d76a8ad77441b9e55f'
43
+ FakeFS do
44
+ FileUtils.mkdir_p('/tmp/cache/org/glassfish/main/external/ant/')
45
+ File.open('/tmp/cache/org/glassfish/main/external/ant/387951c0aa333024b25085d76a8ad77441b9e55f.cache', 'w') do |file|
46
+ file.write('blah')
47
+ end
48
+ it 'should exist' do expect(cache.exists?(gav2) == true) end
49
+ end
50
+ end
51
+
52
+ context '#exists?' do
53
+ gav2 = Nexus::Gav.new(gav_str)
54
+ gav2.sha1 = '2aba52730281caf2ab4d44d85c9ebd20cd7bd99'
55
+ FakeFS do
56
+ FileUtils.mkdir_p('/tmp/cache/org/glassfish/main/external/ant/')
57
+ File.open('/tmp/cache/org/glassfish/main/external/ant/387951c0aa333024b25085d76a8ad77441b9e55f.cache', 'w') do |file|
58
+ file.write('blah')
59
+ end
60
+ it 'should not exist' do expect(cache.exists?(gav2) == false) end
61
+ end
62
+ end
63
+
64
+ # context 'disable analytics' do
65
+ # let(:cache) do
66
+ # Nexus::Cache.new('/tmp/cache', false)
67
+ # end
68
+ # gav2 = Nexus::Gav.new(gav_str)
69
+ # gav2.sha1 = '387951c0aa333024b25085d76a8ad77441b9e55f'
70
+ #
71
+ # it 'should not call analytics class' do
72
+ # FakeFS do
73
+ # FileUtils.mkdir_p('/tmp')
74
+ # File.open('/tmp/ant-4.0.pom', 'w') { |file| file.write('blah')}
75
+ # expect(cache).to receive(:analytics).exactly(0).times
76
+ # expect(Nexus::Analytics).to receive(:new).exactly(0).times
77
+ # expect(cache.analytics_enabled).to be_false
78
+ # expect(cache.add_file(gav2, '/tmp/ant-4.0.pom')).to be_true
79
+ # end
80
+ # end
81
+ # end
82
+ #
83
+ # context 'enable analytics' do
84
+ # let(:cache) do
85
+ # Nexus::Cache.new('/tmp/cache', true)
86
+ # end
87
+ # gav2 = Nexus::Gav.new(gav_str)
88
+ # gav2.sha1 = '387951c0aa333024b25085d76a8ad77441b9e55f'
89
+ #
90
+ #
91
+ # it 'should call analytics class' do
92
+ # FakeFS do
93
+ # #expect(Nexus::Analytics).to receive(:new).exactly(1).times
94
+ # cache2 = Nexus::Cache.new('/tmp/cache', true)
95
+ # puts cache2.analytics.inspect
96
+ # FileUtils.mkdir_p('/tmp')
97
+ # File.open('/tmp/ant-4.0.pom', 'w') { |file| file.write('blah')}
98
+ # expect(cache2).to receive(:analytics).exactly(1).times
99
+ # expect(cache2.analytics).to be_a(Nexus::Analytics)
100
+ # expect(cache2.analytics_enabled).to be_true
101
+ # expect(cache2.add_file(gav2, '/tmp/ant-4.0.pom')).to be_true
102
+ # end
103
+ #
104
+ # end
105
+ # end
106
+
107
+
108
+
109
+ end
110
+
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe Nexus::Gav do
4
+ gav_str = 'org.glassfish.main.external:ant:4.0:central::pom'
5
+ let(:gav) do
6
+ Nexus::Gav.new(gav_str)
7
+ end
8
+
9
+ it 'creates gav resource' do
10
+ expect(gav.group).to eq('org.glassfish.main.external')
11
+ expect(gav.artifact).to eq('ant')
12
+ expect(gav.version).to eq('4.0')
13
+ expect(gav.repo).to eq('central')
14
+ expect(gav.classifier).to eq('')
15
+ expect(gav.extension).to eq('pom')
16
+ end
17
+ it 'raises an error' do
18
+ expect { Nexus::Gav.new(nil) }.to raise_error(RuntimeError, 'Must provide gav_str in the form of "<group>:<artifact>:<version>:<repo>:<classifier>:<extension>"')
19
+ end
20
+
21
+ it 'should create filename' do
22
+ expect(gav.filename).to eq("ant-4.0.pom")
23
+ end
24
+
25
+ context "#to_s" do
26
+ it 'should convert to string' do
27
+ expect(gav.to_s).to eq(gav_str)
28
+ end
29
+ end
30
+
31
+ context '#filename' do
32
+ let(:gav) do
33
+ Nexus::Gav.new('org.glassfish.main.external:ant:4.0:central:blah:pom')
34
+ end
35
+ it 'should create filename with classifier' do
36
+ expect(gav.filename).to eq("ant-4.0-blah.pom")
37
+ end
38
+ end
39
+
40
+
41
+ context '#to_hash' do
42
+ it 'should convert to string' do
43
+ expect(gav.to_hash).to eq({:g=>"org.glassfish.main.external", :a=>"ant",
44
+ :v=>"4.0", :r=>"central", :c=>"", :e=>"pom"})
45
+ end
46
+ end
47
+
48
+ context "#dir_location" do
49
+ it 'should return dir_location' do
50
+ expect(gav.dir_location).to eq("org/glassfish/main/external/ant")
51
+ end
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe Nexus::Client do
4
+ gav_str = 'org.glassfish.main.external:ant:4.0:central::pom'
5
+ include FakeFS::SpecHelpers::All
6
+
7
+ let(:gav) do
8
+ Gav.new(gav_str)
9
+ end
10
+ before(:each) do
11
+ pwuid = double('pwuid')
12
+ allow(pwuid).to receive(:dir).and_return(Dir.new('/home/user1').path)
13
+ allow(Etc).to receive(:getpwuid).and_return(pwuid)
14
+ end
15
+ before(:all) do
16
+ FileUtils.mkdir_p('/home/user1')
17
+ File.open('/home/user1/.nexus_host', 'w') { |file| file.write('http://mynexus.example.com:8080') }
18
+ end
19
+ context 'with defaults' do
20
+ subject(:client) { Nexus::Client.new('http://nexus.example.com:8080') }
21
+
22
+ it 'uses default host' do
23
+ expect(client.host).to eq('http://nexus.example.com:8080')
24
+ end
25
+
26
+ context 'reads the nexus host file' do
27
+ subject(:client) { Nexus::Client.new }
28
+ it {expect(client.read_host).to eq('http://mynexus.example.com:8080')}
29
+ end
30
+ end
31
+
32
+ context 'user accidently supplies extra /nexus' do
33
+ subject(:client) { Nexus::Client.new('http://mynexus.example.com:8080/nexus') }
34
+ it { expect(client.host).to eq('http://mynexus.example.com:8080')}
35
+ end
36
+
37
+ context 'sha1 works' do
38
+ subject(:client) { Nexus::Client.new }
39
+ it {expect(client.sha('/home/user1/.nexus_host')).to eq('87a331f91896d3363e699b828d1cccd37dd07740') }
40
+ end
41
+
42
+ context 'sha_match? works' do
43
+ subject(:client) { Nexus::Client.new }
44
+ mygav = Nexus::Gav.new(gav_str)
45
+ mygav.sha1 = '87a331f91896d3363e699b828d1cccd37dd07740'
46
+ it {expect(client.sha_match?('/home/user1/.nexus_host', mygav)).to be_true }
47
+ end
48
+
49
+ context '#create_directory' do
50
+ subject(:client) { Nexus::Client.new }
51
+ it { expect(client.create_target('/home/user2/apps/app1/target/archives')).to be_true }
52
+ end
53
+
54
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexus_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Thigpen
8
+ - Corey Osman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: trollop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: '2.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '='
26
+ - !ruby/object:Gem::Version
27
+ version: '2.0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: typhoeus
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 0.6.9
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 0.6.9
42
+ - !ruby/object:Gem::Dependency
43
+ name: filesize
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.0.3
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.0.3
56
+ - !ruby/object:Gem::Dependency
57
+ name: sqlite3
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.3'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.3'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '10.3'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '10.3'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '2.99'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '2.99'
112
+ - !ruby/object:Gem::Dependency
113
+ name: fakefs
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '='
117
+ - !ruby/object:Gem::Version
118
+ version: '0.5'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '='
124
+ - !ruby/object:Gem::Version
125
+ version: '0.5'
126
+ description: Simple Ruby client for dealing with Nexus
127
+ email:
128
+ - darwin@senet.us
129
+ - corey@logicminds.biz
130
+ executables:
131
+ - nexus-client
132
+ extensions: []
133
+ extra_rdoc_files: []
134
+ files:
135
+ - ".gitignore"
136
+ - ".travis.yml"
137
+ - Gemfile
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - bin/nexus-client
142
+ - lib/nexus_client.rb
143
+ - lib/nexus_client/analytics.rb
144
+ - lib/nexus_client/cache.rb
145
+ - lib/nexus_client/gav.rb
146
+ - lib/nexus_client/version.rb
147
+ - nexus_client.gemspec
148
+ - spec/integration/analytics_spec.rb
149
+ - spec/integration/cache_spec.rb
150
+ - spec/integration/nexus_client_bin_spec.rb
151
+ - spec/integration/nexus_client_spec.rb
152
+ - spec/integration/real_analytics_spec.rb
153
+ - spec/spec_helper.rb
154
+ - spec/unit/analytics_spec.rb
155
+ - spec/unit/cache_spec.rb
156
+ - spec/unit/gav_spec.rb
157
+ - spec/unit/nexus_client_spec.rb
158
+ homepage: https://github.com/logicminds/nexus-client
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.4.5
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Simple Nexus Ruby Client
182
+ test_files:
183
+ - spec/integration/analytics_spec.rb
184
+ - spec/integration/cache_spec.rb
185
+ - spec/integration/nexus_client_bin_spec.rb
186
+ - spec/integration/nexus_client_spec.rb
187
+ - spec/integration/real_analytics_spec.rb
188
+ - spec/spec_helper.rb
189
+ - spec/unit/analytics_spec.rb
190
+ - spec/unit/cache_spec.rb
191
+ - spec/unit/gav_spec.rb
192
+ - spec/unit/nexus_client_spec.rb