Skip to content

Commit

Permalink
added deleting temporary compose file due deployment update
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Stepanov authored and 7R41N33 committed May 13, 2022
1 parent 79c4bfe commit 6f7cb2d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/app/services/uffizzi_core/deployment_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def update_from_compose(compose_file, project, user, deployment_id)
if deployment_form.valid?
deployment = UffizziCore::Deployment.find(deployment_id)
deployment.containers.destroy_all
deployment.compose_file.destroy if deployment.compose_file.kind.temporary?
deployment.update!(containers: deployment_form.containers, compose_file_id: compose_file.id)

return deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,11 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
assert_response :not_found
end

test '#update - success' do
test '#update - update deployment created from main compose file' do
file_content = File.read('test/fixtures/files/test-compose-success-without-dependencies.yml')
compose_file = create(:compose_file, project: @project, added_by: @admin)
create(:template, :compose_file_source, compose_file: compose_file, project: @project, added_by: @admin, payload: @template.payload)
@deployment.update!(compose_file: compose_file)
encoded_content = Base64.encode64(file_content)
compose_file_attributes = attributes_for(:compose_file, :temporary, project: @project, added_by: @admin, content: encoded_content)
create(:credential, :docker_hub, account: @admin.organizational_account)
Expand All @@ -234,6 +237,34 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon
assert_response :success
end

test '#update - update deployment created from temporary compose file' do
file_content = File.read('test/fixtures/files/test-compose-success-without-dependencies.yml')
compose_file = create(:compose_file, :temporary, project: @project, added_by: @admin)
create(:template, :compose_file_source, compose_file: compose_file, project: @project, added_by: @admin, payload: @template.payload)
@deployment.update!(compose_file: compose_file)
encoded_content = Base64.encode64(file_content)
compose_file_attributes = attributes_for(:compose_file, :temporary, project: @project, added_by: @admin, content: encoded_content)
create(:credential, :docker_hub, account: @admin.organizational_account)

params = {
project_slug: @project.slug,
compose_file: compose_file_attributes,
dependencies: [],
id: @deployment[:id],
}

differences = {
-> { UffizziCore::ComposeFile.temporary.count } => 0,
-> { UffizziCore::Template.with_creation_source(UffizziCore::Template.creation_source.compose_file).count } => 0,
}

assert_difference differences do
put :update, params: params, format: :json
end

assert_response :success
end

test '#deploy_containers' do
Sidekiq::Worker.clear_all
Sidekiq::Testing.fake!
Expand Down

0 comments on commit 6f7cb2d

Please sign in to comment.