Integration test two apps
Use localhost for app_with_roles and 127.0.0.1 for app. Confirm we can deploy both and the respond to requests. Ensure the proxy is removed once both have been removed.
This commit is contained in:
@@ -9,7 +9,7 @@ class BrokenDeployTest < IntegrationTest
|
|||||||
kamal :deploy
|
kamal :deploy
|
||||||
|
|
||||||
assert_app_is_up version: first_version
|
assert_app_is_up version: first_version
|
||||||
assert_container_running host: :vm3, name: "app-workers-#{first_version}"
|
assert_container_running host: :vm3, name: "app_with_roles-workers-#{first_version}"
|
||||||
|
|
||||||
second_version = break_app
|
second_version = break_app
|
||||||
|
|
||||||
@@ -17,8 +17,8 @@ class BrokenDeployTest < IntegrationTest
|
|||||||
|
|
||||||
assert_failed_deploy output
|
assert_failed_deploy output
|
||||||
assert_app_is_up version: first_version
|
assert_app_is_up version: first_version
|
||||||
assert_container_running host: :vm3, name: "app-workers-#{first_version}"
|
assert_container_running host: :vm3, name: "app_with_roles-workers-#{first_version}"
|
||||||
assert_container_not_running host: :vm3, name: "app-workers-#{second_version}"
|
assert_container_not_running host: :vm3, name: "app_with_roles-workers-#{second_version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ asset_path: /usr/share/nginx/html/versions
|
|||||||
deploy_timeout: 2
|
deploy_timeout: 2
|
||||||
drain_timeout: 2
|
drain_timeout: 2
|
||||||
readiness_delay: 0
|
readiness_delay: 0
|
||||||
|
proxy:
|
||||||
|
host: 127.0.0.1
|
||||||
registry:
|
registry:
|
||||||
server: registry:4443
|
server: registry:4443
|
||||||
username: root
|
username: root
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
service: app
|
service: app_with_roles
|
||||||
image: app
|
image: app_with_roles
|
||||||
servers:
|
servers:
|
||||||
web:
|
web:
|
||||||
hosts:
|
hosts:
|
||||||
@@ -14,6 +14,7 @@ drain_timeout: 2
|
|||||||
readiness_delay: 0
|
readiness_delay: 0
|
||||||
|
|
||||||
proxy:
|
proxy:
|
||||||
|
host: localhost
|
||||||
healthcheck:
|
healthcheck:
|
||||||
interval: 1
|
interval: 1
|
||||||
timeout: 1
|
timeout: 1
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ server {
|
|||||||
|
|
||||||
location / {
|
location / {
|
||||||
proxy_pass http://loadbalancer;
|
proxy_pass http://loadbalancer;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
proxy_connect_timeout 10;
|
proxy_connect_timeout 10;
|
||||||
proxy_send_timeout 10;
|
proxy_send_timeout 10;
|
||||||
proxy_read_timeout 10;
|
proxy_read_timeout 10;
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ class IntegrationTest < ActiveSupport::TestCase
|
|||||||
assert_equal "502", response.code
|
assert_equal "502", response.code
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_app_is_up(version: nil)
|
def assert_app_is_up(version: nil, app: @app)
|
||||||
response = app_response
|
response = app_response(app: app)
|
||||||
debug_response_code(response, "200")
|
debug_response_code(response, "200")
|
||||||
assert_equal "200", response.code
|
assert_equal "200", response.code
|
||||||
assert_app_version(version, response) if version
|
assert_app_version(version, response) if version
|
||||||
@@ -69,8 +69,8 @@ class IntegrationTest < ActiveSupport::TestCase
|
|||||||
assert_equal up_times, up_count
|
assert_equal up_times, up_count
|
||||||
end
|
end
|
||||||
|
|
||||||
def app_response
|
def app_response(app: @app)
|
||||||
Net::HTTP.get_response(URI.parse("http://localhost:12345/version"))
|
Net::HTTP.get_response(URI.parse("http://#{app_host(app)}:12345/version"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_app_rev
|
def update_app_rev
|
||||||
@@ -156,4 +156,23 @@ class IntegrationTest < ActiveSupport::TestCase
|
|||||||
def assert_directory_removed(directory)
|
def assert_directory_removed(directory)
|
||||||
assert docker_compose("exec vm1 ls #{directory} | wc -l", capture: true).strip == "0"
|
assert docker_compose("exec vm1 ls #{directory} | wc -l", capture: true).strip == "0"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_proxy_running
|
||||||
|
assert_container_running(host: "vm1", name: "kamal-proxy")
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_proxy_not_running
|
||||||
|
assert_container_not_running(host: "vm1", name: "kamal-proxy")
|
||||||
|
end
|
||||||
|
|
||||||
|
def app_host(app = @app)
|
||||||
|
case app
|
||||||
|
when "app"
|
||||||
|
"127.0.0.1"
|
||||||
|
when "app_with_roles"
|
||||||
|
"localhost"
|
||||||
|
else
|
||||||
|
raise "Unknown app: #{app}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ class MainTest < IntegrationTest
|
|||||||
|
|
||||||
assert_app_is_up version: version
|
assert_app_is_up version: version
|
||||||
assert_hooks_ran "pre-connect", "pre-build", "pre-deploy", "post-deploy"
|
assert_hooks_ran "pre-connect", "pre-build", "pre-deploy", "post-deploy"
|
||||||
assert_container_running host: :vm3, name: "app-workers-#{version}"
|
assert_container_running host: :vm3, name: "app_with_roles-workers-#{version}"
|
||||||
|
|
||||||
second_version = update_app_rev
|
second_version = update_app_rev
|
||||||
|
|
||||||
kamal :redeploy
|
kamal :redeploy
|
||||||
assert_app_is_up version: second_version
|
assert_app_is_up version: second_version
|
||||||
assert_container_running host: :vm3, name: "app-workers-#{second_version}"
|
assert_container_running host: :vm3, name: "app_with_roles-workers-#{second_version}"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "config" do
|
test "config" do
|
||||||
@@ -100,6 +100,29 @@ class MainTest < IntegrationTest
|
|||||||
assert_app_directory_removed
|
assert_app_directory_removed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "two apps" do
|
||||||
|
@app = "app"
|
||||||
|
kamal :deploy
|
||||||
|
app1_version = latest_app_version
|
||||||
|
|
||||||
|
@app = "app_with_roles"
|
||||||
|
kamal :deploy
|
||||||
|
app2_version = latest_app_version
|
||||||
|
|
||||||
|
assert_app_is_up version: app1_version, app: "app"
|
||||||
|
assert_app_is_up version: app2_version, app: "app_with_roles"
|
||||||
|
|
||||||
|
@app = "app"
|
||||||
|
kamal :remove, "-y"
|
||||||
|
assert_app_directory_removed
|
||||||
|
assert_proxy_running
|
||||||
|
|
||||||
|
@app = "app_with_roles"
|
||||||
|
kamal :remove, "-y"
|
||||||
|
assert_app_directory_removed
|
||||||
|
assert_proxy_not_running
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def assert_envs(version:)
|
def assert_envs(version:)
|
||||||
assert_env :CLEAR_TOKEN, "4321", version: version, vm: :vm1
|
assert_env :CLEAR_TOKEN, "4321", version: version, vm: :vm1
|
||||||
@@ -115,21 +138,21 @@ class MainTest < IntegrationTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_env(key, value, vm:, version:)
|
def assert_env(key, value, vm:, version:)
|
||||||
assert_equal "#{key}=#{value}", docker_compose("exec #{vm} docker exec app-web-#{version} env | grep #{key}", capture: true)
|
assert_equal "#{key}=#{value}", docker_compose("exec #{vm} docker exec #{@app}-web-#{version} env | grep #{key}", capture: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_no_env(key, vm:, version:)
|
def assert_no_env(key, vm:, version:)
|
||||||
assert_raises(RuntimeError, /exit 1/) do
|
assert_raises(RuntimeError, /exit 1/) do
|
||||||
docker_compose("exec #{vm} docker exec app-web-#{version} env | grep #{key}", capture: true)
|
docker_compose("exec #{vm} docker exec #{@app}-web-#{version} env | grep #{key}", capture: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_accumulated_assets(*versions)
|
def assert_accumulated_assets(*versions)
|
||||||
versions.each do |version|
|
versions.each do |version|
|
||||||
assert_equal "200", Net::HTTP.get_response(URI.parse("http://localhost:12345/versions/#{version}")).code
|
assert_equal "200", Net::HTTP.get_response(URI.parse("http://#{app_host}:12345/versions/#{version}")).code
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal "200", Net::HTTP.get_response(URI.parse("http://localhost:12345/versions/.hidden")).code
|
assert_equal "200", Net::HTTP.get_response(URI.parse("http://#{app_host}:12345/versions/.hidden")).code
|
||||||
end
|
end
|
||||||
|
|
||||||
def vm1_image_ids
|
def vm1_image_ids
|
||||||
|
|||||||
@@ -49,17 +49,4 @@ class ProxyTest < IntegrationTest
|
|||||||
kamal :proxy, :remove
|
kamal :proxy, :remove
|
||||||
assert_proxy_not_running
|
assert_proxy_not_running
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
def assert_proxy_running
|
|
||||||
assert_match /basecamp\/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION} \"kamal-proxy run\"/, proxy_details
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_proxy_not_running
|
|
||||||
assert_no_match /basecamp\/kamal-proxy:#{Kamal::Configuration::PROXY_MINIMUM_VERSION} \"kamal-proxy run\"/, proxy_details
|
|
||||||
end
|
|
||||||
|
|
||||||
def proxy_details
|
|
||||||
kamal :proxy, :details, capture: true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user