Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix getting the first result and add specs
- Loading branch information
Marc-André Courtois
committed
Apr 19, 2013
1 parent
a1e0955
commit db52a3f
Showing
7 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
hiera-psql (0.1.0) | ||
hiera (~> 1.0) | ||
json (~> 1.7) | ||
pg (~> 0.15) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
diff-lcs (1.2.3) | ||
hiera (1.2.0) | ||
json_pure | ||
json (1.7.7) | ||
json_pure (1.7.7) | ||
pg (0.15.1) | ||
rspec (2.13.0) | ||
rspec-core (~> 2.13.0) | ||
rspec-expectations (~> 2.13.0) | ||
rspec-mocks (~> 2.13.0) | ||
rspec-core (2.13.1) | ||
rspec-expectations (2.13.0) | ||
diff-lcs (>= 1.1.3, < 2.0) | ||
rspec-mocks (2.13.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
hiera-psql! | ||
rspec (= 2.13) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require 'spec_helper' | ||
require 'hiera/backend/psql_backend' | ||
|
||
class Hiera | ||
module Backend | ||
describe Psql_backend do | ||
before do | ||
#Config.load({'psql'=>'asdfas'}) | ||
Hiera.stub :debug | ||
Hiera.stub :warn | ||
@backend = Psql_backend.new | ||
end | ||
|
||
describe '#initialize' do | ||
it 'should print debug through Hiera' do | ||
Hiera.should_receive(:debug).with('Hiera PostgreSQL backend starting') | ||
Psql_backend.new | ||
end | ||
end | ||
|
||
describe '#lookup' do | ||
it 'should look for data in all sources' do | ||
Backend.should_receive(:datasources).and_yield(["one"]).and_yield(["two"]) | ||
|
||
connection_mock = double.as_null_object | ||
Psql_backend.should_receive(:connection).twice.and_return(connection_mock) | ||
connection_mock.should_receive(:exec).once.ordered.with(anything(), [["one"], anything()]) | ||
connection_mock.should_receive(:exec).once.ordered.with(anything(), [["two"], anything()]) | ||
|
||
@backend.lookup('key', {}, nil, :priority) | ||
end | ||
|
||
#it 'should pick data earliest source that has it for priority searches' do | ||
# Backend.should_receive(:datasources).and_yield(["one"])#.and_yield(["two"]) | ||
# | ||
# connection_mock = double('connection').as_null_object | ||
# #result_mock = double('result').as_null_object | ||
# Psql_backend.should_receive(:connection).once.and_return(connection_mock) | ||
# connection_mock.should_receive(:exec).once.ordered.with(anything(), [['one'], anything()]).and_yield({'value'=>'"patate"'}) | ||
# | ||
# #result_mock.should_receive(:first).once.ordered.and_return({'value'=>'"patate"'}) | ||
# #connection_mock.should_receive(:exec).once.ordered.with(anything(), [["two"], anything()]).and_return result_mock | ||
# #result_mock.should_receive(:first).once.ordered.and_return nil | ||
# | ||
# @backend.lookup('key', {}, nil, :priority).should == 'patate' | ||
#end | ||
|
||
|
||
#it 'should return nil for missing path/value' do | ||
# mock_source = double.as_null_object | ||
# Backend.should_receive(:datasources).with(:scope, :override).and_yield(mock_source) | ||
# | ||
# described_class.should_receive(:exec).with(:query, :params).and_return(double.as_null_object) | ||
# | ||
# | ||
# @backend.lookup(:key, :scope, :override, :resolution_type) | ||
#end | ||
# | ||
#it 'should build an array of all data sources for array searches' do | ||
# # todo | ||
# @backend.lookup("key", {}, nil, :array).should == ["answer", "answer"] | ||
#end | ||
# | ||
#it 'should build an array of all data sources for array searches' do | ||
# # todo | ||
# @backend.lookup("key", {}, nil, :hash).should == {"a" => "answer"} | ||
#end | ||
# | ||
#it 'should parse the answer for scope variables' do | ||
# # todo | ||
# @backend.lookup("key", {"rspec" => "test"}, nil, :priority).should == "test_test" | ||
#end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# This file was generated by the `rspec --init` command. Conventionally, all | ||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. | ||
# Require this file using `require "spec_helper"` to ensure that it is only | ||
# loaded once. | ||
# | ||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration | ||
RSpec.configure do |config| | ||
config.treat_symbols_as_metadata_keys_with_true_values = true | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run :focus | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
config.order = 'random' | ||
|
||
config.mock_with :rspec | ||
end | ||
|
||
require 'lib/hiera/backend/psql_backend' | ||
|