From c08bc16169ba1749819593789d724b905ba00c56 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 6 Oct 2022 13:35:37 +0300 Subject: [PATCH] [#273] update tests after rebase --- .../projects/deployments_controller_test.rb | 9 ++++-- core/test/dummy/db/schema.rb | 28 ------------------- core/test/support/controller_stub_support.rb | 10 +++++-- db/schema.rb | 28 ------------------- 4 files changed, 15 insertions(+), 60 deletions(-) diff --git a/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller_test.rb b/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller_test.rb index 2c80992c..99830cf2 100644 --- a/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller_test.rb +++ b/core/test/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller_test.rb @@ -808,7 +808,11 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon end test '#create - with content when compose file does not exist' do + deployment_data = json_fixture('files/controller/deployments.json') + stubbed_deployment_request = stub_controller_get_deployment_request_any(deployment_data) stubbed_controller_create_deployment_request = stub_controller_create_deployment_request + stub_controller_apply_credential + file_content = File.read('test/fixtures/files/test-compose-success-without-dependencies.yml') encoded_content = Base64.encode64(file_content) stub_dockerhub_repository_any @@ -837,6 +841,7 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon assert_response :success assert_requested stubbed_controller_create_deployment_request + assert_requested stubbed_deployment_request container_keys = [:image, :tag, :service_name, :port, :public] actual_containers_attributes = UffizziCore::Container.all.map { |c| c.attributes.deep_symbolize_keys.slice(*container_keys) } @@ -977,11 +982,11 @@ class UffizziCore::Api::Cli::V1::Projects::DeploymentsControllerTest < ActionCon expected_request_to_controller = { containers: [expected_app_container, expected_nginx_container], - credentials: [{ id: docker_hub_credential.id }], + credentials: [{ id: docker_hub_credential.id }, { id: @credential.id }], deployment_url: @deployment.preview_url, } - stubbed_deploy_containers_request = stub_deploy_containers_request_with_body(@deployment, expected_request_to_controller) + stubbed_deploy_containers_request = stub_deploy_containers_request_with_expected(@deployment, expected_request_to_controller) post :deploy_containers, params: params, format: :json diff --git a/core/test/dummy/db/schema.rb b/core/test/dummy/db/schema.rb index ec327906..40ae6990 100644 --- a/core/test/dummy/db/schema.rb +++ b/core/test/dummy/db/schema.rb @@ -129,16 +129,6 @@ t.index ["container_id"], name: "index_container_config_files_on_container_id" end - create_table "uffizzi_core_container_host_volume_files", force: :cascade do |t| - t.string "source_path" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.bigint "container_id", null: false - t.bigint "host_volume_file_id", null: false - t.index ["container_id"], name: "uf_core_cont_h_v_on_cont" - t.index ["host_volume_file_id"], name: "uf_core_cont_h_v_on_h_v_file" - end - create_table "uffizzi_core_containers", force: :cascade do |t| t.string "image" t.string "tag" @@ -224,20 +214,6 @@ t.index ["activity_item_id"], name: "index_events_on_activity_item_id" end - create_table "uffizzi_core_host_volume_files", force: :cascade do |t| - t.string "source" - t.string "path" - t.boolean "is_file" - t.binary "payload" - t.bigint "added_by_id" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.bigint "project_id", null: false - t.bigint "compose_file_id", null: false - t.index ["compose_file_id"], name: "index_host_volume_file_on_compose_file_id" - t.index ["project_id"], name: "index_host_volume_file_on_project_id" - end - create_table "uffizzi_core_invitations", force: :cascade do |t| t.text "email", null: false t.text "token", null: false @@ -424,8 +400,4 @@ t.index ["user_id"], name: "index_users_roles_on_user_id" end - add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_containers", column: "container_id" - add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_host_volume_files", column: "host_volume_file_id" - add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_compose_files", column: "compose_file_id" - add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_projects", column: "project_id" end diff --git a/core/test/support/controller_stub_support.rb b/core/test/support/controller_stub_support.rb index e65c5c2a..c0a25efe 100644 --- a/core/test/support/controller_stub_support.rb +++ b/core/test/support/controller_stub_support.rb @@ -25,6 +25,12 @@ def stub_controller_get_deployment_request(deployment, data = nil) stub_request(:get, uri).to_return(status: 200, body: data.to_json, headers: { 'Content-Type' => 'application/json' }) end + def stub_controller_get_deployment_request_any(data = nil) + uri = %r{#{Regexp.quote(Settings.controller.url.to_s)}/deployments/[0-9]*} + + stub_request(:get, uri).to_return(status: 200, body: data.to_json, headers: { 'Content-Type' => 'application/json' }) + end + def stub_delete_controller_deployment_request(deployment) uri = "#{Settings.controller.url}/deployments/#{deployment.id}" @@ -67,12 +73,12 @@ def stub_container_log_request(deployment_id, pod_name, limit, data) stub_request(:get, uri).to_return(status: 200, body: data.to_json, headers: { 'Content-Type' => 'application/json' }) end - def stub_deploy_containers_request_with_body(deployment, body) + def stub_deploy_containers_request_with_expected(deployment, expected_request) uri = "#{Settings.controller.url}/deployments/#{deployment.id}/containers" stub_request(:post, uri).with do |req| actual_body = JSON.parse(req.body).deep_symbolize_keys.deep_sort - expected_body = body.deep_symbolize_keys.deep_sort + expected_body = expected_request.deep_symbolize_keys.deep_sort actual_body == expected_body end diff --git a/db/schema.rb b/db/schema.rb index d37247fc..40ae6990 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -129,16 +129,6 @@ t.index ["container_id"], name: "index_container_config_files_on_container_id" end - create_table "uffizzi_core_container_host_volume_files", force: :cascade do |t| - t.string "source_path" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.bigint "container_id", null: false - t.bigint "host_volume_file_id", null: false - t.index ["container_id"], name: "uf_core_cont_h_v_on_cont" - t.index ["host_volume_file_id"], name: "uf_core_cont_h_v_on_h_v_file" - end - create_table "uffizzi_core_containers", force: :cascade do |t| t.string "image" t.string "tag" @@ -224,20 +214,6 @@ t.index ["activity_item_id"], name: "index_events_on_activity_item_id" end - create_table "uffizzi_core_host_volume_files", force: :cascade do |t| - t.string "source" - t.string "path" - t.boolean "is_file" - t.binary "payload" - t.bigint "added_by_id" - t.bigint "project_id", null: false - t.bigint "compose_file_id", null: false - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.index ["compose_file_id"], name: "index_host_volume_file_on_compose_file_id" - t.index ["project_id"], name: "index_host_volume_file_on_project_id" - end - create_table "uffizzi_core_invitations", force: :cascade do |t| t.text "email", null: false t.text "token", null: false @@ -424,8 +400,4 @@ t.index ["user_id"], name: "index_users_roles_on_user_id" end - add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_containers", column: "container_id" - add_foreign_key "uffizzi_core_container_host_volume_files", "uffizzi_core_host_volume_files", column: "host_volume_file_id" - add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_compose_files", column: "compose_file_id" - add_foreign_key "uffizzi_core_host_volume_files", "uffizzi_core_projects", column: "project_id" end