mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
test: integration tests for tarring/unfurling (#21544)
This commit is contained in:
parent
86769b0d1c
commit
bbf8f69cb9
9 changed files with 110 additions and 1 deletions
|
@ -132,6 +132,9 @@ mod node_compat_tests;
|
|||
mod node_unit_tests;
|
||||
#[path = "npm_tests.rs"]
|
||||
mod npm;
|
||||
#[path = "publish_tests.rs"]
|
||||
mod publish;
|
||||
|
||||
#[path = "repl_tests.rs"]
|
||||
mod repl;
|
||||
#[path = "run_tests.rs"]
|
||||
|
|
38
cli/tests/integration/publish_tests.rs
Normal file
38
cli/tests/integration/publish_tests.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
static TEST_REGISTRY_URL: &str = "http://127.0.0.1:4250";
|
||||
|
||||
pub fn env_vars_for_registry() -> Vec<(String, String)> {
|
||||
vec![
|
||||
(
|
||||
"DENO_REGISTRY_URL".to_string(),
|
||||
TEST_REGISTRY_URL.to_string(),
|
||||
),
|
||||
(
|
||||
"DENO_REGISTRY_API_URL".to_string(),
|
||||
TEST_REGISTRY_URL.to_string(),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
itest!(no_token {
|
||||
args: "do-not-use-publish publish/missing_deno_json",
|
||||
output: "publish/no_token.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(missing_deno_json {
|
||||
args:
|
||||
"do-not-use-publish --token 'sadfasdf' $TESTDATA/publish/missing_deno_json",
|
||||
output: "publish/missing_deno_json.out",
|
||||
exit_code: 1,
|
||||
temp_cwd: true,
|
||||
});
|
||||
|
||||
itest!(successful {
|
||||
args: "do-not-use-publish --token 'sadfasdf' $TESTDATA/publish/successful",
|
||||
output: "publish/successful.out",
|
||||
envs: env_vars_for_registry(),
|
||||
http_server: true,
|
||||
temp_cwd: true,
|
||||
});
|
1
cli/tests/testdata/publish/missing_deno_json.out
vendored
Normal file
1
cli/tests/testdata/publish/missing_deno_json.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
error: Failed to read deno.json file at [WILDCARD]missing_deno_json[WILDCARD]
|
1
cli/tests/testdata/publish/no_token.out
vendored
Normal file
1
cli/tests/testdata/publish/no_token.out
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
error: No means to authenticate. Pass a token to `--token`[WILDCARD]
|
3
cli/tests/testdata/publish/successful.out
vendored
Normal file
3
cli/tests/testdata/publish/successful.out
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
Publishing @foo/bar@1.0.0 ...
|
||||
Successfully published @foo/bar@1.0.0
|
||||
http://127.0.0.1:4250/@foo/bar/1.0.0_meta.json
|
10
cli/tests/testdata/publish/successful/deno.json
vendored
Normal file
10
cli/tests/testdata/publish/successful/deno.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name": "@foo/bar",
|
||||
"version": "1.0.0",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@std/http": "jsr:@std/http@1"
|
||||
}
|
||||
}
|
5
cli/tests/testdata/publish/successful/mod.ts
vendored
Normal file
5
cli/tests/testdata/publish/successful/mod.ts
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
import http from "@std/http";
|
||||
|
||||
export function foobar() {
|
||||
return http.fileServer;
|
||||
}
|
|
@ -538,7 +538,7 @@ async fn perform_publish(
|
|||
package.version
|
||||
);
|
||||
println!(
|
||||
"{}/@{}/{}/{}_meta.json",
|
||||
"{}@{}/{}/{}_meta.json",
|
||||
registry_url, package.scope, package.package, package.version
|
||||
);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ use pty::Pty;
|
|||
use regex::Regex;
|
||||
use rustls_tokio_stream::TlsStream;
|
||||
use serde::Serialize;
|
||||
use serde_json::json;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::Infallible;
|
||||
use std::env;
|
||||
|
@ -120,6 +121,7 @@ const WS_CLOSE_PORT: u16 = 4244;
|
|||
const WS_PING_PORT: u16 = 4245;
|
||||
const H2_GRPC_PORT: u16 = 4246;
|
||||
const H2S_GRPC_PORT: u16 = 4247;
|
||||
const REGISTRY_SERVER_PORT: u16 = 4250;
|
||||
|
||||
pub const PERMISSION_VARIANTS: [&str; 5] =
|
||||
["read", "write", "env", "net", "run"];
|
||||
|
@ -1815,6 +1817,8 @@ pub async fn run_all_servers() {
|
|||
let h2_only_server_fut = wrap_http_h2_only_server();
|
||||
let h2_grpc_server_fut = h2_grpc_server();
|
||||
|
||||
let registry_server_fut = registry_server();
|
||||
|
||||
let server_fut = async {
|
||||
futures::join!(
|
||||
redirect_server_fut,
|
||||
|
@ -1840,6 +1844,7 @@ pub async fn run_all_servers() {
|
|||
h1_only_server_fut,
|
||||
h2_only_server_fut,
|
||||
h2_grpc_server_fut,
|
||||
registry_server_fut,
|
||||
)
|
||||
}
|
||||
.boxed_local();
|
||||
|
@ -2698,6 +2703,49 @@ pub fn parse_max_mem(output: &str) -> Option<u64> {
|
|||
None
|
||||
}
|
||||
|
||||
async fn registry_server_handler(
|
||||
req: Request<Body>,
|
||||
) -> Result<Response<Body>, hyper::http::Error> {
|
||||
let path = req.uri().path();
|
||||
|
||||
if path.starts_with("/scopes/") {
|
||||
let body = serde_json::to_string_pretty(&json!({
|
||||
"id": "sdfwqer-sffg-qwerasdf",
|
||||
"status": "success",
|
||||
"error": null
|
||||
}))
|
||||
.unwrap();
|
||||
let res = Response::new(Body::from(body));
|
||||
return Ok(res);
|
||||
} else if path.starts_with("/publish_status/") {
|
||||
let body = serde_json::to_string_pretty(&json!({
|
||||
"id": "sdfwqer-qwer-qwerasdf",
|
||||
"status": "success",
|
||||
"error": null
|
||||
}))
|
||||
.unwrap();
|
||||
let res = Response::new(Body::from(body));
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
Response::builder()
|
||||
.status(StatusCode::NOT_FOUND)
|
||||
.body(Body::empty())
|
||||
}
|
||||
|
||||
async fn registry_server() {
|
||||
let registry_server_addr =
|
||||
SocketAddr::from(([127, 0, 0, 1], REGISTRY_SERVER_PORT));
|
||||
let registry_server_svc = make_service_fn(|_| async {
|
||||
Ok::<_, Infallible>(service_fn(registry_server_handler))
|
||||
});
|
||||
let registry_server =
|
||||
Server::bind(®istry_server_addr).serve(registry_server_svc);
|
||||
if let Err(e) = registry_server.await {
|
||||
eprintln!("Registry server error: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod colors {
|
||||
use std::io::Write;
|
||||
|
||||
|
|
Loading…
Reference in a new issue