Skip to content

Commit

Permalink
organize tests and push covergae
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Jan 7, 2016
1 parent 8dd1cd5 commit 3016a66
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mkmf.log
/vendor/
.pc/
debian/*.log
app/config/hieraviz.yml
config/hieraviz.yml
.env.production
.ruby-version
.ruby-gemset
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Hieraviz Changelog
========================

### v0.0.2 - wip
- add oauth2 auth method against gitlab server
- add session persistence on disk

### v0.0.1 - 2015-12-30
- still pretty alpha at this stage, more to come soon
Expand Down
9 changes: 2 additions & 7 deletions app/common.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
require 'sinatra/base'
require 'dotenv'
require 'hieracles'
require 'hieraviz'

module HieravizApp
class Common < Sinatra::Base

configure do
set :app_name, 'HieraViz'
configfile = ENV['HIERAVIZ_CONFIG_FILE'] || File.join("config", "hieraviz.yml")
configfile = File.join(root, configfile) unless configfile[0] == '/'
set :configfile, configfile
set :configdata, YAML.load_file(configfile)
set :config, Hieracles::Config.new({ config: configfile })
set :configdata, Hieraviz::Config.load
set :config, Hieracles::Config.new({ config: Hieraviz::Config.configfile })
enable :session
enable :logging
end
Expand Down
3 changes: 3 additions & 0 deletions app/main.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'hieracles'
require 'hieraviz'

require File.expand_path '../web.rb', __FILE__
require File.expand_path '../apiv1.rb', __FILE__

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/hieraviz.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "hieraviz/version"
require "hieraviz/config"
require "hieraviz/store"
require "hieraviz/auth_gitlab"

Expand Down
4 changes: 1 addition & 3 deletions lib/hieraviz/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def tmpdir
end

def init_tmpdir
configfile = ENV['HIERAVIZ_CONFIG_FILE'] || File.join("config", "hieraviz.yml")
configfile = File.expand_path(File.join('../../../app', configfile), __FILE__) unless configfile[0] == '/'
config = YAML.load_file(configfile)
config = Hieraviz::Config.load
tmp = config['tmpdir'] || '/tmp'
begin
FileUtils.mkdir_p(tmp) unless Dir.exist?(tmp)
Expand Down
1 change: 1 addition & 0 deletions spec/files/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ basepath: "spec/files/puppet"
classpath: "farm_modules/%s/manifests/init.pp"
hierafile: "hiera.yml"
session_seed: "toto"
tmpdir: "spec/files/tmp"
usedb: false
puppetdb:
usessl: false
Expand Down
61 changes: 61 additions & 0 deletions spec/lib/store_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,70 @@
require 'spec_helper'
require 'fileutils'

describe Hieraviz::Store do

describe '.data' do
it { expect(Hieraviz::Store.data).to eq Hash.new }
end

describe '.set' do
let(:name) { '123456' }
let(:value) { { a: 1 } }
let(:tmpfile) { 'spec/files/tmp/123456' }
after do
File.unlink(tmpfile) if File.exist?(tmpfile)
end
it {
Hieraviz::Store.set name, value
expect(File).to exist tmpfile
expect(Hieraviz::Store.data[name]).to eq value
}
end

describe '.tmpfile' do
context "when the filename has weird chars" do
let(:name) { 'gdahsj#@!(scg78ud' }
let(:expected) { 'spec/files/tmp/gdahsjscg78ud' }
it { expect(Hieraviz::Store.tmpfile(name)).to eq expected }
end
context "when the filename is a normal hash" do
let(:name) { 'gdahsjscg78ud' }
let(:expected) { 'spec/files/tmp/gdahsjscg78ud' }
it { expect(Hieraviz::Store.tmpfile(name)).to eq expected }
end
end

describe '.tmpdir' do
let(:tmpdir_ok) { 'spec/files/tmp' }
before do
allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_ok })
end
it { expect(Hieraviz::Store.tmpdir).to eq tmpdir_ok }
end

describe '.init_tmpdir' do
context 'when specified tmp dir is not present, create it' do
let(:tmpdir_nodir) { File.expand_path('../../files/tmp_tmp', __FILE__) }
before do
allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_nodir })
tmpexpect = Hieraviz::Store.init_tmpdir
end
after do
FileUtils.rm_rf(tmpdir_nodir) if Dir.exist?(tmpdir_nodir)
end
it { expect(File).to exist tmpdir_nodir }
end
context 'when tmp dir is present, returns its value' do
let(:tmpdir_ok) { 'spec/files/tmp' }
it { expect(Hieraviz::Store.init_tmpdir).to eq tmpdir_ok }
end
context 'when tmp dir is absent and cannot be created, returns /tmp' do
let(:tmpdir_nowrite) { '/diuyao' }
before do
allow(Hieraviz::Config).to receive(:load).and_return({ 'tmpdir' => tmpdir_nowrite })
end
it { expect(Hieraviz::Store.init_tmpdir).to eq '/tmp' }
end
end

end

0 comments on commit 3016a66

Please sign in to comment.