summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2016-07-28 10:34:03 +0300
committerGitHub <noreply@github.com>2016-07-28 10:34:03 +0300
commit7d0dba17675a9c432189ec50584f5f449801f7d7 (patch)
tree5004f4b3aec877c12903999242c400b2e198df84
parentc6246680d2cb524cba36d414411f6546224130e3 (diff)
parentb8f56e81dcc7696bb983cfc89a4829d28d4d638b (diff)
Merge pull request #513 from danilopopeye/512-fix-resolve_repo-crash
only resolve the repository path when the output is `git`
-rw-r--r--lib/oxidized/node.rb10
-rw-r--r--spec/githubrepo_spec.rb15
-rw-r--r--spec/node_spec.rb1
3 files changed, 17 insertions, 9 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index 3e46b17..f2b125a 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -22,7 +22,7 @@ module Oxidized
@vars = opt[:vars]
@stats = Stats.new
@retry = 0
- @repo = resolve_repo
+ @repo = resolve_repo opt
# model instance needs to access node instance
@model.node = self
@@ -171,7 +171,9 @@ module Oxidized
Oxidized.mgr.model[model].new
end
- def resolve_repo
+ def resolve_repo opt
+ return unless is_git? opt
+
remote_repo = Oxidized.config.output.git.repo
if remote_repo.is_a?(::String)
@@ -185,5 +187,9 @@ module Oxidized
end
end
+ def is_git? opt
+ (opt[:output] || Oxidized.config.output.default) == 'git'
+ end
+
end
end
diff --git a/spec/githubrepo_spec.rb b/spec/githubrepo_spec.rb
index ab5e251..2f84c78 100644
--- a/spec/githubrepo_spec.rb
+++ b/spec/githubrepo_spec.rb
@@ -10,10 +10,11 @@ describe GithubRepo do
let(:repo) { mock() }
let(:gr) { GithubRepo.new }
- before(:each) do
+ before do
Oxidized.asetus = Asetus.new
Oxidized.config.log = '/dev/null'
Oxidized.setup_logger
+ Oxidized.config.output.default = 'git'
end
describe '#validate_cfg!' do
@@ -84,23 +85,23 @@ describe GithubRepo do
let(:group) { nil }
let(:ctx) { OpenStruct.new(node: node) }
let(:node) do
- Oxidized::Node.new(ip: '127.0.0.1', group: group, model: 'junos', output: 'output')
+ Oxidized::Node.new(ip: '127.0.0.1', group: group, model: 'junos', output: 'git')
end
before do
repo_head.expects(:name).twice.returns('refs/heads/master')
repo.expects(:head).twice.returns(repo_head)
- repo.expects(:path).returns('foo.git')
+ repo.expects(:path).returns('/foo.git')
repo.expects(:fetch).with('origin', ['refs/heads/master'], credentials: credentials).returns(Hash.new(0))
end
describe 'when there is only one repository and no groups' do
before do
- Oxidized.config.output.git.repo = 'foo.git'
+ Oxidized.config.output.git.repo = '/foo.git'
remote.expects(:url).returns('https://github.com/username/foo.git')
remote.expects(:push).with(['refs/heads/master'], credentials: credentials).returns(true)
repo.expects(:remotes).returns({'origin' => remote})
- Rugged::Repository.expects(:new).with('foo.git').returns(repo)
+ Rugged::Repository.expects(:new).with('/foo.git').returns(repo)
end
it "will push to the remote repository using https" do
@@ -136,7 +137,7 @@ describe GithubRepo do
describe 'and there are several repositories' do
let(:create_remote) { 'ggrroouupp#remote_repo' }
- let(:repository) { './ggrroouupp.git' }
+ let(:repository) { '/ggrroouupp.git' }
before do
Oxidized.config.output.git.repo.ggrroouupp = repository
@@ -151,7 +152,7 @@ describe GithubRepo do
describe 'and has a single repository' do
let(:create_remote) { 'github_repo_hook#remote_repo' }
- let(:repository) { 'foo.git' }
+ let(:repository) { '/foo.git' }
before do
Oxidized.config.output.git.repo = repository
diff --git a/spec/node_spec.rb b/spec/node_spec.rb
index 5cb5216..829e05a 100644
--- a/spec/node_spec.rb
+++ b/spec/node_spec.rb
@@ -46,6 +46,7 @@ describe Oxidized::Node do
describe '#repo' do
before do
+ Oxidized.config.output.default = 'git'
Oxidized::Node.any_instance.unstub(:resolve_repo)
end