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
92 changes: 92 additions & 0 deletions test/models/unit/lifecycle_environment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
require 'foreman_ansible_director_test_helper'

module ForemanAnsibleDirectorTests
module Models
module Unit
class LifecycleEnvironmentTest < ForemanAnsibleDirectorTestCase
setup do
@path = FactoryBot.create(:lifecycle_environment_path, organization: @organization)
@environment = FactoryBot.create(
:lifecycle_environment,
organization: @organization,
lifecycle_environment_path: @path
)
@collection = FactoryBot.create(:ansible_collection, organization: @organization)
@version = FactoryBot.create(:content_unit_version, versionable: @collection)
end

test 'content_unit_versions returns direct content without snapshot' do
@environment.assign_content_unit_version!(@version)

assert_equal [@version], @environment.content_unit_versions.to_a
end

test 'content_unit_versions returns snapshot content when snapshot is assigned' do
direct_version = FactoryBot.create(:content_unit_version, versionable: @collection)
snapshot = FactoryBot.create(:content_snapshot, references: 1)
FactoryBot.create(
:content_snapshot_content_unit_version,
content_snapshot: snapshot,
content_unit_version: @version
)
@environment.assign_content_unit_version!(direct_version)
@environment.update!(content_snapshot: snapshot)

assert_equal [@version], @environment.content_unit_versions.to_a
end

test 'content_hash returns snapshot content hash when snapshot is assigned' do
snapshot = FactoryBot.create(:content_snapshot, content_hash: 'snapshot')
@environment.assign_content_unit_version!(@version)
@environment.update!(content_snapshot: snapshot)

assert_equal 'snapshot', @environment.content_hash
end

test 'assign_execution_environment! assigns existing execution environment' do
execution_environment = FactoryBot.create(:execution_environment, organization: @organization)

assert @environment.assign_execution_environment!(execution_environment.id)
assert_equal execution_environment.id, @environment.reload.execution_environment_id
end

test 'assign_execution_environment! returns false for missing execution environment' do
assert_equal false, @environment.assign_execution_environment!(-1)
assert_includes @environment.errors[:execution_environment_id], 'not found'
end

test 'root and leaf reflect linked path position' do
child = FactoryBot.create(
:lifecycle_environment,
organization: @organization,
lifecycle_environment_path: @path,
parent: @environment
)
@environment.update!(child: child)

assert @environment.root?
assert_not @environment.leaf?
assert_not child.root?
assert child.leaf?
end

test 'ancestors returns parents recursively' do
child = FactoryBot.create(
:lifecycle_environment,
organization: @organization,
lifecycle_environment_path: @path,
parent: @environment
)
grandchild = FactoryBot.create(
:lifecycle_environment,
organization: @organization,
lifecycle_environment_path: @path,
parent: child
)

assert_equal [child, @environment], grandchild.ancestors
end
end
end
end
end
Loading