Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
fba40d86
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
fba40d86
编写于
2月 03, 2020
作者:
R
Ryan Dahl
提交者:
GitHub
2月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use tokio::test for some of cli's unit tests (#3868)
上级
55063dd8
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
518 addition
and
617 deletion
+518
-617
cli/file_fetcher.rs
cli/file_fetcher.rs
+448
-508
cli/http_util.rs
cli/http_util.rs
+70
-109
未找到文件。
cli/file_fetcher.rs
浏览文件 @
fba40d86
此差异已折叠。
点击以展开。
cli/http_util.rs
浏览文件 @
fba40d86
...
...
@@ -269,37 +269,28 @@ impl AsyncRead for HttpBody {
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
crate
::
tokio_util
;
#[test]
fn
test_fetch_sync_string
()
{
#[t
okio::t
est]
async
fn
test_fetch_sync_string
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
Url
::
parse
(
"http://127.0.0.1:4545/cli/tests/fixture.json"
)
.unwrap
();
let
client
=
create_http_client
();
let
fut
=
fetch_string_once
(
client
,
&
url
,
None
)
.map
(|
result
|
match
result
{
Ok
(
FetchOnceResult
::
Code
(
ResultPayload
{
body
:
code
,
content_type
:
maybe_content_type
,
etag
,
x_typescript_types
,
}))
=>
{
assert
!
(
!
code
.is_empty
());
assert_eq!
(
maybe_content_type
,
Some
(
"application/json"
.to_string
()));
assert_eq!
(
etag
,
None
);
assert_eq!
(
x_typescript_types
,
None
);
}
_
=>
panic!
(),
});
tokio_util
::
run
(
fut
);
let
result
=
fetch_string_once
(
client
,
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Code
(
payload
))
=
result
{
assert
!
(
!
payload
.body
.is_empty
());
assert_eq!
(
payload
.content_type
,
Some
(
"application/json"
.to_string
()));
assert_eq!
(
payload
.etag
,
None
);
assert_eq!
(
payload
.x_typescript_types
,
None
);
}
else
{
panic!
();
}
drop
(
http_server_guard
);
}
#[test]
fn
test_fetch_gzip
()
{
#[t
okio::t
est]
async
fn
test_fetch_gzip
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
Url
::
parse
(
...
...
@@ -307,72 +298,53 @@ mod tests {
)
.unwrap
();
let
client
=
create_http_client
();
let
fut
=
fetch_string_once
(
client
,
&
url
,
None
)
.map
(|
result
|
match
result
{
Ok
(
FetchOnceResult
::
Code
(
ResultPayload
{
body
:
code
,
content_type
:
maybe_content_type
,
etag
,
x_typescript_types
,
}))
=>
{
assert
!
(
!
code
.is_empty
());
assert_eq!
(
code
,
"console.log('gzip')"
);
assert_eq!
(
maybe_content_type
,
Some
(
"application/javascript"
.to_string
())
);
assert_eq!
(
etag
,
None
);
assert_eq!
(
x_typescript_types
,
None
);
}
_
=>
panic!
(),
});
tokio_util
::
run
(
fut
);
let
result
=
fetch_string_once
(
client
,
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Code
(
payload
))
=
result
{
assert_eq!
(
payload
.body
,
"console.log('gzip')"
);
assert_eq!
(
payload
.content_type
,
Some
(
"application/javascript"
.to_string
())
);
assert_eq!
(
payload
.etag
,
None
);
assert_eq!
(
payload
.x_typescript_types
,
None
);
}
else
{
panic!
();
}
drop
(
http_server_guard
);
}
#[test]
fn
test_fetch_with_etag
()
{
#[t
okio::t
est]
async
fn
test_fetch_with_etag
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
let
url
=
Url
::
parse
(
"http://127.0.0.1:4545/etag_script.ts"
)
.unwrap
();
let
client
=
create_http_client
();
let
fut
=
async
move
{
fetch_string_once
(
client
.clone
(),
&
url
,
None
)
.map
(|
result
|
match
result
{
Ok
(
FetchOnceResult
::
Code
(
ResultPayload
{
body
:
code
,
content_type
:
maybe_content_type
,
etag
,
x_typescript_types
,
}))
=>
{
assert
!
(
!
code
.is_empty
());
assert_eq!
(
code
,
"console.log('etag')"
);
assert_eq!
(
maybe_content_type
,
Some
(
"application/typescript"
.to_string
())
);
assert_eq!
(
etag
,
Some
(
"33a64df551425fcc55e"
.to_string
()));
assert_eq!
(
x_typescript_types
,
None
);
}
_
=>
panic!
(),
})
.await
;
let
result
=
fetch_string_once
(
client
.clone
(),
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Code
(
ResultPayload
{
body
,
content_type
,
etag
,
x_typescript_types
,
}))
=
result
{
assert
!
(
!
body
.is_empty
());
assert_eq!
(
body
,
"console.log('etag')"
);
assert_eq!
(
content_type
,
Some
(
"application/typescript"
.to_string
()));
assert_eq!
(
etag
,
Some
(
"33a64df551425fcc55e"
.to_string
()));
assert_eq!
(
x_typescript_types
,
None
);
}
else
{
panic!
();
}
let
res
=
fetch_string_once
(
client
,
&
url
,
Some
(
"33a64df551425fcc55e"
.to_string
()),
)
.await
;
assert_eq!
(
res
.unwrap
(),
FetchOnceResult
::
NotModified
);
};
let
res
=
fetch_string_once
(
client
,
&
url
,
Some
(
"33a64df551425fcc55e"
.to_string
()))
.await
;
assert_eq!
(
res
.unwrap
(),
FetchOnceResult
::
NotModified
);
tokio_util
::
run
(
fut
);
drop
(
http_server_guard
);
}
#[test]
fn
test_fetch_brotli
()
{
#[t
okio::t
est]
async
fn
test_fetch_brotli
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
Url
::
parse
(
...
...
@@ -380,32 +352,24 @@ mod tests {
)
.unwrap
();
let
client
=
create_http_client
();
let
fut
=
fetch_string_once
(
client
,
&
url
,
None
)
.map
(|
result
|
match
result
{
Ok
(
FetchOnceResult
::
Code
(
ResultPayload
{
body
:
code
,
content_type
:
maybe_content_type
,
etag
,
x_typescript_types
,
}))
=>
{
assert
!
(
!
code
.is_empty
());
assert_eq!
(
code
,
"console.log('brotli');"
);
assert_eq!
(
maybe_content_type
,
Some
(
"application/javascript"
.to_string
())
);
assert_eq!
(
etag
,
None
);
assert_eq!
(
x_typescript_types
,
None
);
}
_
=>
panic!
(),
});
tokio_util
::
run
(
fut
);
let
result
=
fetch_string_once
(
client
,
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Code
(
payload
))
=
result
{
assert
!
(
!
payload
.body
.is_empty
());
assert_eq!
(
payload
.body
,
"console.log('brotli');"
);
assert_eq!
(
payload
.content_type
,
Some
(
"application/javascript"
.to_string
())
);
assert_eq!
(
payload
.etag
,
None
);
assert_eq!
(
payload
.x_typescript_types
,
None
);
}
else
{
panic!
();
}
drop
(
http_server_guard
);
}
#[test]
fn
test_fetch_string_once_with_redirect
()
{
#[t
okio::t
est]
async
fn
test_fetch_string_once_with_redirect
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
...
...
@@ -414,15 +378,12 @@ mod tests {
let
target_url
=
Url
::
parse
(
"http://localhost:4545/cli/tests/fixture.json"
)
.unwrap
();
let
client
=
create_http_client
();
let
fut
=
fetch_string_once
(
client
,
&
url
,
None
)
.map
(
move
|
result
|
match
result
{
Ok
(
FetchOnceResult
::
Redirect
(
url
))
=>
{
assert_eq!
(
url
,
target_url
);
}
_
=>
panic!
(),
});
tokio_util
::
run
(
fut
);
let
result
=
fetch_string_once
(
client
,
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Redirect
(
url
))
=
result
{
assert_eq!
(
url
,
target_url
);
}
else
{
panic!
();
}
drop
(
http_server_guard
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录