hieraviz 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Hieraviz::Store do
5
+
6
+ describe '.data' do
7
+ it { expect(Hieraviz::Store.data).to eq Hash.new }
8
+ end
9
+
10
+ describe '.set' do
11
+ let(:name) { '123456' }
12
+ let(:value) { { a: 1 } }
13
+ let(:tmpfile) { 'spec/files/tmp/123456' }
14
+ after do
15
+ File.unlink(tmpfile) if File.exist?(tmpfile)
16
+ end
17
+ it {
18
+ Hieraviz::Store.set name, value
19
+ expect(File).to exist tmpfile
20
+ expect(Hieraviz::Store.data[name]).to eq value
21
+ }
22
+ end
23
+
24
+ describe '.get' do
25
+ let(:name) { '123456' }
26
+ let(:value) { { a: 1 } }
27
+ let(:tmpfile) { 'spec/files/tmp/123456' }
28
+ after do
29
+ File.unlink(tmpfile) if File.exist?(tmpfile)
30
+ end
31
+ context "without expiration and existing session" do
32
+ before do
33
+ Hieraviz::Store.set name, value
34
+ end
35
+ it {
36
+ expect(Hieraviz::Store.get(name)).to eq value
37
+ expect(File).to exist tmpfile
38
+ }
39
+ end
40
+ context "with expiration and existing unexpired session" do
41
+ before do
42
+ Hieraviz::Store.set name, value
43
+ end
44
+ it {
45
+ expect(Hieraviz::Store.get(name, 300)).to eq value
46
+ expect(File).to exist tmpfile
47
+ }
48
+ end
49
+ context "with expiration and existing expired session" do
50
+ before do
51
+ Hieraviz::Store.set name, value
52
+ FileUtils.touch tmpfile, mtime: Time.now - 600
53
+ end
54
+ it {
55
+ expect(Hieraviz::Store.get(name, 300)).to be_falsey
56
+ expect(File).not_to exist tmpfile
57
+ }
58
+ end
59
+ context "without existing session" do
60
+ it {
61
+ expect(Hieraviz::Store.get(name)).to be_falsey
62
+ }
63
+ end
64
+ end
65
+
66
+ describe '.dump' do
67
+ let(:name) { '123456' }
68
+ let(:value) { { a: 1 } }
69
+ let(:tmpfile) { 'spec/files/tmp/123456' }
70
+ let(:expected) { { name => value } }
71
+ after do
72
+ File.unlink(tmpfile) if File.exist?(tmpfile)
73
+ end
74
+ it {
75
+ Hieraviz::Store.set name, value
76
+ expect(File).to exist tmpfile
77
+ expect(Hieraviz::Store.dump).to eq expected
78
+ }
79
+ end
80
+
81
+ describe '.tmpfile' do
82
+ context "when the filename has weird chars" do
83
+ let(:name) { 'gdahsj#@!(scg78ud' }
84
+ let(:expected) { 'spec/files/tmp/gdahsjscg78ud' }
85
+ it { expect(Hieraviz::Store.tmpfile(name)).to eq expected }
86
+ end
87
+ context "when the filename is a normal hash" do
88
+ let(:name) { 'gdahsjscg78ud' }
89
+ 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 })
98
+ end
99
+ it { expect(Hieraviz::Store.tmpdir).to eq tmpdir_ok }
100
+ end
101
+
102
+ describe '.init_tmpdir' do
103
+ context 'when specified tmp dir is not present, create it' do
104
+ let(:tmpdir_nodir) { File.expand_path('../../files/tmp_tmp', __FILE__) }
105
+ before do
106
+ allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_nodir })
107
+ tmpexpect = Hieraviz::Store.init_tmpdir
108
+ end
109
+ after do
110
+ FileUtils.rm_rf(tmpdir_nodir) if Dir.exist?(tmpdir_nodir)
111
+ end
112
+ it { expect(File).to exist tmpdir_nodir }
113
+ end
114
+ context 'when tmp dir is present, returns its value' do
115
+ let(:tmpdir_ok) { 'spec/files/tmp' }
116
+ it { expect(Hieraviz::Store.init_tmpdir).to eq tmpdir_ok }
117
+ end
118
+ context 'when tmp dir is absent and cannot be created, returns /tmp' do
119
+ 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' }
124
+ end
125
+ end
126
+
127
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path '../../app/main.rb', __FILE__
2
+
3
+ module RSpecMixin
4
+ include Rack::Test::Methods
5
+ def app() described_class end
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+ config.include RSpecMixin
10
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,23 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'hieraviz'
2
+
3
+ if !ENV['BUILD']
4
+ require 'rubygems'
5
+ require 'bundler'
6
+
7
+ if ENV['COV']
8
+ require 'simplecov'
9
+ SimpleCov.start do
10
+ add_group 'bin', 'bin'
11
+ add_group 'app', 'app'
12
+ add_group 'lib', 'lib'
13
+ add_filter 'vendor'
14
+ add_filter 'spec'
15
+ end
16
+ else
17
+ require 'coveralls'
18
+ Coveralls.wear!
19
+ end
20
+ end
3
21
 
