hieraviz 0.1.2 → 0.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.
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hieraviz::Facts do
4
-
5
- let(:tmpdir) { "spec/files/tmp" }
6
- let(:base) { "base" }
7
- let(:node) { "node" }
8
- let(:user) { "dummy" }
4
+ let(:tmpdir) { 'spec/files/tmp' }
5
+ let(:base) { 'base' }
6
+ let(:node) { 'node' }
7
+ let(:user) { 'dummy' }
9
8
  let(:facts) { Hieraviz::Facts.new tmpdir, base, node, user }
10
- let(:expected) { "spec/files/tmp/base__node__dummy" }
9
+ let(:expected) { 'spec/files/tmp/base__node__dummy' }
11
10
 
12
11
  describe '.new' do
13
12
  it { expect(facts.instance_variable_get(:@filename)).to eq expected }
@@ -32,10 +31,14 @@ describe Hieraviz::Facts do
32
31
  end
33
32
 
34
33
  describe '.read' do
35
- let(:data) { { a: 'b'} }
36
- before { facts.write(data) }
37
- after { File.unlink expected }
38
- it { expect(facts.read).to eq data }
34
+ context 'when there is facts recorded' do
35
+ let(:data) { { a: 'b' } }
36
+ before { facts.write(data) }
37
+ after { File.unlink expected }
38
+ it { expect(facts.read).to eq data }
39
+ end
40
+ context 'when there is no facts recorded' do
41
+ it { expect(facts.read).to eq({}) }
42
+ end
39
43
  end
40
-
41
44
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hieraviz::Puppetdb do
4
+ let(:ppdb) { Hieraviz::Puppetdb.new({}) }
5
+
6
+ describe '.new' do
7
+ it { expect(ppdb.instance_variable_get(:@request)).to be_a Hieracles::Puppetdb::Request }
8
+ end
9
+
10
+ describe '.events' do
11
+ before do
12
+ allow_any_instance_of(Hieracles::Puppetdb::Request)
13
+ .to receive(:events)
14
+ .and_return('something')
15
+ end
16
+ it { expect(ppdb.events).to eq 'something' }
17
+ end
18
+ end
@@ -3,22 +3,26 @@ require 'fileutils'
3
3
 
4
4
  describe Hieraviz::Store do
5
5
 
6
+ let(:store) { Hieraviz::Store.new('spec/files/tmp') }
7
+
6
8
  describe '.data' do
7
- it { expect(Hieraviz::Store.data).to eq Hash.new }
9
+ it { expect(store.data).to eq({}) }
8
10
  end
9
11
 
10
12
  describe '.set' do
11
13
  let(:name) { '123456' }
12
14
  let(:value) { { a: 1 } }
13
15
  let(:tmpfile) { 'spec/files/tmp/123456' }
16
+ before do
17
+ store.set name, value
18
+ end
14
19
  after do
15
20
  File.unlink(tmpfile) if File.exist?(tmpfile)
16
21
  end
17
- it {
18
- Hieraviz::Store.set name, value
22
+ it do
19
23
  expect(File).to exist tmpfile
20
- expect(Hieraviz::Store.data[name]).to eq value
21
- }
24
+ expect(store.data[name]).to eq value
25
+ end
22
26
  end
23
27
 
24
28
  describe '.get' do
@@ -28,38 +32,38 @@ describe Hieraviz::Store do
28
32
  after do
29
33
  File.unlink(tmpfile) if File.exist?(tmpfile)
30
34
  end
31
- context "without expiration and existing session" do
35
+ context 'without expiration and existing session' do
32
36
  before do
33
- Hieraviz::Store.set name, value
37
+ store.set name, value
34
38
  end
35
- it {
36
- expect(Hieraviz::Store.get(name)).to eq value
39
+ it do
40
+ expect(store.get(name, false)).to eq value
37
41
  expect(File).to exist tmpfile
38
- }
42
+ end
39
43
  end
40
- context "with expiration and existing unexpired session" do
44
+ context 'with expiration and existing unexpired session' do
41
45
  before do
