Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions test/lib/unit/simple_ansible_content_unit_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
require 'foreman_ansible_director_test_helper'

module ForemanAnsibleDirectorTests
module Lib
module Unit
class SimpleAnsibleContentUnitTest < ForemanAnsibleDirectorTestCase
test 'splits collection name into namespace and unit name' do
unit = simple_unit(unit_name: 'theforeman.operations')

assert_equal 'theforeman', unit.unit_namespace
assert_equal 'operations', unit.unit_name
end

test 'builds collection file with explicit versions' do
unit = simple_unit(unit_versions: %w[1.0.0 1.1.0])

collection_file = YAML.safe_load(unit.collection_file, permitted_classes: [Symbol])

assert_equal(
[
{
'name' => 'theforeman.operations',
'version' => '1.0.0',
'source' => 'https://galaxy.example.com',
'type' => :collection,
},
{
'name' => 'theforeman.operations',
'version' => '1.1.0',
'source' => 'https://galaxy.example.com',
'type' => :collection,
},
],
collection_file.fetch('collections')
)
end

test 'builds collection file without versions' do
unit = simple_unit(unit_versions: [])

collection_file = YAML.safe_load(unit.collection_file, permitted_classes: [Symbol])

assert_equal(
[
{
'name' => 'theforeman.operations',
'source' => 'https://galaxy.example.com',
},
],
collection_file.fetch('collections')
)
end

test 'builds role url for role units' do
unit = simple_unit(unit_type: :role, unit_name: 'theforeman.foreman')

assert_equal(
'https://galaxy.example.comapi/v1/roles/?namespace=theforeman&name=foreman',
unit.role_url
)
end

test 'to_hash serializes action input fields' do
unit = simple_unit(unit_versions: ['1.0.0'])

assert_equal(
{
unit_type: :collection,
name: 'theforeman.operations',
versions: ['1.0.0'],
source: 'https://galaxy.example.com',
type: :collection,
src: nil,
scm: nil,
},
unit.to_hash
)
end

private

def simple_unit(**overrides)
defaults = {
unit_type: :collection,
unit_name: 'theforeman.operations',
unit_source_type: :galaxy,
unit_source: 'https://galaxy.example.com',
unit_versions: ['1.0.0'],
}

::ForemanAnsibleDirector::AnsibleContent::SimpleAnsibleContentUnit.new(
**defaults.merge(overrides)
)
end
end
end
end
end
Loading