4
22
  require 'rack/test'
5
23
  require 'rspec'
@@ -7,15 +25,9 @@ require 'rspec'
7
25
  ENV['RACK_ENV'] = 'test'
8
26
  ENV['HIERAVIZ_CONFIG_FILE'] = File.expand_path '../files/config.yml', __FILE__
9
27
 
10
- require File.expand_path '../../app/main.rb', __FILE__
11
-
12
- module RSpecMixin
13
- include Rack::Test::Methods
14
- def app() described_class end
15
- end
28
+ require 'hieraviz'
16
29
 
17
30
  RSpec.configure do |config|
18
- config.include RSpecMixin
19
31
  config.mock_with :rspec
20
32
  config.expect_with :rspec do |c|
21
33
  c.syntax = :expect
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.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-30 00:00:00.000000000 Z
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sinatra
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra-flash
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: hieracles
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +150,20 @@ dependencies:
122
150
  - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
125
167
  - !ruby/object:Gem::Dependency
126
168
  name: simplecov
127
169
  requirement: !ruby/object:Gem::Requirement
@@ -180,12 +222,11 @@ files:
180
222
  - README.md
181
223
  - app/apiv1.rb
182
224
  - app/common.rb
183
- - app/config/hieraviz.default.yml
184
- - app/config/hieraviz.yml
185
225
  - app/main.rb
186
226
  - app/public/css/main.css
187
227
  - app/public/img/loader.gif
188
228
  - app/public/js/farms.js
229
+ - app/public/js/fetch.js
189
230
  - app/public/js/logout.js
190
231
  - app/public/js/main.js
191
232
  - app/public/js/modules.js
@@ -194,6 +235,7 @@ files:
194
235
  - app/views/_foot.erb
195
236
  - app/views/_head.erb
196
237
  - app/views/_layout.erb
238
+ - app/views/data.erb
197
239
  - app/views/farms.erb
198
240
  - app/views/home.erb
199
241
  - app/views/logout.erb
@@ -201,10 +243,13 @@ files:
201
243
  - app/views/nodes.erb
202
244
  - app/views/not_found.erb
203
245
  - app/views/resources.erb
246
+ - app/views/store.erb
204
247
  - app/web.rb
205
248
  - bin/hv-ctl
206
249
  - config.ru
207
250
  - lib/hieraviz.rb
251
+ - lib/hieraviz/auth_gitlab.rb
252
+ - lib/hieraviz/config.rb
208
253
  - lib/hieraviz/store.rb
209
254
  - lib/hieraviz/version.rb
210
255
  - spec/app/apiv1_spec.rb
@@ -217,6 +262,10 @@ files:
217
262
  - spec/files/puppet/modules/module1/init.pp
218
263
  - spec/files/puppet/params/common/common.yml
219
264
  - spec/files/puppet/params/nodes/node1.example.com.yaml
265
+ - spec/lib/auth_gitlab_spec.rb
266
+ - spec/lib/config_spec.rb
267
+ - spec/lib/store_spec.rb
268
+ - spec/sinatra_helper.rb
220
269
  - spec/spec_helper.rb
221
270
  homepage: https://github.com/Gandi/hieraviz
222
271
  licenses:
@@ -255,3 +304,7 @@ test_files:
255
304
  - spec/files/puppet/farm_modules/farm1/manifests/init.pp
256
305
  - spec/files/puppet/modules/module1/init.pp
257
306
  - spec/files/puppet/hiera.yml
307
+ - spec/sinatra_helper.rb
308
+ - spec/lib/auth_gitlab_spec.rb
309
+ - spec/lib/config_spec.rb
310
+ - spec/lib/store_spec.rb
@@ -1,13 +0,0 @@
1
- ---
2
- app_name: HieraViz
3
- basepath: "../puppet"
4
- classpath: "farm_modules/%s/manifests/init.pp"
5
- hierafile: "dev/hiera-local.yaml"
6
- usedb: true
7
- puppetdb:
8
- usessl: false
9
- host: puppetdb.example.com
10
- port: 8080
11
- http_auth:
12
- username: 'xxx'
13
- password: 'xxx'
@@ -1,13 +0,0 @@
1
- ---
2
- app_name: HieraViz
3
- basepath: "../../gandi/puppet2.7"
4
- classpath: "farm_modules/%s/manifests/init.pp"
5
- hierafile: "dev/hiera-local.yaml"
6
- usedb: true
7
- puppetdb:
8
- usessl: false
9
- host: puppetdb.sd2.0x35.net
10
- port: 8080
11
- http_auth:
12
- username: 'xxx'
13
- password: 'xxx'