42
- Hieraviz::Store.set name, value
46
+ store.set name, value
43
47
  end
44
- it {
45
- expect(Hieraviz::Store.get(name, 300)).to eq value
48
+ it do
49
+ expect(store.get(name, 300)).to eq value
46
50
  expect(File).to exist tmpfile
47
- }
51
+ end
48
52
  end
49
- context "with expiration and existing expired session" do
53
+ context 'with expiration and existing expired session' do
50
54
  before do
51
- Hieraviz::Store.set name, value
55
+ store.set name, value
52
56
  FileUtils.touch tmpfile, mtime: Time.now - 600
53
57
  end
54
- it {
55
- expect(Hieraviz::Store.get(name, 300)).to be_falsey
58
+ it do
59
+ expect(store.get(name, 300)).to eq({})
56
60
  expect(File).not_to exist tmpfile
57
- }
61
+ end
58
62
  end
59
- context "without existing session" do
60
- it {
61
- expect(Hieraviz::Store.get(name)).to be_falsey
62
- }
63
+ context 'without existing session' do
64
+ it do
65
+ expect(store.get(name, false)).to eq({})
66
+ end
63
67
  end
64
68
  end
65
69
 
@@ -71,40 +75,31 @@ describe Hieraviz::Store do
71
75
  after do
72
76
  File.unlink(tmpfile) if File.exist?(tmpfile)
73
77
  end
74
- it {
75
- Hieraviz::Store.set name, value
78
+ it do
79
+ store.set name, value
76
80
  expect(File).to exist tmpfile
77
- expect(Hieraviz::Store.dump).to eq expected
78
- }
81
+ expect(store.dump).to eq expected
82
+ end
79
83
  end
80
84
 
81
85
  describe '.tmpfile' do
82
- context "when the filename has weird chars" do
86
+ context 'when the filename has weird chars' do
83
87
  let(:name) { 'gdahsj#@!(scg78ud' }
84
88
  let(:expected) { 'spec/files/tmp/gdahsjscg78ud' }
85
- it { expect(Hieraviz::Store.tmpfile(name)).to eq expected }
89
+ it { expect(store.tmpfile(name)).to eq expected }
86
90
  end
87
- context "when the filename is a normal hash" do
91
+ context 'when the filename is a normal hash' do
88
92
  let(:name) { 'gdahsjscg78ud' }
89
93
  let(:expected) { 'spec/files/tmp/gdahsjscg78ud' }
90
- it { expect(Hieraviz::Store.tmpfile(name)).to eq expected }
91
- end
92
- end
93
-
94
- describe '.tmpdir' do
95
- let(:tmpdir_ok) { 'spec/files/tmp' }
96
- before do
97
- allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_ok })
94
+ it { expect(store.tmpfile(name)).to eq expected }
98
95
  end
99
- it { expect(Hieraviz::Store.tmpdir).to eq tmpdir_ok }
100
96
  end
101
97
 
102
98
  describe '.init_tmpdir' do
103
- context 'when specified tmp dir is not present, create it' do
99
+ context 'when specified tmp dir is not present, create it' do
104
100
  let(:tmpdir_nodir) { File.expand_path('../../files/tmp_tmp', __FILE__) }
105
101
  before do
106
- allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_nodir })
107
- tmpexpect = Hieraviz::Store.init_tmpdir
102
+ store.init_tmpdir tmpdir_nodir
108
103
  end
109
104
  after do
110
105
  FileUtils.rm_rf(tmpdir_nodir) if Dir.exist?(tmpdir_nodir)
@@ -113,15 +108,11 @@ describe Hieraviz::Store do
113
108
  end
114
109
  context 'when tmp dir is present, returns its value' do
115
110
  let(:tmpdir_ok) { 'spec/files/tmp' }
116
- it { expect(Hieraviz::Store.init_tmpdir).to eq tmpdir_ok }
111
+ it { expect(store.init_tmpdir tmpdir_ok).to eq tmpdir_ok }
117
112
  end
