2016-03-20 18:40:03 +00:00
|
|
|
from six.moves import cStringIO as StringIO
|
2015-06-08 14:03:33 +00:00
|
|
|
import mock
|
|
|
|
|
2016-06-17 12:15:48 +00:00
|
|
|
from pathod import pathoc_cmdline as cmdline
|
|
|
|
|
|
|
|
from . import tutils
|
|
|
|
|
2015-06-08 14:03:33 +00:00
|
|
|
|
|
|
|
@mock.patch("argparse.ArgumentParser.error")
|
|
|
|
def test_pathoc(perror):
|
|
|
|
assert cmdline.args_pathoc(["pathoc", "foo.com", "get:/"])
|
2016-03-20 18:40:03 +00:00
|
|
|
s = StringIO()
|
2015-09-21 21:03:45 +00:00
|
|
|
with tutils.raises(SystemExit):
|
|
|
|
cmdline.args_pathoc(["pathoc", "--show-uas"], s, s)
|
2015-06-08 14:03:33 +00:00
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "foo.com:8888", "get:/"])
|
|
|
|
assert a.port == 8888
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "foo.com:xxx", "get:/"])
|
|
|
|
assert perror.called
|
|
|
|
perror.reset_mock()
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "-I", "10, 20", "foo.com:8888", "get:/"])
|
|
|
|
assert a.ignorecodes == [10, 20]
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "-I", "xx, 20", "foo.com:8888", "get:/"])
|
|
|
|
assert perror.called
|
|
|
|
perror.reset_mock()
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "-c", "foo:10", "foo.com:8888", "get:/"])
|
|
|
|
assert a.connect_to == ["foo", 10]
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "foo.com", "get:/", "--http2"])
|
2016-05-29 09:43:29 +00:00
|
|
|
assert a.use_http2 is True
|
|
|
|
assert a.ssl is True
|
2015-06-08 14:03:33 +00:00
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "foo.com", "get:/", "--http2-skip-connection-preface"])
|
2016-05-29 09:43:29 +00:00
|
|
|
assert a.use_http2 is True
|
|
|
|
assert a.ssl is True
|
|
|
|
assert a.http2_skip_connection_preface is True
|
2015-06-08 14:03:33 +00:00
|
|
|
|
|
|
|
a = cmdline.args_pathoc(["pathoc", "-c", "foo", "foo.com:8888", "get:/"])
|
|
|
|
assert perror.called
|
|
|
|
perror.reset_mock()
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(
|
|
|
|
["pathoc", "-c", "foo:bar", "foo.com:8888", "get:/"])
|
|
|
|
assert perror.called
|
|
|
|
perror.reset_mock()
|
|
|
|
|
|
|
|
a = cmdline.args_pathoc(
|
|
|
|
[
|
|
|
|
"pathoc",
|
|
|
|
"foo.com:8888",
|
|
|
|
tutils.test_data.path("data/request")
|
|
|
|
]
|
|
|
|
)
|
|
|
|
assert len(list(a.requests)) == 1
|
|
|
|
|
2015-09-21 21:03:45 +00:00
|
|
|
with tutils.raises(SystemExit):
|
|
|
|
cmdline.args_pathoc(["pathoc", "foo.com", "invalid"], s, s)
|