From 7659da0e1a115da1e1bb063bb94324648a9417f7 Mon Sep 17 00:00:00 2001 From: Tyler Ball Date: Fri, 17 May 2019 11:33:02 -0400 Subject: [PATCH] fix missing write state in tunnel task --- lib/shopify-cli/tasks/tunnel.rb | 5 +++-- test/fixtures/ngrok.pid | 1 + test/task/tunnel_test.rb | 14 +++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/shopify-cli/tasks/tunnel.rb b/lib/shopify-cli/tasks/tunnel.rb index 0299878301..44e81c683a 100644 --- a/lib/shopify-cli/tasks/tunnel.rb +++ b/lib/shopify-cli/tasks/tunnel.rb @@ -1,5 +1,5 @@ require 'json' -require 'tempfile' +require 'fileutils' require 'shopify_cli' module ShopifyCli @@ -34,7 +34,8 @@ def start install unless running? - ShopifyCli::Helpers::ProcessSupervision.start(ngrok_command) + pid = ShopifyCli::Helpers::ProcessSupervision.start(ngrok_command) + write_state(pid, Time.now) end url = fetch_url @ctx.puts("{{green:✔︎}} ngrok tunnel running at #{url}") diff --git a/test/fixtures/ngrok.pid b/test/fixtures/ngrok.pid index e69de29bb2..1b3909214e 100644 --- a/test/fixtures/ngrok.pid +++ b/test/fixtures/ngrok.pid @@ -0,0 +1 @@ +{"pid":40000,"time":"2019-01-01 12:34:56 -0400"} diff --git a/test/task/tunnel_test.rb b/test/task/tunnel_test.rb index 88ff24af4d..8f72780b86 100644 --- a/test/task/tunnel_test.rb +++ b/test/task/tunnel_test.rb @@ -13,10 +13,9 @@ def setup def test_start_running_returns_url with_log do - Tunnel.any_instance.stubs(:running?).returns(true) - Tunnel.any_instance.stubs(:state).returns( - url: 'https://example.ngrok.io', - ) + ShopifyCli::Helpers::ProcessSupervision.stubs(:running?) + .with(40000).returns(:true) + FakeFS::FileSystem.clone(pid_path) Tunnel.new.call(@context) assert_equal 'https://example.ngrok.io', @context.app_metadata[:host] end @@ -27,11 +26,12 @@ def test_start_not_running_starts_ngrok with_log do ShopifyCli::Helpers::ProcessSupervision.expects(:start).with( "exec #{File.join(ShopifyCli::ROOT, 'ngrok')} http -log=stdout -log-level=debug 8081 > /tmp/ngrok.log" - ) + ).returns(40004) @context.expects(:puts).with( "{{green:✔︎}} ngrok tunnel running at https://example.ngrok.io" ) assert_equal 'https://example.ngrok.io', ShopifyCli::Tasks::Tunnel.new.call(@context) + assert File.read(pid_path).include?('"pid":40004') assert_equal 'https://example.ngrok.io', @context.app_metadata[:host] end end @@ -49,7 +49,7 @@ def test_start_raises_error_on_ngrok_failure end def with_log(fixture = 'ngrok') - log_path = File.join(File.absolute_path(File.dirname(__FILE__)), "../fixtures/#{fixture}.log") + log_path = File.join(ShopifyCli::ROOT, "test/fixtures/#{fixture}.log") FakeFS::FileSystem.clone(log_path) Tunnel.any_instance.stubs(:log).returns( FakeLogger.new(log_path) @@ -58,7 +58,7 @@ def with_log(fixture = 'ngrok') end def pid_path - @pid_path ||= File.join(File.absolute_path(File.dirname(__FILE__)), '../fixtures/ngrok.pid') + @pid_path ||= File.join(ShopifyCli::ROOT, 'test/fixtures/ngrok.pid') end class FakeLogger < ShopifyCli::Tasks::Tunnel::Logger