118
113
  context 'when tmp dir is absent and cannot be created, returns /tmp' do
119
114
  let(:tmpdir_nowrite) { '/diuyao' }
120
- before do
121
- allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_nowrite })
122
- end
123
- it { expect(Hieraviz::Store.init_tmpdir).to eq '/tmp' }
115
+ it { expect(store.init_tmpdir tmpdir_nowrite).to eq '/tmp' }
124
116
  end
125
117
  end
126
-
127
118
  end
@@ -1,8 +1,9 @@
1
1
  class AuthCodeMock
2
- def authorize_url(args)
2
+ def authorize_url(_args)
3
3
  'authorize url'
4
4
  end
5
- def get_token(code, args)
5
+
6
+ def get_token(_code, _args)
6
7
  '123456'
7
8
  end
8
9
  end
@@ -11,6 +12,7 @@ class RequestMock
11
12
  def body
12
13
  '{"somekey":"somevalue"}'
13
14
  end
15
+
14
16
  def url
15
17
  'http://example.com'
16
18
  end
@@ -25,7 +27,7 @@ end
25
27
 
26
28
  class Oauth2Mock
27
29
  attr_reader :auth_code
28
- def initialize(*args)
30
+ def initialize(*_args)
29
31
  @auth_code = AuthCodeMock.new
30
32
  end
31
33
  end
@@ -1,5 +1,3 @@
1
- ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
2
-
3
1
  require 'spec_helper'
4
2
 
5
3
  require File.expand_path '../../app/main.rb', __FILE__
@@ -8,11 +6,11 @@ require 'sinatra/base'
8
6
 
9
7
  module RSpecMixin
10
8
  include Rack::Test::Methods
11
- def app()
9
+ def app
12
10
  described_class
13
11
  end
14
12
  end
15
13
 
16
- RSpec.configure do |config|
14
+ RSpec.configure do |config|
17
15
  config.include RSpecMixin
18
16
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
 
3
- if !ENV['BUILD']
3
+ unless ENV['BUILD']
4
4
  require 'rubygems'
5
5
  require 'bundler'
6
6
 
@@ -23,9 +23,11 @@ require 'rack/test'
23
23
  require 'rspec'
24
24
 
25
25
  ENV['RACK_ENV'] = 'test'
26
- # ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
26
+ ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
27
27
 
28
- RSpec.configure do |config|
28
+ require 'hieraviz'
29
+
30
+ RSpec.configure do |config|
29
31
  config.mock_with :rspec
30
32
  config.expect_with :rspec do |c|
31
33
  c.syntax = :expect
@@ -35,15 +37,15 @@ end
35
37
  module Rack
36
38
  module Test
37
39
  class Session
38
- alias_method :old_env_for, :env_for
40
+ alias old_env_for env_for
39
41
  def rack_session
40
42
  @rack_session ||= {}
41
43
  end
42
- def rack_session=(hash)
43
- @rack_session = hash
44
- end
44
+
45
+ attr_writer :rack_session
46
+
45
47
  def env_for(path, env)
46
- old_env_for(path, env).merge({'rack.session' => rack_session})
48
+ old_env_for(path, env).merge('rack.session' => rack_session)
47
49
  end
48
50
  end
49
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hieraviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -206,10 +206,53 @@ dependencies:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
208
  version: '0'
209
- description: "Simple web application for accessing Puppet development code \n and
210
- production data in a unified interface. Its main goal is \n to
211
- enable a better visibility on the Puppet architecture for \n more
212
- actors to be able to interact with it."
209
+ - !ruby/object:Gem::Dependency
210
+ name: bundler-audit
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rubocop
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: reek
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ description: |-
252
+ Simple web application for accessing Puppet development code
253
+ and production data in a unified interface. Its main goal is
254
+ to enable a better visibility on the Puppet architecture for
255
+ more actors to be able to interact with it.
213
256
  email:
214
257
  - mose@gandi.net
215
258
  executables:
