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

module ForemanAnsibleDirectorTests
module Models
module Unit
class ExecutionEnvironmentTest < ForemanAnsibleDirectorTestCase
setup do
@execution_environment = FactoryBot.create(:execution_environment, organization: @organization)
@collection = FactoryBot.create(:ansible_collection, organization: @organization)
@version = FactoryBot.create(:content_unit_version, versionable: @collection, version: '1.0.0')
end

test 'registry_url returns local registry path for execution environment' do
assert_equal(
"localhost/ansible_director/#{@execution_environment.id}:latest",
@execution_environment.registry_url
)
end

test 'generate_content_hash changes when content changes' do
original_hash = @execution_environment.generate_content_hash

@execution_environment.add_content_unit(@collection, @version)

assert_not_equal original_hash, @execution_environment.generate_content_hash
end

test 'generate_content_hash changes when ansible version changes' do
original_hash = @execution_environment.generate_content_hash

@execution_environment.ansible_version = '2.19.0'

assert_not_equal original_hash, @execution_environment.generate_content_hash
end

test 'generate_content_hash changes when base image changes' do
original_hash = @execution_environment.generate_content_hash

@execution_environment.base_image_url = 'quay.io/ansible/other-ee:latest'

assert_not_equal original_hash, @execution_environment.generate_content_hash
end

test 'rebuild_necessary? tracks content hash changes' do
@execution_environment.update!(content_hash: 'abcd1234')

assert @execution_environment.rebuild_necessary?
end

test 'add_content_unit creates execution environment content unit' do
assignment = @execution_environment.add_content_unit(@collection, @version)

assert_equal @execution_environment, assignment.execution_environment
assert_equal @collection, assignment.content_unit
assert_equal @version, assignment.content_unit_version
end

test 'add_content_unit reuses existing execution environment content unit' do
first_assignment = @execution_environment.add_content_unit(@collection, @version)
second_assignment = @execution_environment.add_content_unit(@collection, @version)

assert_equal first_assignment, second_assignment
assert_equal 1, @execution_environment.execution_environment_content_units.count
end
end
end
end
end
Loading