From b8f56e81dcc7696bb983cfc89a4829d28d4d638b Mon Sep 17 00:00:00 2001 From: Danilo Sousa Date: Tue, 26 Jul 2016 13:37:29 -0300 Subject: only resolve the repository path when the output is `git` fixes #512 --- lib/oxidized/node.rb | 10 ++++++++-- spec/githubrepo_spec.rb | 15 ++++++++------- spec/node_spec.rb | 1 + 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 -- cgit v1.2.1