diff options
author | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-16 14:18:07 -0200 |
---|---|---|
committer | Danilo Sousa <dsgoncalves@uoldiveo.com> | 2016-02-18 12:14:03 -0200 |
commit | e17356f22505f0aed88fd04c9925b8aeb2520e28 (patch) | |
tree | 73db9857b9edc3e9c736228bedaa80bf521941fd | |
parent | 2e7dd813f8659e9418b65983b661b48a1aaf832e (diff) |
`Node#repo` should return the node group repository
-rw-r--r-- | lib/oxidized/node.rb | 14 | ||||
-rw-r--r-- | spec/node_spec.rb | 25 |
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 7a278a9..a1504b9 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -24,7 +24,7 @@ module Oxidized @vars = opt[:vars] @stats = Stats.new @retry = 0 - @repo = Oxidized.config.output.git.repo + @repo = resolve_repo # model instance needs to access node instance @model.node = self @@ -170,5 +170,17 @@ module Oxidized Oxidized.mgr.model[model].new end + def resolve_repo + git = Oxidized.config.output.git + cfg_repo = git.repo + + if group && !git.single_repo? + basedir = File.dirname(cfg_repo) + File.join(basedir, "#{group}.git") + else + cfg_repo + end + end + end end diff --git a/spec/node_spec.rb b/spec/node_spec.rb index c568463..f9c912e 100644 --- a/spec/node_spec.rb +++ b/spec/node_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Oxidized::Node do before(:each) do Oxidized.stubs(:asetus).returns(Asetus.new) + Oxidized.config.output.git.repo = '/tmp/repository.git' Oxidized::Node.any_instance.stubs(:resolve_output) @node = Oxidized::Node.new(name: 'example.com', @@ -41,4 +42,28 @@ describe Oxidized::Node do status.must_equal :success end end + + describe '#repo' do + it 'when there is no groups' do + @node.repo.must_equal '/tmp/repository.git' + end + + describe 'when there are groups' do + let(:node) do + Oxidized::Node.new({ + ip: '127.0.0.1', group: 'ggrroouupp', model: 'junos' + }) + end + + it 'with only one repository' do + Oxidized.config.output.git.single_repo = true + node.repo.must_equal '/tmp/repository.git' + end + + it 'with more than one repository' do + Oxidized.config.output.git.single_repo = false + node.repo.must_equal '/tmp/ggrroouupp.git' + end + end + end end |