@@ -255,8 +298,10 @@ files:
255
298
  - lib/hieraviz/facts.rb
256
299
  - lib/hieraviz/puppetdb.rb
257
300
  - lib/hieraviz/store.rb
301
+ - lib/hieraviz/utilities.rb
258
302
  - lib/hieraviz/version.rb
259
303
  - spec/app/apiv1_spec.rb
304
+ - spec/app/web_dummy_auth_spec.rb
260
305
  - spec/app/web_spec.rb
261
306
  - spec/files/config.yml
262
307
  - spec/files/config_dummy.yml
@@ -278,6 +323,7 @@ files:
278
323
  - spec/lib/auth_gitlab_spec.rb
279
324
  - spec/lib/config_spec.rb
280
325
  - spec/lib/facts_spec.rb
326
+ - spec/lib/puppetdb_spec.rb
281
327
  - spec/lib/store_spec.rb
282
328
  - spec/oauth2_helper.rb
283
329
  - spec/sinatra_helper.rb
@@ -303,34 +349,36 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
349
  version: '0'
304
350
  requirements: []
305
351
  rubyforge_project:
306
- rubygems_version: 2.4.8
352
+ rubygems_version: 2.4.3
307
353
  signing_key:
308
354
  specification_version: 4
309
355
  summary: Web and API server for accessing Puppet dev and prod data.
310
356
  test_files:
311
357
  - spec/oauth2_helper.rb
312
- - spec/spec_helper.rb
313
- - spec/app/apiv1_spec.rb
314
- - spec/app/web_spec.rb
315
- - spec/files/config_gitlab.yml
316
- - spec/files/config_multi.yml
317
- - spec/files/hiera.yml
318
358
  - spec/files/config_dummy.yml
359
+ - spec/files/hiera.yml
319
360
  - spec/files/config.yml
320
- - spec/files/puppet/params/common/common.yaml
321
- - spec/files/puppet/params/nodes/node1.example.com.yaml
322
- - spec/files/puppet/enc/node1.example.com.yaml
323
- - spec/files/puppet/farm_modules/farm1/manifests/init.pp
324
- - spec/files/puppet/modules/module1/init.pp
325
- - spec/files/puppet/hiera.yml
326
- - spec/files/puppet2/params/common/common.yaml
327
- - spec/files/puppet2/params/nodes/node1.example.com.yaml
328
- - spec/files/puppet2/enc/node1.example.com.yaml
329
361
  - spec/files/puppet2/farm_modules/farm1/manifests/init.pp
330
- - spec/files/puppet2/modules/module1/init.pp
331
362
  - spec/files/puppet2/hiera.yml
332
- - spec/sinatra_helper.rb
363
+ - spec/files/puppet2/enc/node1.example.com.yaml
364
+ - spec/files/puppet2/params/nodes/node1.example.com.yaml
365
+ - spec/files/puppet2/params/common/common.yaml
366
+ - spec/files/puppet2/modules/module1/init.pp
367
+ - spec/files/config_gitlab.yml
368
+ - spec/files/config_multi.yml
369
+ - spec/files/puppet/farm_modules/farm1/manifests/init.pp
370
+ - spec/files/puppet/hiera.yml
371
+ - spec/files/puppet/enc/node1.example.com.yaml
372
+ - spec/files/puppet/params/nodes/node1.example.com.yaml
373
+ - spec/files/puppet/params/common/common.yaml
374
+ - spec/files/puppet/modules/module1/init.pp
375
+ - spec/spec_helper.rb
333
376
  - spec/lib/auth_gitlab_spec.rb
334
377
  - spec/lib/config_spec.rb
335
- - spec/lib/facts_spec.rb
336
378
  - spec/lib/store_spec.rb
379
+ - spec/lib/facts_spec.rb
380
+ - spec/lib/puppetdb_spec.rb
381
+ - spec/sinatra_helper.rb
382
+ - spec/app/web_spec.rb
383
+ - spec/app/web_dummy_auth_spec.rb
384
+ - spec/app/apiv1_spec.rb