This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation and tests for tunnel command
- Loading branch information
Showing
11 changed files
with
251 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.rubocop-* | ||
.tmp/* | ||
./ngrok* |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'test_helper' | ||
|
||
module ShopifyCli | ||
module Commands | ||
class TunnelTest < MiniTest::Test | ||
def setup | ||
@command = ShopifyCli::Commands::Tunnel.new | ||
end | ||
|
||
def test_start | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:call) | ||
@command.call(['start'], nil) | ||
end | ||
|
||
def test_stop | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:stop) | ||
@command.call(['stop'], nil) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
t=2019-03-26T14:45:57-0400 lvl=dbug msg="start tunnel listen" obj=tunnels.session name="command_line (http)" proto=http opts="&{Hostname:example.ngrok.io Auth: Subdomain: HostHeaderRewrite:false LocalURLScheme:http}" err=nil | ||
t=2019-03-26T14:45:57-0400 lvl=info msg="started tunnel" obj=tunnels name="command_line (http)" addr=http://localhost:8081 url=http://example.ngrok.io | ||
t=2019-03-26T14:45:57-0400 lvl=info msg="started tunnel" obj=tunnels name=command_line addr=http://localhost:8081 url=https://example.ngrok.io |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
t=2019-01-04T10:03:57-0500 lvl=crit msg="command failed" err="Tunnel session failed: Your account may not run more than 8 tunnels over a single ngrok client session." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'test_helper' | ||
|
||
module ShopifyCli | ||
module Tasks | ||
class TunnelTest < MiniTest::Test | ||
include TestHelpers::Context | ||
|
||
def setup | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:pid_file).returns(pid_path) | ||
super | ||
FakeFS::FileSystem.clone(pid_path) | ||
end | ||
|
||
def test_start_running_returns_url | ||
stub_binary | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:running?).returns(true) | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:state).returns( | ||
url: 'https://example.ngrok.io', | ||
) | ||
assert_equal 'https://example.ngrok.io', ShopifyCli::Tasks::Tunnel.new.call(@context) | ||
end | ||
|
||
def test_start_not_running_returns_starts_ngrok | ||
binary = stub_binary | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:running?).returns(false) | ||
with_log do |log_path| | ||
@context.expects(:spawn).with( | ||
"exec #{binary} http -log=stdout -log-level=debug 8081 > #{log_path}", | ||
chdir: ShopifyCli::ROOT | ||
).returns(1000) | ||
Process.expects(:detach).with(1000) | ||
@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) | ||
end | ||
end | ||
|
||
def test_start_raises_error_on_ngrok_failure | ||
binary = stub_binary | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:running?).returns(false) | ||
with_log('ngrok_error') do |log_path| | ||
@context.expects(:spawn).with( | ||
"exec #{binary} http -log=stdout -log-level=debug 8081 > #{log_path}", | ||
chdir: ShopifyCli::ROOT | ||
).returns(1000) | ||
assert_raises ShopifyCli::Tasks::Tunnel::NgrokError do | ||
ShopifyCli::Tasks::Tunnel.new.call(@context) | ||
end | ||
end | ||
end | ||
|
||
def with_log(fixture = 'ngrok') | ||
log_path = File.join(File.absolute_path(File.dirname(__FILE__)), "../fixtures/#{fixture}.log") | ||
FakeFS::FileSystem.clone(log_path) | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:log).returns(log_path) | ||
yield(log_path) | ||
end | ||
|
||
def stub_binary | ||
ShopifyCli::Tasks::Tunnel.any_instance.stubs(:install) | ||
binary = File.join(ShopifyCli::ROOT, 'ngrok') | ||
FakeFS::FileSystem.clone(binary) | ||
binary | ||
end | ||
|
||
def pid_path | ||
@pid_path ||= File.join(File.absolute_path(File.dirname(__FILE__)), '../fixtures/ngrok.pid') | ||
end | ||
end | ||
end | ||
end |