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
|
||||
|
||||
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
|
||||
|
||||
@@ -17,8 +17,8 @@ class BrokenDeployTest < IntegrationTest
|
||||
|
||||
assert_failed_deploy output
|
||||
assert_app_is_up version: first_version
|
||||
assert_container_running host: :vm3, name: "app-workers-#{first_version}"
|
||||
assert_container_not_running host: :vm3, name: "app-workers-#{second_version}"
|
||||
assert_container_running host: :vm3, name: "app_with_roles-workers-#{first_version}"
|
||||
assert_container_not_running host: :vm3, name: "app_with_roles-workers-#{second_version}"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -23,7 +23,8 @@ asset_path: /usr/share/nginx/html/versions
|
||||
deploy_timeout: 2
|
||||
drain_timeout: 2
|
||||
readiness_delay: 0
|
||||
|
||||
proxy:
|
||||
host: 127.0.0.1
|
||||
registry:
|
||||
server: registry:4443
|
||||
username: root
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
service: app
|
||||
image: app
|
||||
service: app_with_roles
|
||||
image: app_with_roles
|
||||
servers:
|
||||
web:
|
||||
hosts:
|
||||
@@ -14,6 +14,7 @@ drain_timeout: 2
|
||||
readiness_delay: 0
|
||||
|
||||
proxy:
|
||||
host: localhost
|
||||
healthcheck:
|
||||
interval: 1
|
||||
timeout: 1
|
||||
|
||||
@@ -8,6 +8,8 @@ server {
|
||||
|
||||
location / {
|
||||
proxy_pass http://loadbalancer;
|
||||
proxy_set_header Host $host;
|
||||
|
||||
proxy_connect_timeout 10;
|
||||
proxy_send_timeout 10;
|
||||
proxy_read_timeout 10;
|
||||
|
||||
@@ -50,8 +50,8 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
assert_equal "502", response.code
|
||||
end
|
||||
|
||||
def assert_app_is_up(version: nil)
|
||||
response = app_response
|
||||
def assert_app_is_up(version: nil, app: @app)
|
||||
response = app_response(app: app)
|
||||
debug_response_code(response, "200")
|
||||
assert_equal "200", response.code
|
||||
assert_app_version(version, response) if version
|
||||
@@ -69,8 +69,8 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
assert_equal up_times, up_count
|
||||
end
|
||||
|
||||
def app_response
|
||||
Net::HTTP.get_response(URI.parse("http://localhost:12345/version"))
|
||||
def app_response(app: @app)
|
||||
Net::HTTP.get_response(URI.parse("http://#{app_host(app)}:12345/version"))
|
||||
end
|
||||
|
||||
def update_app_rev
|
||||
@@ -156,4 +156,23 @@ class IntegrationTest < ActiveSupport::TestCase
|
||||
def assert_directory_removed(directory)
|
||||
assert docker_compose("exec vm1 ls #{directory} | wc -l", capture: true).strip == "0"
|
||||
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
|
||||
|
||||
@@ -46,13 +46,13 @@ class MainTest < IntegrationTest
|
||||
|
||||
assert_app_is_up version: version
|
||||
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
|
||||
|
||||
kamal :redeploy
|
||||
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
|
||||
|
||||
test "config" do
|
||||
@@ -100,6 +100,29 @@ class MainTest < IntegrationTest
|
||||
assert_app_directory_removed
|
||||
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
|
||||
def assert_envs(version:)
|
||||
assert_env :CLEAR_TOKEN, "4321", version: version, vm: :vm1
|
||||
@@ -115,21 +138,21 @@ class MainTest < IntegrationTest
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def assert_no_env(key, vm:, version:)
|
||||
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
|
||||
|
||||
def assert_accumulated_assets(*versions)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def vm1_image_ids
|
||||
|
||||
@@ -49,17 +49,4 @@ class ProxyTest < IntegrationTest
|
||||
kamal :proxy, :remove
|
||||
assert_proxy_not_running
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user