Skip to content

Commit

Permalink
Merge pull request #3190 from robertcheramy/2222-fix-group-nil
Browse files Browse the repository at this point in the history
Fix version not found in oxidized-web
  • Loading branch information
robertcheramy committed Jun 13, 2024
2 parents c17f7a5 + 5ae6f40 commit d87b2ca
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Fixed
- fixed prompt for vyos/vyatta to allow logins with non-priviliged accounts. Fixes #3111 (@h-lopez)
- fixed power consumption included in ArubaOS-CX diffs starting with FL.10.13.xxx. Fixes #3142 (@terratalpi)
- fixed oxidized-web getting "version not found" when fetching a version from git and no group is defined. Fixes #2222 (@robertcheramy)

## [0.30.1 – 2024-04-12]

Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/output/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_diff(node, group, oid1, oid2)
def yield_repo_and_path(node, group)
repo, path = node.repo, node.name

path = "#{group}/#{node.name}" if group && @cfg.single_repo?
path = "#{group}/#{node.name}" if group && !group.empty? && @cfg.single_repo?

[repo, path]
end
Expand Down
42 changes: 42 additions & 0 deletions spec/output/git_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require_relative '../spec_helper'
require 'oxidized/output/git'

describe Oxidized::Git do
describe '#yield_repo_and_path' do
# Note that #yield_repo_and_path is private, so we can not call it directy
# we use @git.send(:yield_repo_and_path, ...) to bypass the protection
before do
# Default value in most tests
Oxidized.config.output.git.single_repo = true

@mock_node = Minitest::Mock.new
@mock_node.expect(:repo, '/tmp/oxidized.git')
@mock_node.expect(:name, 'switch-42')

@git = Oxidized::Git.new
end

it 'accepts group = nil' do
result = @git.send(:yield_repo_and_path, @mock_node, nil)
_(result).must_equal ['/tmp/oxidized.git', 'switch-42']
end

it 'ignores an empty group' do
result = @git.send(:yield_repo_and_path, @mock_node, nil)
_(result).must_equal ['/tmp/oxidized.git', 'switch-42']
end

it 'takes the group into accout when simple_repo=true' do
# node.name will be needed a second time
@mock_node.expect(:name, 'switch-42')
result = @git.send(:yield_repo_and_path, @mock_node, 'testgroup')
_(result).must_equal ['/tmp/oxidized.git', 'testgroup/switch-42']
end

it 'ignores the group when simple_repo=false' do
Oxidized.config.output.git.single_repo = false
result = @git.send(:yield_repo_and_path, @mock_node, 'testgroup')
_(result).must_equal ['/tmp/oxidized.git', 'switch-42']
end
end
end

0 comments on commit d87b2ca

Please sign in to comment.