Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
fix missing write state in tunnel task
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerball committed May 17, 2019
1 parent 59db9dc commit 7659da0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/shopify-cli/tasks/tunnel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'json'
require 'tempfile'
require 'fileutils'
require 'shopify_cli'

module ShopifyCli
Expand Down Expand Up @@ -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}")
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/ngrok.pid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pid":40000,"time":"2019-01-01 12:34:56 -0400"}
14 changes: 7 additions & 7 deletions test/task/tunnel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 7659da0

Please sign in to comment.