Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
612 changes: 142 additions & 470 deletions rust/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ zip = { version = "8.6.0", default-features = false, features = ["deflate-flate2
iso_currency = "0.5.3"

[dev-dependencies]
httpmock = "0.7"
httpmock = "0.8"
tempfile = "3"

[lints.rust]
Expand Down
2 changes: 1 addition & 1 deletion rust/domains-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ prettyplease = "0.2"
syn = "2"

[dev-dependencies]
httpmock = "0.7"
httpmock = "0.8"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync"] }
21 changes: 18 additions & 3 deletions rust/src/api_explorer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,11 @@ fn search_command() -> RuntimeCommandSpec {
.with_tier(Tier::Read)
.no_auth(true)
.with_default_fields("domain,method,path,summary")
.with_output_schema::<ApiEndpoint>(),
.with_output_schema::<ApiEndpoint>()
.with_pagination(PaginationConfig {
max_limit: 100,
..Default::default()
}),
|_cred, args: SearchArgs| async move {
let hits = search_endpoints(catalog(), &args.query);
if hits.is_empty() {
Expand Down Expand Up @@ -2174,14 +2178,25 @@ fn schema_get_command() -> RuntimeCommandSpec {

#[cfg(test)]
mod tests {
use cli_engine::{Cli, CliConfig};
use cli_engine::{Cli, CliConfig, PaginationConfig};

use super::{catalog, find_endpoint, merge_required_scopes};
use super::{catalog, find_endpoint, merge_required_scopes, search_command};

fn v(items: &[&str]) -> Vec<String> {
items.iter().map(|s| (*s).to_owned()).collect()
}

#[test]
fn search_command_opts_into_pagination_with_no_default_and_a_max_limit() {
assert_eq!(
search_command().spec.pagination,
Some(PaginationConfig {
max_limit: 100,
..Default::default()
})
);
}

#[test]
fn merge_flags_only_when_no_endpoint_scopes() {
assert_eq!(merge_required_scopes(v(&["a", "b"]), &[]), v(&["a", "b"]));
Expand Down
42 changes: 15 additions & 27 deletions rust/src/application/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,11 @@ mod tests {
when.method(POST)
.path("/v1/apps/app-registry-subgraph")
.header("authorization", "Bearer test-token")
.matches(|req| {
req.body
.as_ref()
.map(|b| {
let body = String::from_utf8_lossy(b);
body.contains("activateRelease")
&& body.contains("app-123")
&& body.contains("rel-456")
})
.unwrap_or(false)
.is_true(|req| {
let body = req.body_string();
body.contains("activateRelease")
&& body.contains("app-123")
&& body.contains("rel-456")
});
then.status(200).json_body(json!({
"data": { "activateRelease": { "id": "rel-456", "status": "ACTIVE" } }
Expand Down Expand Up @@ -476,15 +471,9 @@ mod tests {
.mock_async(|when, then| {
when.method(POST)
.path("/v1/apps/app-registry-subgraph")
.matches(|req| {
req.body
.as_ref()
.map(|b| {
let body = String::from_utf8_lossy(b);
body.contains("updateApplication")
&& body.contains(r#""status":"ACTIVE""#)
})
.unwrap_or(false)
.is_true(|req| {
let body = req.body_string();
body.contains("updateApplication") && body.contains(r#""status":"ACTIVE""#)
});
then.status(200).json_body(json!({
"data": { "updateApplication": { "id": "app-1", "status": "ACTIVE" } }
Expand Down Expand Up @@ -533,7 +522,7 @@ mod tests {
matches!(err, ClientError::TooLarge { .. }),
"unexpected: {err}"
);
assert_eq!(mock.hits_async().await, 0);
assert_eq!(mock.calls_async().await, 0);
}

#[tokio::test]
Expand Down Expand Up @@ -565,7 +554,7 @@ mod tests {
matches!(err, ClientError::Http { status: 403, .. }),
"unexpected: {err}"
);
assert_eq!(mock.hits_async().await, 1);
assert_eq!(mock.calls_async().await, 1);
}

#[tokio::test]
Expand Down Expand Up @@ -597,7 +586,7 @@ mod tests {
matches!(err, ClientError::Http { status: 503, .. }),
"unexpected: {err}"
);
assert_eq!(mock.hits_async().await, 3);
assert_eq!(mock.calls_async().await, 3);
}

#[tokio::test]
Expand All @@ -609,10 +598,9 @@ mod tests {
.path("/upload")
.header("x-amz-signature", "sig")
// assert x-amz-meta-upload-id was stripped
.matches(|req| {
!req.headers
.is_true(|req| {
!req.headers_vec()
.iter()
.flatten()
.any(|(k, _)| k.eq_ignore_ascii_case("x-amz-meta-upload-id"))
});
then.status(200).header("etag", "\"abc123\"");
Expand Down Expand Up @@ -673,7 +661,7 @@ mod tests {
matches!(err, ClientError::InvalidHeader(_)),
"unexpected: {err}"
);
assert_eq!(mock.hits_async().await, 0);
assert_eq!(mock.calls_async().await, 0);
}

#[tokio::test]
Expand Down Expand Up @@ -710,6 +698,6 @@ mod tests {
.expect("upload shared payload");
}

mock.assert_hits_async(2).await;
mock.assert_calls_async(2).await;
}
}
27 changes: 21 additions & 6 deletions rust/src/application/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cli_engine::{
CommandResult, CommandSpec, GroupSpec, NextAction, NextActionParam, RuntimeCommandSpec,
RuntimeGroupSpec, StreamSender, TableColumn, Tier,
CommandResult, CommandSpec, GroupSpec, NextAction, NextActionParam, PaginationConfig,
RuntimeCommandSpec, RuntimeGroupSpec, StreamSender, TableColumn, Tier,
};
use serde_json::{Value, json};

Expand Down Expand Up @@ -251,7 +251,11 @@ fn list_command() -> RuntimeCommandSpec {
.with_system("applications")
.with_tier(Tier::Read)
.with_default_fields("name,label,status")
.with_output_schema::<ApplicationSummary>(),
.with_output_schema::<ApplicationSummary>()
.with_pagination(PaginationConfig {
max_limit: 200,
..Default::default()
}),
|ctx| async move {
let client = make_client(&ctx).await?;
let data = client.list_applications().await.map_err(client_err)?;
Expand Down Expand Up @@ -1846,12 +1850,12 @@ pub fn add_extension_group() -> RuntimeGroupSpec {

#[cfg(test)]
mod tests {
use cli_engine::{Cli, CliConfig, Stage};
use cli_engine::{Cli, CliConfig, PaginationConfig, Stage};
use serde_json::json;

use super::{
add_config_next_actions, deploy_next_actions, init_view_columns, update_command,
validate_command, validate_remote_application,
add_config_next_actions, deploy_next_actions, init_view_columns, list_command,
update_command, validate_command, validate_remote_application,
};

#[test]
Expand All @@ -1860,6 +1864,17 @@ mod tests {
assert_eq!(deploy_next_actions("app").len(), 3);
}

#[test]
fn list_command_opts_into_pagination_with_no_default_and_a_max_limit() {
assert_eq!(
list_command().spec.pagination,
Some(PaginationConfig {
max_limit: 200,
..Default::default()
})
);
}

#[test]
fn add_config_next_actions_skips_empty_name_prefill() {
let actions = add_config_next_actions("");
Expand Down
27 changes: 25 additions & 2 deletions rust/src/dns/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! `dns list` — list DNS records for a domain, with optional type/name filters.

use cli_engine::{CliCoreError, CommandResult, CommandSpec, RuntimeCommandSpec, Tier};
use cli_engine::{
CliCoreError, CommandResult, CommandSpec, PaginationConfig, RuntimeCommandSpec, Tier,
};
use serde_json::{Value, json};

use crate::domain::make_client;
Expand Down Expand Up @@ -38,7 +40,11 @@ pub(super) fn command() -> RuntimeCommandSpec {
.with_tier(Tier::Read)
.with_default_fields("type,name,data,ttl")
.with_json_schema::<types::DnsRecord>()
.with_scopes(&[DOMAINS_READ]),
.with_scopes(&[DOMAINS_READ])
.with_pagination(PaginationConfig {
max_limit: 500,
..Default::default()
}),
|ctx, args: ListArgs| async move {
let domain = args.domain;
let type_opt = args.record_type;
Expand Down Expand Up @@ -66,3 +72,20 @@ pub(super) fn command() -> RuntimeCommandSpec {
},
)
}

#[cfg(test)]
mod tests {
use super::command;
use cli_engine::PaginationConfig;

#[test]
fn opts_into_pagination_with_no_default_and_a_max_limit() {
assert_eq!(
command().spec.pagination,
Some(PaginationConfig {
max_limit: 500,
..Default::default()
})
);
}
}
6 changes: 3 additions & 3 deletions rust/src/dns/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,12 +1002,12 @@ mod tests {
.await;

assert_eq!(
create.hits_async().await,
create.calls_async().await,
0,
"no create for a no-op replace"
);
assert_eq!(
delete.hits_async().await,
delete.calls_async().await,
0,
"no delete for a no-op replace"
);
Expand Down Expand Up @@ -1047,7 +1047,7 @@ mod tests {
.await;

assert_eq!(
delete.hits_async().await,
delete.calls_async().await,
0,
"the old record must not be touched when the create fails"
);
Expand Down
30 changes: 25 additions & 5 deletions rust/src/domain/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! `gddy domain list` — list the domains in the account (v1).

use cli_engine::{
CliCoreError, CommandResult, CommandSpec, NextActionParam, Result, RuntimeCommandSpec, Tier,
CliCoreError, CommandResult, CommandSpec, NextActionParam, PaginationConfig, Result,
RuntimeCommandSpec, Tier,
};
use serde_json::json;

Expand Down Expand Up @@ -48,14 +49,17 @@ pub(super) fn command() -> RuntimeCommandSpec {
"List the domains registered to your account. Shows domain, status, \
expiry, and auto-renew by default; use --fields to pick columns. Hides \
domains that are cancelled or otherwise not visible unless --show-hidden \
is passed; use --status to filter to specific status values (repeatable, \
overrides the default filter).",
is passed; use --status to filter to specific status values (repeatable).",
)
.with_system("domain")
.with_tier(Tier::Read)
.with_default_fields("domain,status,expires,renewAuto")
.with_json_schema::<types::V1DomainSummary>()
.with_scopes(&[DOMAINS_READ]),
.with_scopes(&[DOMAINS_READ])
.with_pagination(PaginationConfig {
max_limit: 500,
..Default::default()
}),
|ctx, args: ListArgs| async move {
let debug = !ctx.middleware.debug.is_empty();
let statuses = parse_statuses(&args.status)?;
Expand Down Expand Up @@ -89,9 +93,25 @@ pub(super) fn command() -> RuntimeCommandSpec {

#[cfg(test)]
mod tests {
use super::{parse_statuses, wants_visible_only};
use super::{command, parse_statuses, wants_visible_only};
use cli_engine::PaginationConfig;
use domains_client::types;

/// Regression pin: `domain list` opts into pagination with no forced
/// `default_limit` (an unflagged invocation must keep returning every
/// domain, exactly like before this feature existed) but a `max_limit`
/// so `--limit` can't be pointed at an absurd value.
#[test]
fn opts_into_pagination_with_no_default_and_a_max_limit() {
assert_eq!(
command().spec.pagination,
Some(PaginationConfig {
max_limit: 500,
..Default::default()
})
);
}

#[test]
fn parse_statuses_is_case_insensitive_and_validates() {
use types::ListStatusesItem;
Expand Down
7 changes: 1 addition & 6 deletions rust/src/hosting/nodejs/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ mod tests {
.mock_async(|when, then| {
when.method(POST)
.path("/v1/hosting/nodejs/apps/app-1/source")
.matches(|req| {
req.body
.as_ref()
.map(|b| String::from_utf8_lossy(b).contains("zipFile"))
.unwrap_or(false)
});
.is_true(|req| req.body_string().contains("zipFile"));
then.status(200).json_body(json!({ "jobId": "upload-1" }));
})
.await;
Expand Down
6 changes: 3 additions & 3 deletions rust/src/onboarding/ensure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
);
assert!(stderr.is_empty());
status.assert_async().await;
assert_eq!(complete.hits_async().await, 0);
assert_eq!(complete.calls_async().await, 0);
}

#[tokio::test]
Expand Down Expand Up @@ -262,7 +262,7 @@ mod tests {
.expect_err("agreements required");

assert!(err.to_string().contains("agreements must be accepted"));
assert_eq!(complete.hits_async().await, 0);
assert_eq!(complete.calls_async().await, 0);
}

#[tokio::test]
Expand Down Expand Up @@ -376,6 +376,6 @@ mod tests {
.expect_err("prompt I/O error must be reported");

assert!(err.to_string().contains("writer unavailable"));
assert_eq!(complete.hits_async().await, 0);
assert_eq!(complete.calls_async().await, 0);
}
}