#![allow(deprecated)]
use std::collections::BTreeSet;
use std::future::Future;
use std::pin::Pin;
use std::time::Duration;
use base64::Engine as _;
use base64::engine::general_purpose::{GeneralPurpose, STANDARD, STANDARD_NO_PAD};
use buffa::Message as _;
use pethost::{Client, Error, ErrorCode, ErrorDetail, ResponseStream, Timestamp, types};
use serde::Serialize;
use serde::de::DeserializeOwned;
use serde_json::Value;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::{TcpListener, TcpStream};
#[path = "../src/wire/buffa/mod.rs"]
#[rustfmt::skip]
#[allow(clippy::all, dead_code, unreachable_pub)]
mod proto;
use proto::pethost::panel::v1 as wire;
const TOKEN: &str = "pth_checks";
const HEADERS: [(&str, &str); 3] = [
("authorization", "Bearer pth_checks"),
("user-agent", "pethost-rust/0.2.5"),
("connect-protocol-version", "1"),
];
const MESSAGE: &str = "the fake's sentence";
const SOON: Duration = Duration::from_secs(10);
const STREAMS: [&str; 3] = ["WatchOperation", "TailContainerLogs", "TailHttpTraffic"];
struct Answer {
status: u16,
content_type: &'static str,
body: Vec<u8>,
open: bool,
}
fn ok(response: &impl buffa::Message) -> Answer {
Answer {
status: 200,
content_type: "application/proto",
body: response.encode_to_vec(),
open: false,
}
}
fn error(code: &str, details: &[(&str, &[u8])], encode: &GeneralPurpose) -> Value {
let details: Vec<Value> = details
.iter()
.map(|(name, bytes)| serde_json::json!({ "type": name, "value": encode.encode(bytes) }))
.collect();
serde_json::json!({ "code": code, "message": MESSAGE, "details": details })
}
fn failure(code: &str, status: u16, details: &[(&str, &[u8])], encode: &GeneralPurpose) -> Answer {
Answer {
status,
content_type: "application/json",
body: error(code, details, encode).to_string().into_bytes(),
open: false,
}
}
enum End {
Clean,
Failed(Value),
Open,
}
const END_STREAM: u8 = 0b10;
fn streamed<Response: buffa::Message>(responses: &[Response], end: End) -> Answer {
let last = match end {
End::Clean => Some(serde_json::json!({})),
End::Failed(error) => Some(serde_json::json!({ "error": error })),
End::Open => None,
};
let mut body: Vec<u8> = responses
.iter()
.flat_map(|response| envelope(0, &response.encode_to_vec()))
.collect();
if let Some(last) = &last {
body.extend(envelope(END_STREAM, last.to_string().as_bytes()));
}
Answer {
status: 200,
content_type: "application/connect+proto",
body,
open: last.is_none(),
}
}
fn envelope(flags: u8, message: &[u8]) -> Vec<u8> {
let mut bytes = vec![flags];
bytes.extend_from_slice(&(message.len() as u32).to_be_bytes());
bytes.extend_from_slice(message);
bytes
}
fn unwrapped(body: &[u8]) -> &[u8] {
let (head, message) = body.split_at(5);
let length = u32::from_be_bytes(head[1..].try_into().unwrap());
assert_eq!(head[0], 0, "the request's envelope has flags");
assert_eq!(
length as usize,
message.len(),
"the request's envelope says another length"
);
message
}
struct Taken {
line: String,
headers: http::HeaderMap,
body: Vec<u8>,
socket: TcpStream,
}
async fn take(listener: TcpListener) -> Taken {
let (mut socket, _) = listener.accept().await.unwrap();
let mut bytes = Vec::new();
let end = loop {
if let Some(end) = bytes.windows(4).position(|window| window == b"\r\n\r\n") {
break end;
}
more(&mut socket, &mut bytes).await;
};
let mut body = bytes.split_off(end + 4);
let head = String::from_utf8(bytes).unwrap();
let mut lines = head.trim_end().split("\r\n");
let line = lines.next().unwrap().to_owned();
let headers: http::HeaderMap = lines.map(header).collect();
let length: usize = headers
.get("content-length")
.map_or(0, |length| length.to_str().unwrap().parse().unwrap());
while body.len() < length {
more(&mut socket, &mut body).await;
}
assert_eq!(body.len(), length, "the client sent more than its request");
Taken {
line,
headers,
body,
socket,
}
}
fn header(line: &str) -> (http::HeaderName, http::HeaderValue) {
let (name, value) = line.split_once(':').expect("a header's line has no colon");
(name.parse().unwrap(), value.trim().parse().unwrap())
}
async fn more(socket: &mut TcpStream, bytes: &mut Vec<u8>) {
let read = socket.read_buf(bytes).await.unwrap();
assert!(read > 0, "the client closed the connection inside a request");
}
impl Taken {
async fn answer(mut self, answer: Answer) -> Self {
let length = if answer.open {
String::new()
} else {
format!("content-length: {}\r\n", answer.body.len())
};
let head = format!(
"HTTP/1.1 {} Fake\r\ncontent-type: {}\r\n{length}connection: close\r\n\r\n",
answer.status, answer.content_type
);
self.socket.write_all(head.as_bytes()).await.unwrap();
self.socket.write_all(&answer.body).await.unwrap();
if answer.open {
left(&mut self.socket).await;
}
self
}
async fn unanswered(mut self) {
left(&mut self.socket).await;
}
}
async fn left(socket: &mut TcpStream) {
let mut more = [0; 1];
let read = socket.read(&mut more).await;
assert!(!matches!(read, Ok(1..)), "the caller said more after its request");
}
async fn exchange<Request, Call>(
rpc: &str,
answer: Answer,
call: impl FnOnce(Client) -> Call,
) -> (Request, Call::Output)
where
Request: buffa::Message,
Call: Future,
{
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let address = listener.local_addr().unwrap();
let client = Client::with_base_url(&format!("{TOKEN}\n"), &format!("http://{address}")).unwrap();
let fake = tokio::spawn(async move { take(listener).await.answer(answer).await });
let response = call(client.clone()).await;
let taken = tokio::time::timeout(SOON, fake)
.await
.expect("the client made no call, or did not leave the one the fake kept open")
.unwrap();
let (content_type, message) = if STREAMS.contains(&rpc) {
("application/connect+proto", unwrapped(&taken.body))
} else {
("application/proto", taken.body.as_slice())
};
assert_eq!(
taken.line,
format!("POST /pethost.panel.v1.PanelService/{rpc} HTTP/1.1")
);
for (name, value) in HEADERS.into_iter().chain([("content-type", content_type)]) {
let said = taken.headers.get(name).map(|said| said.to_str().unwrap());
assert_eq!(said, Some(value), "{name}");
}
(Request::decode_from_slice(message).unwrap(), response)
}
#[allow(dead_code)]
mod states {
use pethost::Timestamp;
const FLAG_BITS: usize = 2;
pub fn text(name: &str, k: usize) -> String {
format!("{name} {k}")
}
pub fn number(field: u32, k: usize) -> u32 {
field * 1000 + k as u32 + 1
}
pub fn flag(ordinal: usize, k: usize) -> bool {
(ordinal >> (k % FLAG_BITS)) & 1 == 1
}
pub fn plain<T: Default>(k: usize, value: T) -> T {
if k % 2 == 1 { value } else { T::default() }
}
pub fn marked<T: Default>(k: usize, value: T) -> Option<T> {
match k % 3 {
0 => None,
1 => Some(T::default()),
_ => Some(value),
}
}
pub fn maybe<T>(k: usize, value: T) -> Option<T> {
(k % 2 == 1).then_some(value)
}
pub fn many<T>(k: usize, items: [T; 2]) -> Vec<T> {
if k % 2 == 1 { items.into() } else { Vec::new() }
}
pub fn time(number: u32) -> Timestamp {
Timestamp {
seconds: 1_700_000_000 + i64::from(number),
nanos: number,
}
}
pub fn time_on_wire(number: u32) -> buffa_types::google::protobuf::Timestamp {
buffa_types::google::protobuf::Timestamp {
seconds: 1_700_000_000 + i64::from(number),
nanos: number as i32,
..Default::default()
}
}
pub fn present<T: Default + PartialEq>(value: T) -> Option<T> {
(value != T::default()).then_some(value)
}
pub fn set<E: buffa::Enumeration>(value: buffa::EnumValue<E>) -> Option<buffa::EnumValue<E>> {
(value.to_i32() != 0).then_some(value)
}
pub fn make<T: Default>(fill: impl FnOnce(&mut T)) -> T {
let mut message = T::default();
fill(&mut message);
message
}
pub fn later_field() -> buffa::UnknownField {
buffa::UnknownField {
number: 29,
data: buffa::UnknownFieldData::LengthDelimited(b"later".to_vec()),
}
}
}
#[allow(unused_variables)]
mod samples {
use super::*;
pub fn alert_channel_kind(k: usize) -> types::AlertChannelKind {
match k % 5 {
0 => types::AlertChannelKind::Unspecified,
1 => types::AlertChannelKind::Email,
2 => types::AlertChannelKind::Telegram,
3 => types::AlertChannelKind::Slack,
_ => types::AlertChannelKind::Unrecognized(4),
}
}
pub fn machine_session_kind(k: usize) -> types::MachineSessionKind {
match k % 7 {
0 => types::MachineSessionKind::Unspecified,
1 => types::MachineSessionKind::WebTerminal,
2 => types::MachineSessionKind::SshTerminal,
3 => types::MachineSessionKind::SshCommand,
4 => types::MachineSessionKind::Sftp,
5 => types::MachineSessionKind::Tunnel,
_ => types::MachineSessionKind::Unrecognized(6),
}
}
pub fn project_problem_kind(k: usize) -> types::ProjectProblemKind {
match k % 15 {
0 => types::ProjectProblemKind::Unspecified,
1 => types::ProjectProblemKind::DeployFailed,
2 => types::ProjectProblemKind::ServiceUnhealthy,
3 => types::ProjectProblemKind::ServiceRestarting,
4 => types::ProjectProblemKind::ServiceOutOfMemory,
5 => types::ProjectProblemKind::BackupFailed,
6 => types::ProjectProblemKind::DeployCancelled,
7 => types::ProjectProblemKind::ServiceExited,
8 => types::ProjectProblemKind::RestoreFailed,
9 => types::ProjectProblemKind::AutoDeployRefused,
10 => types::ProjectProblemKind::ServicePortClosed,
11 => types::ProjectProblemKind::SiteDown,
12 => types::ProjectProblemKind::HttpErrors,
13 => types::ProjectProblemKind::HttpSlow,
_ => types::ProjectProblemKind::Unrecognized(14),
}
}
pub fn services_action_kind(k: usize) -> types::ServicesActionKind {
match k % 5 {
0 => types::ServicesActionKind::Unspecified,
1 => types::ServicesActionKind::Start,
2 => types::ServicesActionKind::Stop,
3 => types::ServicesActionKind::Restart,
_ => types::ServicesActionKind::Unrecognized(4),
}
}
pub fn service_state(k: usize) -> types::ServiceState {
match k % 10 {
0 => types::ServiceState::Unspecified,
1 => types::ServiceState::NotCreated,
2 => types::ServiceState::Starting,
3 => types::ServiceState::Running,
4 => types::ServiceState::Healthy,
5 => types::ServiceState::Unhealthy,
6 => types::ServiceState::Restarting,
7 => types::ServiceState::Stopped,
8 => types::ServiceState::Exited,
_ => types::ServiceState::Unrecognized(9),
}
}
pub fn restart_policy(k: usize) -> types::RestartPolicy {
match k % 6 {
0 => types::RestartPolicy::Unspecified,
1 => types::RestartPolicy::No,
2 => types::RestartPolicy::OnFailure,
3 => types::RestartPolicy::UnlessStopped,
4 => types::RestartPolicy::Always,
_ => types::RestartPolicy::Unrecognized(5),
}
}
pub fn health_status(k: usize) -> types::HealthStatus {
match k % 5 {
0 => types::HealthStatus::Unspecified,
1 => types::HealthStatus::Starting,
2 => types::HealthStatus::Healthy,
3 => types::HealthStatus::Unhealthy,
_ => types::HealthStatus::Unrecognized(4),
}
}
pub fn certificate_source(k: usize) -> types::CertificateSource {
match k % 5 {
0 => types::CertificateSource::Unspecified,
1 => types::CertificateSource::None,
2 => types::CertificateSource::Installed,
3 => types::CertificateSource::Automatic,
_ => types::CertificateSource::Unrecognized(4),
}
}
pub fn operation_kind(k: usize) -> types::OperationKind {
match k % 7 {
0 => types::OperationKind::Unspecified,
1 => types::OperationKind::Deploy,
2 => types::OperationKind::RecreateService,
3 => types::OperationKind::Backup,
4 => types::OperationKind::Restore,
5 => types::OperationKind::Delete,
_ => types::OperationKind::Unrecognized(6),
}
}
pub fn operation_status(k: usize) -> types::OperationStatus {
match k % 6 {
0 => types::OperationStatus::Unspecified,
1 => types::OperationStatus::InProgress,
2 => types::OperationStatus::Succeeded,
3 => types::OperationStatus::Failed,
4 => types::OperationStatus::Cancelled,
_ => types::OperationStatus::Unrecognized(5),
}
}
pub fn deploy_failure_reason(k: usize) -> types::DeployFailureReason {
match k % 13 {
0 => types::DeployFailureReason::Unspecified,
1 => types::DeployFailureReason::ImagePullFailed,
2 => types::DeployFailureReason::ImageBuildFailed,
3 => types::DeployFailureReason::ContainerStartFailed,
4 => types::DeployFailureReason::DiskFull,
5 => types::DeployFailureReason::Internal,
6 => types::DeployFailureReason::PortUnavailable,
7 => types::DeployFailureReason::ContainerExited,
8 => types::DeployFailureReason::ContainerUnhealthy,
9 => types::DeployFailureReason::TimedOut,
10 => types::DeployFailureReason::UncoveredImageVolume,
11 => types::DeployFailureReason::BuildMemoryUnavailable,
_ => types::DeployFailureReason::Unrecognized(12),
}
}
pub fn traffic_metric(k: usize) -> types::TrafficMetric {
match k % 5 {
0 => types::TrafficMetric::Unspecified,
1 => types::TrafficMetric::ServerErrors,
2 => types::TrafficMetric::ServerErrorPercent,
3 => types::TrafficMetric::LatencyP95Ms,
_ => types::TrafficMetric::Unrecognized(4),
}
}
pub fn alert_status(k: usize) -> types::AlertStatus {
match k % 7 {
0 => types::AlertStatus::Unspecified,
1 => types::AlertStatus::Ok,
2 => types::AlertStatus::Pending,
3 => types::AlertStatus::Firing,
4 => types::AlertStatus::Paused,
5 => types::AlertStatus::NoData,
_ => types::AlertStatus::Unrecognized(6),
}
}
pub fn incident_quiet_reason(k: usize) -> types::IncidentQuietReason {
match k % 6 {
0 => types::IncidentQuietReason::Unspecified,
1 => types::IncidentQuietReason::Muted,
2 => types::IncidentQuietReason::Off,
3 => types::IncidentQuietReason::FirstEvaluation,
4 => types::IncidentQuietReason::ManualDeploy,
_ => types::IncidentQuietReason::Unrecognized(5),
}
}
pub fn output_stream(k: usize) -> types::OutputStream {
match k % 4 {
0 => types::OutputStream::Unspecified,
1 => types::OutputStream::Stdout,
2 => types::OutputStream::Stderr,
_ => types::OutputStream::Unrecognized(3),
}
}
pub fn file_type(k: usize) -> types::FileType {
match k % 6 {
0 => types::FileType::Unspecified,
1 => types::FileType::File,
2 => types::FileType::Directory,
3 => types::FileType::Symlink,
4 => types::FileType::Other,
_ => types::FileType::Unrecognized(5),
}
}
pub fn file_location(k: usize) -> types::FileLocation {
match k % 5 {
0 => types::FileLocation::Unspecified,
1 => types::FileLocation::Container,
2 => types::FileLocation::Volume,
3 => types::FileLocation::ProjectFiles,
_ => types::FileLocation::Unrecognized(4),
}
}
pub fn no_machine_reason(k: usize) -> types::NoMachineReason {
match k % 4 {
0 => types::NoMachineReason::Unspecified,
1 => types::NoMachineReason::NoPlan,
2 => types::NoMachineReason::BeingPrepared,
_ => types::NoMachineReason::Unrecognized(3),
}
}
pub fn get_machine_request(_k: usize, later: bool) -> types::GetMachineRequest {
types::GetMachineRequest {}
}
pub fn get_machine_response(k: usize, later: bool) -> types::GetMachineResponse {
states::make(|message: &mut types::GetMachineResponse| {
message.machine = states::maybe(k, samples::machine(k, later));
message.projects = states::many(
k,
[
samples::project_summary(k + 1, later),
samples::project_summary(k + 2, later),
],
);
message.deleted_projects = states::many(
k,
[
samples::deleted_project(k + 2, later),
samples::deleted_project(k + 3, later),
],
);
message.github = states::maybe(k, samples::github_connection(k + 3, later));
})
}
pub fn machine(k: usize, later: bool) -> types::Machine {
states::make(|message: &mut types::Machine| {
message.name = states::plain(k, states::text("name", k));
message.location = states::plain(k, states::text("location", k));
message.sample_time = states::maybe(k, states::time(states::number(3, k + 2)));
message.cpu_used_cores = states::plain(k, f64::from(states::number(5, k)) + 0.5);
message.cpu_total_cores = states::plain(k, f64::from(states::number(6, k)) + 0.5);
message.memory_used_bytes = states::plain(k, u64::from(states::number(7, k)) << 44);
message.memory_total_bytes = states::plain(k, u64::from(states::number(8, k)) << 44);
message.disk_used_bytes = states::plain(k, u64::from(states::number(9, k)) << 44);
message.disk_total_bytes = states::plain(k, u64::from(states::number(10, k)) << 44);
message.disk_usage = states::maybe(k, samples::disk_usage(k + 9, later));
message.hostname = states::plain(k, states::text("hostname", k));
message.ssh_host_key_fingerprint = states::plain(k, states::text("ssh_host_key_fingerprint", k));
message.ssh_keys = states::many(k, [samples::ssh_key(k + 12, later), samples::ssh_key(k + 13, later)]);
message.backups_enabled = states::flag(1, k);
message.snapshot_list_time = states::maybe(k, states::time(states::number(22, k + 14)));
message.snapshot_list_failure_message = states::plain(k, states::text("snapshot_list_failure_message", k));
message.backup_retention_hours = states::plain(k, states::number(4, k));
message.acme_enabled = states::flag(2, k);
message.apps_domain = states::plain(k, states::text("apps_domain", k));
message.daemon_version = states::plain(k, states::text("daemon_version", k));
message.docker_version = states::plain(k, states::text("docker_version", k));
message.boot_time = states::maybe(k, states::time(states::number(18, k + 21)));
message.restart_required_time = states::maybe(k, states::time(states::number(19, k + 22)));
message.scheduled_restart_time = states::maybe(k, states::time(states::number(20, k + 23)));
message.sessions = states::many(
k,
[
samples::machine_session(k + 24, later),
samples::machine_session(k + 25, later),
],
);
message.alert_channels = states::many(
k,
[
samples::alert_destination(k + 25, later),
samples::alert_destination(k + 26, later),
],
);
})
}
pub fn alert_destination(k: usize, later: bool) -> types::AlertDestination {
states::make(|message: &mut types::AlertDestination| {
message.kind = samples::alert_channel_kind(k);
message.label = states::plain(k, states::text("label", k));
})
}
pub fn machine_session(k: usize, later: bool) -> types::MachineSession {
states::make(|message: &mut types::MachineSession| {
message.session_id = states::plain(k, states::text("session_id", k));
message.kind = samples::machine_session_kind(k + 1);
message.project_id = states::plain(k, states::text("project_id", k));
message.service = states::plain(k, states::text("service", k));
message.port = states::plain(k, states::number(5, k));
message.start_time = states::maybe(k, states::time(states::number(6, k + 5)));
message.client_address = states::plain(k, states::text("client_address", k));
message.ssh_key_label = states::plain(k, states::text("ssh_key_label", k));
message.ssh_key_fingerprint = states::plain(k, states::text("ssh_key_fingerprint", k));
})
}
pub fn disk_usage(k: usize, later: bool) -> types::DiskUsage {
states::make(|message: &mut types::DiskUsage| {
message.images_bytes = states::plain(k, u64::from(states::number(1, k)) << 44);
message.build_cache_bytes = states::marked(k, u64::from(states::number(2, k)) << 44);
message.volumes_bytes = states::plain(k, u64::from(states::number(3, k)) << 44);
message.container_layers_bytes = states::plain(k, u64::from(states::number(4, k)) << 44);
message.project_files_bytes = states::plain(k, u64::from(states::number(5, k)) << 44);
message.container_logs_bytes = states::plain(k, u64::from(states::number(6, k)) << 44);
message.http_traffic_bytes = states::plain(k, u64::from(states::number(7, k)) << 44);
})
}
pub fn ssh_key(k: usize, later: bool) -> types::SshKey {
types::SshKey {
public_key: states::plain(k, states::text("public_key", k)),
label: states::plain(k, states::text("label", k)),
fingerprint: states::plain(k, states::text("fingerprint", k)),
}
}
pub fn github_connection(k: usize, later: bool) -> types::GithubConnection {
states::make(|message: &mut types::GithubConnection| {
message.app_name = states::plain(k, states::text("app_name", k));
message.install_url = states::plain(k, states::text("install_url", k));
message.repositories = states::many(
k,
[
samples::github_repository(k + 2, later),
samples::github_repository(k + 3, later),
],
);
message.repository_count = states::plain(k, states::number(4, k));
message.webhooks_enabled = states::flag(1, k);
})
}
pub fn github_repository(k: usize, later: bool) -> types::GithubRepository {
states::make(|message: &mut types::GithubRepository| {
message.repository = states::plain(k, states::text("repository", k));
message.default_branch = states::plain(k, states::text("default_branch", k));
message.private = states::flag(1, k);
message.push_time = states::maybe(k, states::time(states::number(4, k + 3)));
})
}
pub fn deleted_project(k: usize, later: bool) -> types::DeletedProject {
states::make(|message: &mut types::DeletedProject| {
message.project_id = states::plain(k, states::text("project_id", k));
message.newest_snapshot = states::maybe(k, samples::snapshot(k + 1, later));
message.snapshot_count = states::plain(k, states::number(3, k));
})
}
pub fn run_machine_action_request(k: usize, later: bool) -> types::RunMachineActionRequest {
types::RunMachineActionRequest {
action: match k % 12 {
0 => None,
1 => None,
2 => Some(types::RunMachineActionRequestAction::AddSshKey(samples::ssh_key(
k, later,
))),
3 => Some(types::RunMachineActionRequestAction::RemoveSshKeyFingerprint(
states::text("remove_ssh_key_fingerprint", k),
)),
4 => Some(types::RunMachineActionRequestAction::RestartMachine(
samples::restart_machine_action(k, later),
)),
5 => Some(types::RunMachineActionRequestAction::CancelRestart(true)),
6 => Some(types::RunMachineActionRequestAction::EndSessionId(states::text(
"end_session_id",
k,
))),
7 => Some(types::RunMachineActionRequestAction::AddSshKey(Default::default())),
8 => Some(types::RunMachineActionRequestAction::RemoveSshKeyFingerprint(
Default::default(),
)),
9 => Some(types::RunMachineActionRequestAction::RestartMachine(Default::default())),
10 => Some(types::RunMachineActionRequestAction::CancelRestart(Default::default())),
_ => Some(types::RunMachineActionRequestAction::EndSessionId(Default::default())),
},
}
}
pub fn restart_machine_action(k: usize, later: bool) -> types::RestartMachineAction {
types::RestartMachineAction {
restart_time: states::maybe(k, states::time(states::number(1, k))),
at_maintenance_window: states::flag(1, k),
interrupt_operations: states::flag(2, k),
}
}
pub fn run_machine_action_response(k: usize, later: bool) -> types::RunMachineActionResponse {
states::make(|message: &mut types::RunMachineActionResponse| {
message.machine = states::maybe(k, samples::machine(k, later));
})
}
pub fn project_metadata(k: usize, later: bool) -> types::ProjectMetadata {
types::ProjectMetadata {
name: states::marked(k, states::text("name", k)),
emoji: states::marked(k, states::text("emoji", k)),
description: states::marked(k, states::text("description", k)),
notes: states::marked(k, states::text("notes", k)),
}
}
pub fn project_summary(k: usize, later: bool) -> types::ProjectSummary {
states::make(|message: &mut types::ProjectSummary| {
message.project_id = states::plain(k, states::text("project_id", k));
message.metadata = states::maybe(k, samples::project_metadata(k + 1, later));
message.problems = states::many(
k,
[
samples::project_problem(k + 2, later),
samples::project_problem(k + 3, later),
],
);
message.services = states::many(
k,
[
samples::service_summary(k + 3, later),
samples::service_summary(k + 4, later),
],
);
message.url = states::plain(k, states::text("url", k));
message.hosts = states::many(k, [states::text("hosts", k), states::text("hosts", k + 1)]);
message.http_traffic_last_day = states::maybe(k, samples::http_traffic_summary(k + 6, later));
message.cpu_used_cores = states::plain(k, f64::from(states::number(8, k)) + 0.5);
message.memory_used_bytes = states::plain(k, u64::from(states::number(9, k)) << 44);
message.deploy_time = states::maybe(k, states::time(states::number(10, k + 9)));
message.running_operations = states::many(
k,
[samples::operation(k + 10, later), samples::operation(k + 11, later)],
);
message.pinned = states::flag(1, k);
message.disk_used_bytes = states::plain(k, u64::from(states::number(13, k)) << 44);
})
}
pub fn service_summary(k: usize, later: bool) -> types::ServiceSummary {
states::make(|message: &mut types::ServiceSummary| {
message.service = states::plain(k, states::text("service", k));
message.state = samples::service_state(k + 1);
})
}
pub fn project_problem(k: usize, later: bool) -> types::ProjectProblem {
states::make(|message: &mut types::ProjectProblem| {
message.kind = samples::project_problem_kind(k);
message.service = states::plain(k, states::text("service", k));
message.operation_id = states::plain(k, states::text("operation_id", k));
message.since_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.problem_message = states::plain(k, states::text("problem_message", k));
message.incident_id = states::plain(k, states::text("incident_id", k));
})
}
pub fn get_project_request(k: usize, later: bool) -> types::GetProjectRequest {
types::GetProjectRequest {
project_id: states::plain(k, states::text("project_id", k)),
include_secret_values: states::flag(1, k),
snapshots_before: states::maybe(k, states::time(states::number(3, k + 2))),
snapshots_volume: states::plain(k, states::text("snapshots_volume", k)),
incidents_before: states::maybe(k, states::time(states::number(5, k + 4))),
uptime_day_count: states::plain(k, states::number(6, k)),
incidents_before_id: states::plain(k, states::text("incidents_before_id", k)),
}
}
pub fn get_project_response(k: usize, later: bool) -> types::GetProjectResponse {
states::make(|message: &mut types::GetProjectResponse| {
message.project = states::maybe(k, samples::project(k, later));
})
}
pub fn project(k: usize, later: bool) -> types::Project {
states::make(|message: &mut types::Project| {
message.project_id = states::plain(k, states::text("project_id", k));
message.metadata = states::maybe(k, samples::project_metadata(k + 1, later));
message.problems = states::many(
k,
[
samples::project_problem(k + 2, later),
samples::project_problem(k + 3, later),
],
);
message.url = states::plain(k, states::text("url", k));
message.cpu_used_cores = states::plain(k, f64::from(states::number(5, k)) + 0.5);
message.memory_used_bytes = states::plain(k, u64::from(states::number(6, k)) << 44);
message.deploy_id = states::plain(k, states::text("deploy_id", k));
message.deploy_status = samples::operation_status(k + 7);
message.deploy_time = states::maybe(k, states::time(states::number(8, k + 8)));
message.x_pethost_applies_at_once = states::flag(1, k);
message.services = states::many(k, [samples::service(k + 10, later), samples::service(k + 11, later)]);
message.volumes = states::many(k, [samples::volume(k + 11, later), samples::volume(k + 12, later)]);
message.routes = states::many(k, [samples::route(k + 12, later), samples::route(k + 13, later)]);
message.hosts = states::many(k, [samples::host(k + 13, later), samples::host(k + 14, later)]);
message.password_protected = states::flag(2, k);
message.operations = states::many(
k,
[samples::operation(k + 15, later), samples::operation(k + 16, later)],
);
message.snapshots = states::many(k, [samples::snapshot(k + 16, later), samples::snapshot(k + 17, later)]);
message.snapshot_count = states::plain(k, states::number(15, k));
message.snapshot_list_time = states::maybe(k, states::time(states::number(20, k + 18)));
message.http_traffic_last_day = states::maybe(k, samples::http_traffic_summary(k + 19, later));
message.source = states::maybe(k, samples::project_source(k + 20, later));
message.running_services_action = states::maybe(k, samples::running_services_action(k + 21, later));
message.alerts = states::maybe(k, samples::project_alerts(k + 22, later));
message.incidents = states::many(k, [samples::incident(k + 23, later), samples::incident(k + 24, later)]);
message.more_incidents = states::flag(3, k);
message.uptime_days = states::many(
k,
[samples::uptime_day(k + 25, later), samples::uptime_day(k + 26, later)],
);
})
}
pub fn running_services_action(k: usize, later: bool) -> types::RunningServicesAction {
states::make(|message: &mut types::RunningServicesAction| {
message.kind = samples::services_action_kind(k);
message.services = states::many(k, [states::text("services", k), states::text("services", k + 1)]);
message.start_time = states::maybe(k, states::time(states::number(3, k + 2)));
})
}
pub fn project_source(k: usize, later: bool) -> types::ProjectSource {
types::ProjectSource {
kind: match k % 6 {
0 => None,
1 => later.then_some(types::ProjectSourceKind::Unrecognized),
2 => Some(types::ProjectSourceKind::Files(true)),
3 => Some(types::ProjectSourceKind::Github(samples::github_source(k, later))),
4 => Some(types::ProjectSourceKind::Files(Default::default())),
_ => Some(types::ProjectSourceKind::Github(Default::default())),
},
}
}
pub fn github_source(k: usize, later: bool) -> types::GithubSource {
types::GithubSource {
repository: states::marked(k, states::text("repository", k)),
branch: states::marked(k, states::text("branch", k)),
directory: states::marked(k, states::text("directory", k)),
auto_deploy: states::marked(k, true),
newest_commit: states::maybe(k, samples::github_commit(k + 4, later)),
deployed_commit: states::maybe(k, samples::github_commit(k + 5, later)),
pinned: states::flag(1, k),
auto_deploy_pending: states::flag(2, k),
}
}
pub fn github_commit(k: usize, later: bool) -> types::GithubCommit {
types::GithubCommit {
sha: states::plain(k, states::text("sha", k)),
title: states::plain(k, states::text("title", k)),
url: states::plain(k, states::text("url", k)),
}
}
pub fn service(k: usize, later: bool) -> types::Service {
states::make(|message: &mut types::Service| {
message.service = states::plain(k, states::text("service", k));
message.state = samples::service_state(k + 1);
message.container_running = states::flag(1, k);
message.image = states::plain(k, states::text("image", k));
message.builds_image = states::flag(2, k);
message.image_digest = states::plain(k, states::text("image_digest", k));
message.image_size_bytes = states::plain(k, u64::from(states::number(6, k)) << 44);
message.command = states::many(k, [states::text("command", k), states::text("command", k + 1)]);
message.run_as_user = states::plain(k, states::text("run_as_user", k));
message.start_time = states::maybe(k, states::time(states::number(9, k + 9)));
message.finish_time = states::maybe(k, states::time(states::number(10, k + 10)));
message.exit_code = states::marked(k, -(states::number(11, k) as i32));
message.out_of_memory = states::flag(3, k);
message.restart_count = states::plain(k, states::number(13, k));
message.cpu_used_cores = states::plain(k, f64::from(states::number(14, k)) + 0.5);
message.memory_used_bytes = states::plain(k, u64::from(states::number(15, k)) << 44);
message.memory_limit_bytes = states::plain(k, u64::from(states::number(16, k)) << 44);
message.cpu_limit_cores = states::plain(k, f64::from(states::number(17, k)) + 0.5);
message.writable_layer_bytes = states::plain(k, u64::from(states::number(18, k)) << 44);
message.ports = states::many(k, [states::number(19, k), states::number(19, k + 1)]);
message.listening_ports = states::many(k, [states::number(28, k), states::number(28, k + 1)]);
message.published_ports = states::many(
k,
[
samples::published_port(k + 21, later),
samples::published_port(k + 22, later),
],
);
message.volume_mounts = states::many(
k,
[
samples::volume_mount(k + 22, later),
samples::volume_mount(k + 23, later),
],
);
message.restart_policy = samples::restart_policy(k + 23);
message.health_check = states::maybe(k, samples::health_check(k + 24, later));
message.environment = states::many(
k,
[
samples::environment_variable(k + 25, later),
samples::environment_variable(k + 26, later),
],
);
message.env_files = states::many(k, [states::text("env_files", k), states::text("env_files", k + 1)]);
message.ssh_command = states::plain(k, states::text("ssh_command", k));
})
}
pub fn published_port(k: usize, later: bool) -> types::PublishedPort {
states::make(|message: &mut types::PublishedPort| {
message.machine_port = states::plain(k, states::number(1, k));
message.container_port = states::plain(k, states::number(2, k));
message.protocol = states::plain(k, states::text("protocol", k));
})
}
pub fn volume_mount(k: usize, later: bool) -> types::VolumeMount {
states::make(|message: &mut types::VolumeMount| {
message.volume = states::plain(k, states::text("volume", k));
message.container_path = states::plain(k, states::text("container_path", k));
})
}
pub fn health_check(k: usize, later: bool) -> types::HealthCheck {
states::make(|message: &mut types::HealthCheck| {
message.command = states::many(k, [states::text("command", k), states::text("command", k + 1)]);
message.interval_seconds = states::plain(k, states::number(2, k));
message.status = samples::health_status(k + 2);
message.consecutive_failure_count = states::plain(k, states::number(4, k));
message.recent_results_passed = states::many(k, [true, true]);
message.last_failure_output = states::plain(k, states::text("last_failure_output", k));
})
}
pub fn environment_variable(k: usize, later: bool) -> types::EnvironmentVariable {
states::make(|message: &mut types::EnvironmentVariable| {
message.name = states::plain(k, states::text("name", k));
message.value = states::plain(k, states::text("value", k));
message.secret = states::flag(1, k);
message.source_file = states::plain(k, states::text("source_file", k));
message.from_env_file_variables = states::many(
k,
[
states::text("from_env_file_variables", k),
states::text("from_env_file_variables", k + 1),
],
);
message.value_left_out = states::flag(2, k);
})
}
pub fn volume(k: usize, later: bool) -> types::Volume {
states::make(|message: &mut types::Volume| {
message.volume = states::plain(k, states::text("volume", k));
message.size_bytes = states::plain(k, u64::from(states::number(2, k)) << 44);
message.mounted_by = states::many(
k,
[
samples::volume_mounted_by(k + 2, later),
samples::volume_mounted_by(k + 3, later),
],
);
message.last_backup_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.snapshot_count = states::plain(k, states::number(6, k));
message.declared = states::flag(1, k);
})
}
pub fn volume_mounted_by(k: usize, later: bool) -> types::VolumeMountedBy {
states::make(|message: &mut types::VolumeMountedBy| {
message.service = states::plain(k, states::text("service", k));
message.container_path = states::plain(k, states::text("container_path", k));
})
}
pub fn host(k: usize, later: bool) -> types::Host {
states::make(|message: &mut types::Host| {
message.host = states::plain(k, states::text("host", k));
message.url = states::plain(k, states::text("url", k));
message.certificate_source = samples::certificate_source(k + 2);
message.certificate_expire_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.unavailable_message = states::plain(k, states::text("unavailable_message", k));
})
}
pub fn route(k: usize, later: bool) -> types::Route {
types::Route {
host: states::plain(k, states::text("host", k)),
path: states::plain(k, states::text("path", k)),
service: states::plain(k, states::text("service", k)),
port: states::plain(k, states::number(4, k)),
strip_path: states::flag(1, k),
}
}
pub fn operation(k: usize, later: bool) -> types::Operation {
states::make(|message: &mut types::Operation| {
message.operation_id = states::plain(k, states::text("operation_id", k));
message.kind = samples::operation_kind(k + 1);
message.status = samples::operation_status(k + 2);
message.start_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.finish_time = states::maybe(k, states::time(states::number(5, k + 4)));
message.failure_message = states::plain(k, states::text("failure_message", k));
message.deploy_failure_reason = samples::deploy_failure_reason(k + 6);
message.made_current = states::flag(1, k);
message.service = states::plain(k, states::text("service", k));
message.failed_exit_code = states::plain(k, -(states::number(10, k) as i32));
message.snapshot_id = states::plain(k, states::text("snapshot_id", k));
message.restored_volumes = states::many(
k,
[
states::text("restored_volumes", k),
states::text("restored_volumes", k + 1),
],
);
message.undo_snapshot_id = states::plain(k, states::text("undo_snapshot_id", k));
message.github_commit = states::maybe(k, samples::github_commit(k + 13, later));
message.archive_name = states::plain(k, states::text("archive_name", k));
message.adjustments = states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]);
message.changed_paths = states::many(
k,
[states::text("changed_paths", k), states::text("changed_paths", k + 1)],
);
message.changed_path_count = states::plain(k, states::number(18, k));
message.files_kept = states::flag(2, k);
message.files_operation_id = states::plain(k, states::text("files_operation_id", k));
})
}
pub fn snapshot(k: usize, later: bool) -> types::Snapshot {
states::make(|message: &mut types::Snapshot| {
message.snapshot_id = states::plain(k, states::text("snapshot_id", k));
message.create_time = states::maybe(k, states::time(states::number(2, k + 1)));
message.size_bytes = states::plain(k, u64::from(states::number(3, k)) << 44);
message.volumes = states::many(k, [states::text("volumes", k), states::text("volumes", k + 1)]);
})
}
pub fn http_traffic_summary(k: usize, later: bool) -> types::HttpTrafficSummary {
states::make(|message: &mut types::HttpTrafficSummary| {
message.request_count = states::plain(k, u64::from(states::number(1, k)) << 44);
message.server_error_count = states::plain(k, u64::from(states::number(2, k)) << 44);
message.latency_p50_ms = states::plain(k, states::number(3, k));
message.latency_p95_ms = states::plain(k, states::number(4, k));
})
}
pub fn create_project_request(k: usize, later: bool) -> types::CreateProjectRequest {
types::CreateProjectRequest {
project_id: states::plain(k, states::text("project_id", k)),
source: states::maybe(k, samples::project_source(k + 1, later)),
upload_id: states::plain(k, states::text("upload_id", k)),
files: states::many(
k,
[samples::file_change(k + 3, later), samples::file_change(k + 4, later)],
),
x_pethost: states::maybe(k, samples::project_extension(k + 4, later)),
timeout_seconds: states::plain(k, states::number(6, k)),
operation_id: states::plain(k, states::text("operation_id", k)),
wait_seconds: states::marked(k, states::number(9, k)),
}
}
pub fn create_project_response(k: usize, later: bool) -> types::CreateProjectResponse {
states::make(|message: &mut types::CreateProjectResponse| {
message.operation = states::maybe(k, samples::operation(k, later));
message.violations = states::many(
k,
[
samples::spec_violation(k + 1, later),
samples::spec_violation(k + 2, later),
],
);
message.adjustments = states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]);
message.project = states::maybe(k, samples::project(k + 3, later));
message.log = states::many(
k,
[
samples::operation_log_line(k + 4, later),
samples::operation_log_line(k + 5, later),
],
);
})
}
pub fn deploy_project_request(k: usize, later: bool) -> types::DeployProjectRequest {
types::DeployProjectRequest {
project_id: states::plain(k, states::text("project_id", k)),
base_deploy_id: states::plain(k, states::text("base_deploy_id", k)),
files: states::many(
k,
[samples::file_change(k + 2, later), samples::file_change(k + 3, later)],
),
x_pethost: states::maybe(k, samples::project_extension(k + 3, later)),
mount_volume: states::maybe(k, samples::mount_volume(k + 4, later)),
timeout_seconds: states::plain(k, states::number(4, k)),
operation_id: states::plain(k, states::text("operation_id", k)),
version: match k % 10 {
0 => None,
1 => None,
2 => Some(types::DeployProjectRequestVersion::UploadId(states::text(
"upload_id",
k,
))),
3 => Some(types::DeployProjectRequestVersion::Commit(states::text("commit", k))),
4 => Some(types::DeployProjectRequestVersion::NewestCommit(true)),
5 => Some(types::DeployProjectRequestVersion::RollbackDeployId(states::text(
"rollback_deploy_id",
k,
))),
6 => Some(types::DeployProjectRequestVersion::UploadId(Default::default())),
7 => Some(types::DeployProjectRequestVersion::Commit(Default::default())),
8 => Some(types::DeployProjectRequestVersion::NewestCommit(Default::default())),
_ => Some(types::DeployProjectRequestVersion::RollbackDeployId(Default::default())),
},
wait_seconds: states::marked(k, states::number(13, k)),
}
}
pub fn mount_volume(k: usize, later: bool) -> types::MountVolume {
types::MountVolume {
service: states::plain(k, states::text("service", k)),
volume: states::plain(k, states::text("volume", k)),
container_path: states::plain(k, states::text("container_path", k)),
}
}
pub fn project_extension(k: usize, later: bool) -> types::ProjectExtension {
types::ProjectExtension {
metadata: states::maybe(k, samples::project_metadata(k, later)),
routes: states::many(k, [samples::route(k + 1, later), samples::route(k + 2, later)]),
remove_routes: states::flag(1, k),
password: states::plain(k, states::text("password", k)),
remove_password: states::flag(2, k),
}
}
pub fn file_change(k: usize, later: bool) -> types::FileChange {
types::FileChange {
path: states::plain(k, states::text("path", k)),
change: match k % 14 {
0 => None,
1 => None,
2 => Some(types::FileChangeChange::Text(states::text("text", k))),
3 => Some(types::FileChangeChange::Data(states::text("data", k).into_bytes())),
4 => Some(types::FileChangeChange::MakeDirectory(true)),
5 => Some(types::FileChangeChange::Delete(true)),
6 => Some(types::FileChangeChange::DeleteTree(true)),
7 => Some(types::FileChangeChange::RenameTo(states::text("rename_to", k))),
8 => Some(types::FileChangeChange::Text(Default::default())),
9 => Some(types::FileChangeChange::Data(Default::default())),
10 => Some(types::FileChangeChange::MakeDirectory(Default::default())),
11 => Some(types::FileChangeChange::Delete(Default::default())),
12 => Some(types::FileChangeChange::DeleteTree(Default::default())),
_ => Some(types::FileChangeChange::RenameTo(Default::default())),
},
executable: states::flag(1, k),
}
}
pub fn deploy_project_response(k: usize, later: bool) -> types::DeployProjectResponse {
states::make(|message: &mut types::DeployProjectResponse| {
message.operation = states::maybe(k, samples::operation(k, later));
message.violations = states::many(
k,
[
samples::spec_violation(k + 1, later),
samples::spec_violation(k + 2, later),
],
);
message.adjustments = states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]);
message.project = states::maybe(k, samples::project(k + 3, later));
message.log = states::many(
k,
[
samples::operation_log_line(k + 4, later),
samples::operation_log_line(k + 5, later),
],
);
})
}
pub fn spec_violation(k: usize, later: bool) -> types::SpecViolation {
states::make(|message: &mut types::SpecViolation| {
message.service = states::plain(k, states::text("service", k));
message.location = states::plain(k, states::text("location", k));
message.violation_message = states::plain(k, states::text("violation_message", k));
})
}
pub fn list_commits_request(k: usize, later: bool) -> types::ListCommitsRequest {
types::ListCommitsRequest {
project_id: states::plain(k, states::text("project_id", k)),
before_commit: states::plain(k, states::text("before_commit", k)),
}
}
pub fn list_commits_response(k: usize, later: bool) -> types::ListCommitsResponse {
states::make(|message: &mut types::ListCommitsResponse| {
message.commits = states::many(
k,
[samples::branch_commit(k, later), samples::branch_commit(k + 1, later)],
);
message.more = states::flag(1, k);
})
}
pub fn branch_commit(k: usize, later: bool) -> types::BranchCommit {
states::make(|message: &mut types::BranchCommit| {
message.commit = states::maybe(k, samples::github_commit(k, later));
message.author = states::plain(k, states::text("author", k));
message.commit_time = states::maybe(k, states::time(states::number(3, k + 2)));
message.deployed = states::flag(1, k);
message.last_deploy = states::maybe(k, samples::operation(k + 4, later));
message.newest = states::flag(2, k);
})
}
pub fn run_project_action_request(k: usize, later: bool) -> types::RunProjectActionRequest {
types::RunProjectActionRequest {
project_id: states::plain(k, states::text("project_id", k)),
action: match k % 22 {
0 => None,
1 => None,
2 => Some(types::RunProjectActionRequestAction::StartServices(
samples::services_action(k, later),
)),
3 => Some(types::RunProjectActionRequestAction::StopServices(
samples::services_action(k, later),
)),
4 => Some(types::RunProjectActionRequestAction::RestartServices(
samples::services_action(k, later),
)),
5 => Some(types::RunProjectActionRequestAction::RecreateService(
samples::recreate_service_action(k, later),
)),
6 => Some(types::RunProjectActionRequestAction::BackUp(samples::back_up_action(
k, later,
))),
7 => Some(types::RunProjectActionRequestAction::RestoreSnapshot(
samples::restore_snapshot_action(k, later),
)),
8 => Some(types::RunProjectActionRequestAction::CancelOperation(
samples::cancel_operation_action(k, later),
)),
9 => Some(types::RunProjectActionRequestAction::DeleteProject(
samples::delete_project_action(k, later),
)),
10 => Some(types::RunProjectActionRequestAction::SetSource(
samples::project_source(k, later),
)),
11 => Some(types::RunProjectActionRequestAction::DeleteVolume(states::text(
"delete_volume",
k,
))),
12 => Some(types::RunProjectActionRequestAction::StartServices(Default::default())),
13 => Some(types::RunProjectActionRequestAction::StopServices(Default::default())),
14 => Some(types::RunProjectActionRequestAction::RestartServices(Default::default())),
15 => Some(types::RunProjectActionRequestAction::RecreateService(Default::default())),
16 => Some(types::RunProjectActionRequestAction::BackUp(Default::default())),
17 => Some(types::RunProjectActionRequestAction::RestoreSnapshot(Default::default())),
18 => Some(types::RunProjectActionRequestAction::CancelOperation(Default::default())),
19 => Some(types::RunProjectActionRequestAction::DeleteProject(Default::default())),
20 => Some(types::RunProjectActionRequestAction::SetSource(Default::default())),
_ => Some(types::RunProjectActionRequestAction::DeleteVolume(Default::default())),
},
operation_id: states::plain(k, states::text("operation_id", k)),
wait_seconds: states::marked(k, states::number(13, k)),
}
}
pub fn services_action(k: usize, later: bool) -> types::ServicesAction {
types::ServicesAction {
services: states::many(k, [states::text("services", k), states::text("services", k + 1)]),
}
}
pub fn recreate_service_action(k: usize, later: bool) -> types::RecreateServiceAction {
types::RecreateServiceAction {
service: states::plain(k, states::text("service", k)),
pull_latest_image: states::flag(1, k),
}
}
pub fn back_up_action(_k: usize, later: bool) -> types::BackUpAction {
types::BackUpAction {}
}
pub fn restore_snapshot_action(k: usize, later: bool) -> types::RestoreSnapshotAction {
types::RestoreSnapshotAction {
snapshot_id: states::plain(k, states::text("snapshot_id", k)),
volumes: states::many(k, [states::text("volumes", k), states::text("volumes", k + 1)]),
}
}
pub fn cancel_operation_action(k: usize, later: bool) -> types::CancelOperationAction {
types::CancelOperationAction {
operation_id: states::plain(k, states::text("operation_id", k)),
}
}
pub fn delete_project_action(k: usize, later: bool) -> types::DeleteProjectAction {
types::DeleteProjectAction {
skip_final_backup: states::flag(1, k),
}
}
pub fn run_project_action_response(k: usize, later: bool) -> types::RunProjectActionResponse {
states::make(|message: &mut types::RunProjectActionResponse| {
message.operation = states::maybe(k, samples::operation(k, later));
message.project = states::maybe(k, samples::project(k + 1, later));
message.log = states::many(
k,
[
samples::operation_log_line(k + 2, later),
samples::operation_log_line(k + 3, later),
],
);
})
}
pub fn set_project_alerts_request(k: usize, later: bool) -> types::SetProjectAlertsRequest {
types::SetProjectAlertsRequest {
project_id: states::plain(k, states::text("project_id", k)),
checks: states::many(
k,
[samples::site_check(k + 1, later), samples::site_check(k + 2, later)],
),
remove_checks: states::flag(1, k),
traffic_rules: states::many(
k,
[samples::traffic_rule(k + 3, later), samples::traffic_rule(k + 4, later)],
),
remove_traffic_rules: states::flag(2, k),
off: states::marked(k, true),
mute_minutes: states::marked(k, states::number(7, k)),
}
}
pub fn set_project_alerts_response(k: usize, later: bool) -> types::SetProjectAlertsResponse {
states::make(|message: &mut types::SetProjectAlertsResponse| {
message.alerts = states::maybe(k, samples::project_alerts(k, later));
})
}
pub fn site_check(k: usize, later: bool) -> types::SiteCheck {
types::SiteCheck {
host: states::plain(k, states::text("host", k)),
path: states::plain(k, states::text("path", k)),
expect_status: states::plain(k, states::number(3, k)),
must_contain: states::plain(k, states::text("must_contain", k)),
}
}
pub fn traffic_rule(k: usize, later: bool) -> types::TrafficRule {
types::TrafficRule {
metric: samples::traffic_metric(k),
filter: states::maybe(k, samples::http_traffic_filter(k + 1, later)),
threshold: states::plain(k, f64::from(states::number(3, k)) + 0.5),
window_minutes: states::plain(k, states::number(4, k)),
min_requests: states::plain(k, states::number(5, k)),
}
}
pub fn project_alerts(k: usize, later: bool) -> types::ProjectAlerts {
states::make(|message: &mut types::ProjectAlerts| {
message.checks = states::many(
k,
[
samples::site_check_state(k, later),
samples::site_check_state(k + 1, later),
],
);
message.traffic_rules = states::many(
k,
[
samples::traffic_rule_state(k + 1, later),
samples::traffic_rule_state(k + 2, later),
],
);
message.off = states::flag(1, k);
message.mute_end_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.uptime_percent = states::marked(k, f64::from(states::number(5, k)) + 0.5);
})
}
pub fn site_check_state(k: usize, later: bool) -> types::SiteCheckState {
states::make(|message: &mut types::SiteCheckState| {
message.check = states::maybe(k, samples::site_check(k, later));
message.machine_default = states::flag(1, k);
message.status = samples::alert_status(k + 2);
message.last_result = states::maybe(k, samples::site_check_result(k + 3, later));
message.incident_id = states::plain(k, states::text("incident_id", k));
})
}
pub fn site_check_result(k: usize, later: bool) -> types::SiteCheckResult {
states::make(|message: &mut types::SiteCheckResult| {
message.check_time = states::maybe(k, states::time(states::number(1, k)));
message.status = states::plain(k, states::number(2, k));
message.duration_ms = states::plain(k, states::number(3, k));
message.failure_message = states::plain(k, states::text("failure_message", k));
})
}
pub fn traffic_rule_state(k: usize, later: bool) -> types::TrafficRuleState {
states::make(|message: &mut types::TrafficRuleState| {
message.rule = states::maybe(k, samples::traffic_rule(k, later));
message.machine_default = states::flag(1, k);
message.status = samples::alert_status(k + 2);
message.value = states::plain(k, f64::from(states::number(4, k)) + 0.5);
message.request_count = states::plain(k, u64::from(states::number(5, k)) << 44);
message.incident_id = states::plain(k, states::text("incident_id", k));
})
}
pub fn incident(k: usize, later: bool) -> types::Incident {
states::make(|message: &mut types::Incident| {
message.incident_id = states::plain(k, states::text("incident_id", k));
message.kind = samples::project_problem_kind(k + 1);
message.service = states::plain(k, states::text("service", k));
message.check = states::maybe(k, samples::site_check(k + 3, later));
message.traffic_rule = states::maybe(k, samples::traffic_rule(k + 4, later));
message.operation_id = states::plain(k, states::text("operation_id", k));
message.open_time = states::maybe(k, states::time(states::number(7, k + 6)));
message.resolve_time = states::maybe(k, states::time(states::number(8, k + 7)));
message.value = states::plain(k, f64::from(states::number(9, k)) + 0.5);
message.request_count = states::plain(k, u64::from(states::number(10, k)) << 44);
message.after_operation_id = states::plain(k, states::text("after_operation_id", k));
message.after_operation_end_time = states::maybe(k, states::time(states::number(12, k + 11)));
message.joined_incident_id = states::plain(k, states::text("joined_incident_id", k));
message.quiet_reason = samples::incident_quiet_reason(k + 13);
message.flapping = states::flag(1, k);
message.incident_message = states::plain(k, states::text("incident_message", k));
message.evidence = states::maybe(k, samples::incident_evidence(k + 16, later));
})
}
pub fn incident_evidence(k: usize, later: bool) -> types::IncidentEvidence {
states::make(|message: &mut types::IncidentEvidence| {
message.check_result = states::maybe(k, samples::site_check_result(k, later));
message.exit_code = states::plain(k, -(states::number(2, k) as i32));
message.oom_killed = states::flag(1, k);
message.restart_count = states::plain(k, states::number(4, k));
message.health_output = states::plain(k, states::text("health_output", k));
message.log_lines = states::many(k, [samples::log_line(k + 5, later), samples::log_line(k + 6, later)]);
message.top_path = states::maybe(k, samples::http_path_traffic(k + 6, later));
})
}
pub fn uptime_day(k: usize, later: bool) -> types::UptimeDay {
states::make(|message: &mut types::UptimeDay| {
message.start_time = states::maybe(k, states::time(states::number(1, k)));
message.uptime_percent = states::marked(k, f64::from(states::number(2, k)) + 0.5);
message.down_seconds = states::plain(k, states::number(3, k));
})
}
pub fn get_operation_request(k: usize, later: bool) -> types::GetOperationRequest {
types::GetOperationRequest {
project_id: states::plain(k, states::text("project_id", k)),
operation_id: states::plain(k, states::text("operation_id", k)),
wait_seconds: states::marked(k, states::number(3, k)),
after_log_line: states::marked(k, states::number(4, k)),
log_line_limit: states::marked(k, states::number(5, k)),
}
}
pub fn get_operation_response(k: usize, later: bool) -> types::GetOperationResponse {
states::make(|message: &mut types::GetOperationResponse| {
message.operation = states::maybe(k, samples::operation(k, later));
message.project = states::maybe(k, samples::project(k + 1, later));
message.log = states::many(
k,
[
samples::operation_log_line(k + 2, later),
samples::operation_log_line(k + 3, later),
],
);
message.log_line_count = states::plain(k, states::number(3, k));
message.next_after_log_line = states::plain(k, states::number(4, k));
})
}
pub fn operation_log_line(k: usize, later: bool) -> types::OperationLogLine {
states::make(|message: &mut types::OperationLogLine| {
message.time = states::maybe(k, states::time(states::number(1, k)));
message.text = states::plain(k, states::text("text", k));
})
}
pub fn http_traffic_filter(k: usize, later: bool) -> types::HttpTrafficFilter {
types::HttpTrafficFilter {
host: states::plain(k, states::text("host", k)),
method: states::plain(k, states::text("method", k)),
path_contains: states::plain(k, states::text("path_contains", k)),
path_pattern: states::plain(k, states::text("path_pattern", k)),
status_class: states::plain(k, states::number(5, k)),
}
}
pub fn query_http_traffic_request(k: usize, later: bool) -> types::QueryHttpTrafficRequest {
types::QueryHttpTrafficRequest {
project_id: states::plain(k, states::text("project_id", k)),
filter: states::maybe(k, samples::http_traffic_filter(k + 1, later)),
start_time: states::maybe(k, states::time(states::number(3, k + 2))),
end_time: states::maybe(k, states::time(states::number(4, k + 3))),
last_seconds: states::plain(k, states::number(8, k)),
bucket_width_seconds: states::plain(k, states::number(5, k)),
request_limit: states::plain(k, states::number(6, k)),
page_token: states::plain(k, states::text("page_token", k)),
}
}
pub fn query_http_traffic_response(k: usize, later: bool) -> types::QueryHttpTrafficResponse {
states::make(|message: &mut types::QueryHttpTrafficResponse| {
message.start_time = states::maybe(k, states::time(states::number(1, k)));
message.end_time = states::maybe(k, states::time(states::number(2, k + 1)));
message.oldest_kept_time = states::maybe(k, states::time(states::number(8, k + 2)));
message.summary = states::maybe(k, samples::http_traffic_summary(k + 3, later));
message.buckets = states::many(
k,
[
samples::http_traffic_bucket(k + 4, later),
samples::http_traffic_bucket(k + 5, later),
],
);
message.top_paths = states::many(
k,
[
samples::http_path_traffic(k + 5, later),
samples::http_path_traffic(k + 6, later),
],
);
message.newest_sequence = states::plain(k, u64::from(states::number(9, k)) << 44);
message.requests = states::many(
k,
[samples::http_request(k + 7, later), samples::http_request(k + 8, later)],
);
message.next_page_token = states::plain(k, states::text("next_page_token", k));
message.tail_sequence = states::plain(k, u64::from(states::number(10, k)) << 44);
})
}
pub fn http_traffic_bucket(k: usize, later: bool) -> types::HttpTrafficBucket {
states::make(|message: &mut types::HttpTrafficBucket| {
message.start_time = states::maybe(k, states::time(states::number(1, k)));
message.summary = states::maybe(k, samples::http_traffic_summary(k + 1, later));
})
}
pub fn http_path_traffic(k: usize, later: bool) -> types::HttpPathTraffic {
states::make(|message: &mut types::HttpPathTraffic| {
message.method = states::plain(k, states::text("method", k));
message.path_pattern = states::plain(k, states::text("path_pattern", k));
message.summary = states::maybe(k, samples::http_traffic_summary(k + 2, later));
})
}
pub fn http_request(k: usize, later: bool) -> types::HttpRequest {
states::make(|message: &mut types::HttpRequest| {
message.sequence = states::plain(k, u64::from(states::number(1, k)) << 44);
message.finish_time = states::maybe(k, states::time(states::number(2, k + 1)));
message.host = states::plain(k, states::text("host", k));
message.method = states::plain(k, states::text("method", k));
message.path = states::plain(k, states::text("path", k));
message.path_pattern = states::plain(k, states::text("path_pattern", k));
message.route_path = states::plain(k, states::text("route_path", k));
message.service = states::plain(k, states::text("service", k));
message.port = states::plain(k, states::number(9, k));
message.status_code = states::plain(k, states::number(10, k));
message.response_size_bytes = states::plain(k, u64::from(states::number(11, k)) << 44);
message.duration_ms = states::plain(k, states::number(12, k));
message.service_duration_ms = states::plain(k, states::number(13, k));
message.client_ip_address = states::plain(k, states::text("client_ip_address", k));
message.user_agent = states::plain(k, states::text("user_agent", k));
})
}
pub fn container_log_filter(k: usize, later: bool) -> types::ContainerLogFilter {
types::ContainerLogFilter {
service: states::plain(k, states::text("service", k)),
stream: samples::output_stream(k + 1),
text_contains: states::plain(k, states::text("text_contains", k)),
}
}
pub fn query_container_logs_request(k: usize, later: bool) -> types::QueryContainerLogsRequest {
types::QueryContainerLogsRequest {
project_id: states::plain(k, states::text("project_id", k)),
filter: states::maybe(k, samples::container_log_filter(k + 1, later)),
start_time: states::maybe(k, states::time(states::number(3, k + 2))),
end_time: states::maybe(k, states::time(states::number(4, k + 3))),
last_seconds: states::plain(k, states::number(8, k)),
limit: states::plain(k, states::number(5, k)),
from_start: states::flag(1, k),
page_token: states::plain(k, states::text("page_token", k)),
}
}
pub fn query_container_logs_response(k: usize, later: bool) -> types::QueryContainerLogsResponse {
states::make(|message: &mut types::QueryContainerLogsResponse| {
message.start_time = states::maybe(k, states::time(states::number(4, k)));
message.end_time = states::maybe(k, states::time(states::number(5, k + 1)));
message.oldest_kept_time = states::maybe(k, states::time(states::number(6, k + 2)));
message.lines = states::many(k, [samples::log_line(k + 3, later), samples::log_line(k + 4, later)]);
message.next_page_token = states::plain(k, states::text("next_page_token", k));
message.tail_cursor = states::plain(k, states::text("tail_cursor", k));
})
}
pub fn log_line(k: usize, later: bool) -> types::LogLine {
states::make(|message: &mut types::LogLine| {
message.time = states::maybe(k, states::time(states::number(1, k)));
message.service = states::plain(k, states::text("service", k));
message.stream = samples::output_stream(k + 2);
message.text = states::plain(k, states::text("text", k));
})
}
pub fn run_service_command_request(k: usize, later: bool) -> types::RunServiceCommandRequest {
types::RunServiceCommandRequest {
project_id: states::plain(k, states::text("project_id", k)),
service: states::plain(k, states::text("service", k)),
command: states::many(k, [states::text("command", k), states::text("command", k + 1)]),
stdin: states::plain(k, states::text("stdin", k)),
run_as_user: states::plain(k, states::text("run_as_user", k)),
working_directory: states::plain(k, states::text("working_directory", k)),
timeout_seconds: states::plain(k, states::number(7, k)),
}
}
pub fn run_service_command_response(k: usize, later: bool) -> types::RunServiceCommandResponse {
states::make(|message: &mut types::RunServiceCommandResponse| {
message.exit_code = states::plain(k, -(states::number(1, k) as i32));
message.timed_out = states::flag(1, k);
message.stdout = states::plain(k, states::text("stdout", k));
message.stderr = states::plain(k, states::text("stderr", k));
message.output_truncated = states::flag(2, k);
})
}
pub fn file_entry(k: usize, later: bool) -> types::FileEntry {
states::make(|message: &mut types::FileEntry| {
message.name = states::plain(k, states::text("name", k));
message.r#type = samples::file_type(k + 1);
message.size_bytes = states::plain(k, u64::from(states::number(3, k)) << 44);
message.modify_time = states::maybe(k, states::time(states::number(4, k + 3)));
message.mode = states::plain(k, states::text("mode", k));
message.owner_uid = states::plain(k, states::number(6, k));
message.owner_gid = states::plain(k, states::number(7, k));
message.symlink_target = states::plain(k, states::text("symlink_target", k));
})
}
pub fn read_path_request(k: usize, later: bool) -> types::ReadPathRequest {
types::ReadPathRequest {
project_id: states::plain(k, states::text("project_id", k)),
root: match k % 6 {
0 => None,
1 => None,
2 => Some(types::ReadPathRequestRoot::Service(states::text("service", k))),
3 => Some(types::ReadPathRequestRoot::Volume(states::text("volume", k))),
4 => Some(types::ReadPathRequestRoot::Service(Default::default())),
_ => Some(types::ReadPathRequestRoot::Volume(Default::default())),
},
path: states::plain(k, states::text("path", k)),
entry_limit: states::plain(k, states::number(6, k)),
offset_bytes: states::plain(k, u64::from(states::number(7, k)) << 44),
length_bytes: states::plain(k, states::number(8, k)),
entry_page_token: states::plain(k, states::text("entry_page_token", k)),
}
}
pub fn read_path_response(k: usize, later: bool) -> types::ReadPathResponse {
states::make(|message: &mut types::ReadPathResponse| {
message.entry = states::maybe(k, samples::file_entry(k, later));
message.location = samples::file_location(k + 1);
message.volume = states::plain(k, states::text("volume", k));
message.entries = states::many(
k,
[samples::file_entry(k + 3, later), samples::file_entry(k + 4, later)],
);
message.entry_count = states::plain(k, states::number(4, k));
message.next_entry_page_token = states::plain(k, states::text("next_entry_page_token", k));
message.text = states::plain(k, states::text("text", k));
message.binary = states::flag(1, k);
message.next_offset_bytes = states::plain(k, u64::from(states::number(7, k)) << 44);
message.deploy_id = states::plain(k, states::text("deploy_id", k));
})
}
pub fn create_transfer_request(k: usize, later: bool) -> types::CreateTransferRequest {
types::CreateTransferRequest {
transfer: match k % 8 {
0 => None,
1 => None,
2 => Some(types::CreateTransferRequestTransfer::UploadArchive(
samples::archive_upload(k, later),
)),
3 => Some(types::CreateTransferRequestTransfer::UploadFile(samples::file_upload(
k, later,
))),
4 => Some(types::CreateTransferRequestTransfer::Download(samples::path_download(
k, later,
))),
5 => Some(types::CreateTransferRequestTransfer::UploadArchive(Default::default())),
6 => Some(types::CreateTransferRequestTransfer::UploadFile(Default::default())),
_ => Some(types::CreateTransferRequestTransfer::Download(Default::default())),
},
}
}
pub fn archive_upload(k: usize, later: bool) -> types::ArchiveUpload {
types::ArchiveUpload {
file_name: states::plain(k, states::text("file_name", k)),
}
}
pub fn file_upload(k: usize, later: bool) -> types::FileUpload {
types::FileUpload {
project_id: states::plain(k, states::text("project_id", k)),
root: match k % 6 {
0 => None,
1 => None,
2 => Some(types::FileUploadRoot::Service(states::text("service", k))),
3 => Some(types::FileUploadRoot::Volume(states::text("volume", k))),
4 => Some(types::FileUploadRoot::Service(Default::default())),
_ => Some(types::FileUploadRoot::Volume(Default::default())),
},
path: states::plain(k, states::text("path", k)),
}
}
pub fn path_download(k: usize, later: bool) -> types::PathDownload {
types::PathDownload {
project_id: states::plain(k, states::text("project_id", k)),
root: match k % 6 {
0 => None,
1 => None,
2 => Some(types::PathDownloadRoot::Service(states::text("service", k))),
3 => Some(types::PathDownloadRoot::Volume(states::text("volume", k))),
4 => Some(types::PathDownloadRoot::Service(Default::default())),
_ => Some(types::PathDownloadRoot::Volume(Default::default())),
},
path: states::plain(k, states::text("path", k)),
}
}
pub fn create_transfer_response(k: usize, later: bool) -> types::CreateTransferResponse {
states::make(|message: &mut types::CreateTransferResponse| {
message.url = states::plain(k, states::text("url", k));
message.http_method = states::plain(k, states::text("http_method", k));
message.expire_time = states::maybe(k, states::time(states::number(3, k + 2)));
message.command = states::plain(k, states::text("command", k));
message.upload_id = states::plain(k, states::text("upload_id", k));
message.replaces = states::flag(1, k);
message.file_name = states::plain(k, states::text("file_name", k));
message.exclude_names = states::many(
k,
[states::text("exclude_names", k), states::text("exclude_names", k + 1)],
);
})
}
pub fn project_busy(k: usize, later: bool) -> types::ProjectBusy {
states::make(|message: &mut types::ProjectBusy| {
message.operation_id = states::plain(k, states::text("operation_id", k));
message.kind = samples::operation_kind(k + 1);
message.start_time = states::maybe(k, states::time(states::number(3, k + 2)));
})
}
pub fn project_changed(_k: usize, later: bool) -> types::ProjectChanged {
types::ProjectChanged::default()
}
pub fn machine_unreachable(k: usize, later: bool) -> types::MachineUnreachable {
states::make(|message: &mut types::MachineUnreachable| {
message.since_time = states::maybe(k, states::time(states::number(1, k)));
})
}
pub fn machine_update_pending(_k: usize, later: bool) -> types::MachineUpdatePending {
types::MachineUpdatePending::default()
}
pub fn no_machine(k: usize, later: bool) -> types::NoMachine {
states::make(|message: &mut types::NoMachine| {
message.reason = samples::no_machine_reason(k);
message.url = states::plain(k, states::text("url", k));
})
}
pub fn watch_operation_request(k: usize, later: bool) -> types::WatchOperationRequest {
types::WatchOperationRequest {
project_id: states::plain(k, states::text("project_id", k)),
operation_id: states::plain(k, states::text("operation_id", k)),
}
}
pub fn watch_operation_response(k: usize, later: bool) -> types::WatchOperationResponse {
states::make(|message: &mut types::WatchOperationResponse| {
message.message = match k % 6 {
0 => None,
1 => later.then_some(types::WatchOperationResponseMessage::Unrecognized),
2 => Some(types::WatchOperationResponseMessage::Log(samples::operation_log_line(
k, later,
))),
3 => Some(types::WatchOperationResponseMessage::FinishedOperation(
samples::operation(k, later),
)),
4 => Some(types::WatchOperationResponseMessage::Log(Default::default())),
_ => Some(types::WatchOperationResponseMessage::FinishedOperation(
Default::default(),
)),
};
})
}
pub fn tail_container_logs_request(k: usize, later: bool) -> types::TailContainerLogsRequest {
types::TailContainerLogsRequest {
project_id: states::plain(k, states::text("project_id", k)),
filter: states::maybe(k, samples::container_log_filter(k + 1, later)),
after_cursor: states::plain(k, states::text("after_cursor", k)),
}
}
pub fn tail_container_logs_response(k: usize, later: bool) -> types::TailContainerLogsResponse {
states::make(|message: &mut types::TailContainerLogsResponse| {
message.line = states::maybe(k, samples::log_line(k, later));
message.cursor = states::plain(k, states::text("cursor", k));
})
}
pub fn tail_http_traffic_request(k: usize, later: bool) -> types::TailHttpTrafficRequest {
types::TailHttpTrafficRequest {
project_id: states::plain(k, states::text("project_id", k)),
filter: states::maybe(k, samples::http_traffic_filter(k + 1, later)),
after_sequence: states::plain(k, u64::from(states::number(3, k)) << 44),
}
}
pub fn tail_http_traffic_response(k: usize, later: bool) -> types::TailHttpTrafficResponse {
states::make(|message: &mut types::TailHttpTrafficResponse| {
message.request = states::maybe(k, samples::http_request(k, later));
})
}
}
mod on_wire {
use super::*;
pub fn alert_channel_kind(k: usize) -> buffa::EnumValue<wire::AlertChannelKind> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn machine_session_kind(k: usize) -> buffa::EnumValue<wire::MachineSessionKind> {
let number = match k % 7 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
_ => 6,
};
buffa::EnumValue::from(number)
}
pub fn project_problem_kind(k: usize) -> buffa::EnumValue<wire::ProjectProblemKind> {
let number = match k % 15 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
_ => 14,
};
buffa::EnumValue::from(number)
}
pub fn services_action_kind(k: usize) -> buffa::EnumValue<wire::ServicesActionKind> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn service_state(k: usize) -> buffa::EnumValue<wire::ServiceState> {
let number = match k % 10 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
_ => 9,
};
buffa::EnumValue::from(number)
}
pub fn restart_policy(k: usize) -> buffa::EnumValue<wire::RestartPolicy> {
let number = match k % 6 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
_ => 5,
};
buffa::EnumValue::from(number)
}
pub fn health_status(k: usize) -> buffa::EnumValue<wire::HealthStatus> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn certificate_source(k: usize) -> buffa::EnumValue<wire::CertificateSource> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn operation_kind(k: usize) -> buffa::EnumValue<wire::OperationKind> {
let number = match k % 7 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
_ => 6,
};
buffa::EnumValue::from(number)
}
pub fn operation_status(k: usize) -> buffa::EnumValue<wire::OperationStatus> {
let number = match k % 6 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
_ => 5,
};
buffa::EnumValue::from(number)
}
pub fn deploy_failure_reason(k: usize) -> buffa::EnumValue<wire::DeployFailureReason> {
let number = match k % 13 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
_ => 12,
};
buffa::EnumValue::from(number)
}
pub fn traffic_metric(k: usize) -> buffa::EnumValue<wire::TrafficMetric> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn alert_status(k: usize) -> buffa::EnumValue<wire::AlertStatus> {
let number = match k % 7 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
_ => 6,
};
buffa::EnumValue::from(number)
}
pub fn incident_quiet_reason(k: usize) -> buffa::EnumValue<wire::IncidentQuietReason> {
let number = match k % 6 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
_ => 5,
};
buffa::EnumValue::from(number)
}
pub fn output_stream(k: usize) -> buffa::EnumValue<wire::OutputStream> {
let number = match k % 4 {
0 => 0,
1 => 1,
2 => 2,
_ => 3,
};
buffa::EnumValue::from(number)
}
pub fn file_type(k: usize) -> buffa::EnumValue<wire::FileType> {
let number = match k % 6 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
4 => 4,
_ => 5,
};
buffa::EnumValue::from(number)
}
pub fn file_location(k: usize) -> buffa::EnumValue<wire::FileLocation> {
let number = match k % 5 {
0 => 0,
1 => 1,
2 => 2,
3 => 3,
_ => 4,
};
buffa::EnumValue::from(number)
}
pub fn no_machine_reason(k: usize) -> buffa::EnumValue<wire::NoMachineReason> {
let number = match k % 4 {
0 => 0,
1 => 1,
2 => 2,
_ => 3,
};
buffa::EnumValue::from(number)
}
pub fn get_machine_request(k: usize, received: bool) -> wire::GetMachineRequest {
let mut message = wire::GetMachineRequest { ..Default::default() };
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn get_machine_response(k: usize, received: bool) -> wire::GetMachineResponse {
let mut message = wire::GetMachineResponse {
machine: states::maybe(k, on_wire::machine(k, received)).into(),
projects: states::many(
k,
[
on_wire::project_summary(k + 1, received),
on_wire::project_summary(k + 2, received),
],
),
deleted_projects: states::many(
k,
[
on_wire::deleted_project(k + 2, received),
on_wire::deleted_project(k + 3, received),
],
),
github: states::maybe(k, on_wire::github_connection(k + 3, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn machine(k: usize, received: bool) -> wire::Machine {
let mut message = wire::Machine {
name: states::present(states::plain(k, states::text("name", k))),
location: states::present(states::plain(k, states::text("location", k))),
sample_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
cpu_used_cores: states::present(states::plain(k, f64::from(states::number(5, k)) + 0.5)),
cpu_total_cores: states::present(states::plain(k, f64::from(states::number(6, k)) + 0.5)),
memory_used_bytes: states::present(states::plain(k, u64::from(states::number(7, k)) << 44)),
memory_total_bytes: states::present(states::plain(k, u64::from(states::number(8, k)) << 44)),
disk_used_bytes: states::present(states::plain(k, u64::from(states::number(9, k)) << 44)),
disk_total_bytes: states::present(states::plain(k, u64::from(states::number(10, k)) << 44)),
disk_usage: states::maybe(k, on_wire::disk_usage(k + 9, received)).into(),
hostname: states::present(states::plain(k, states::text("hostname", k))),
ssh_host_key_fingerprint: states::present(states::plain(k, states::text("ssh_host_key_fingerprint", k))),
ssh_keys: states::many(
k,
[on_wire::ssh_key(k + 12, received), on_wire::ssh_key(k + 13, received)],
),
backups_enabled: states::present(states::flag(1, k)),
snapshot_list_time: states::maybe(k, states::time_on_wire(states::number(22, k + 14))).into(),
snapshot_list_failure_message: states::present(states::plain(
k,
states::text("snapshot_list_failure_message", k),
)),
backup_retention_hours: states::present(states::plain(k, states::number(4, k))),
acme_enabled: states::present(states::flag(2, k)),
apps_domain: states::present(states::plain(k, states::text("apps_domain", k))),
daemon_version: states::present(states::plain(k, states::text("daemon_version", k))),
docker_version: states::present(states::plain(k, states::text("docker_version", k))),
boot_time: states::maybe(k, states::time_on_wire(states::number(18, k + 21))).into(),
restart_required_time: states::maybe(k, states::time_on_wire(states::number(19, k + 22))).into(),
scheduled_restart_time: states::maybe(k, states::time_on_wire(states::number(20, k + 23))).into(),
sessions: states::many(
k,
[
on_wire::machine_session(k + 24, received),
on_wire::machine_session(k + 25, received),
],
),
alert_channels: states::many(
k,
[
on_wire::alert_destination(k + 25, received),
on_wire::alert_destination(k + 26, received),
],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn alert_destination(k: usize, received: bool) -> wire::AlertDestination {
let mut message = wire::AlertDestination {
kind: states::set(on_wire::alert_channel_kind(k)),
label: states::present(states::plain(k, states::text("label", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn machine_session(k: usize, received: bool) -> wire::MachineSession {
let mut message = wire::MachineSession {
session_id: states::present(states::plain(k, states::text("session_id", k))),
kind: states::set(on_wire::machine_session_kind(k + 1)),
project_id: states::present(states::plain(k, states::text("project_id", k))),
service: states::present(states::plain(k, states::text("service", k))),
port: states::present(states::plain(k, states::number(5, k))),
start_time: states::maybe(k, states::time_on_wire(states::number(6, k + 5))).into(),
client_address: states::present(states::plain(k, states::text("client_address", k))),
ssh_key_label: states::present(states::plain(k, states::text("ssh_key_label", k))),
ssh_key_fingerprint: states::present(states::plain(k, states::text("ssh_key_fingerprint", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn disk_usage(k: usize, received: bool) -> wire::DiskUsage {
let mut message = wire::DiskUsage {
images_bytes: states::present(states::plain(k, u64::from(states::number(1, k)) << 44)),
build_cache_bytes: states::marked(k, u64::from(states::number(2, k)) << 44),
volumes_bytes: states::present(states::plain(k, u64::from(states::number(3, k)) << 44)),
container_layers_bytes: states::present(states::plain(k, u64::from(states::number(4, k)) << 44)),
project_files_bytes: states::present(states::plain(k, u64::from(states::number(5, k)) << 44)),
container_logs_bytes: states::present(states::plain(k, u64::from(states::number(6, k)) << 44)),
http_traffic_bytes: states::present(states::plain(k, u64::from(states::number(7, k)) << 44)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn ssh_key(k: usize, received: bool) -> wire::SshKey {
let mut message = wire::SshKey {
public_key: states::present(states::plain(k, states::text("public_key", k))),
label: states::present(states::plain(k, states::text("label", k))),
fingerprint: states::present(states::plain(k, states::text("fingerprint", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn github_connection(k: usize, received: bool) -> wire::GithubConnection {
let mut message = wire::GithubConnection {
app_name: states::present(states::plain(k, states::text("app_name", k))),
install_url: states::present(states::plain(k, states::text("install_url", k))),
repositories: states::many(
k,
[
on_wire::github_repository(k + 2, received),
on_wire::github_repository(k + 3, received),
],
),
repository_count: states::present(states::plain(k, states::number(4, k))),
webhooks_enabled: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn github_repository(k: usize, received: bool) -> wire::GithubRepository {
let mut message = wire::GithubRepository {
repository: states::present(states::plain(k, states::text("repository", k))),
default_branch: states::present(states::plain(k, states::text("default_branch", k))),
private: states::present(states::flag(1, k)),
push_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn deleted_project(k: usize, received: bool) -> wire::DeletedProject {
let mut message = wire::DeletedProject {
project_id: states::present(states::plain(k, states::text("project_id", k))),
newest_snapshot: states::maybe(k, on_wire::snapshot(k + 1, received)).into(),
snapshot_count: states::present(states::plain(k, states::number(3, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_machine_action_request(k: usize, received: bool) -> wire::RunMachineActionRequest {
let mut message = wire::RunMachineActionRequest {
action: match k % 12 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::run_machine_action_request::Action::AddSshKey(
Box::new(on_wire::ssh_key(k, received)),
)),
3 => Some(
wire::__buffa::oneof::run_machine_action_request::Action::RemoveSshKeyFingerprint(states::text(
"remove_ssh_key_fingerprint",
k,
)),
),
4 => Some(
wire::__buffa::oneof::run_machine_action_request::Action::RestartMachine(Box::new(
on_wire::restart_machine_action(k, received),
)),
),
5 => Some(wire::__buffa::oneof::run_machine_action_request::Action::CancelRestart(
true,
)),
6 => Some(wire::__buffa::oneof::run_machine_action_request::Action::EndSessionId(
states::text("end_session_id", k),
)),
7 => Some(wire::__buffa::oneof::run_machine_action_request::Action::AddSshKey(
Default::default(),
)),
8 => Some(
wire::__buffa::oneof::run_machine_action_request::Action::RemoveSshKeyFingerprint(
Default::default(),
),
),
9 => Some(wire::__buffa::oneof::run_machine_action_request::Action::RestartMachine(Default::default())),
10 => Some(wire::__buffa::oneof::run_machine_action_request::Action::CancelRestart(
Default::default(),
)),
_ => Some(wire::__buffa::oneof::run_machine_action_request::Action::EndSessionId(
Default::default(),
)),
},
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn restart_machine_action(k: usize, received: bool) -> wire::RestartMachineAction {
let mut message = wire::RestartMachineAction {
restart_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
at_maintenance_window: states::present(states::flag(1, k)),
interrupt_operations: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_machine_action_response(k: usize, received: bool) -> wire::RunMachineActionResponse {
let mut message = wire::RunMachineActionResponse {
machine: states::maybe(k, on_wire::machine(k, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_metadata(k: usize, received: bool) -> wire::ProjectMetadata {
let mut message = wire::ProjectMetadata {
name: states::marked(k, states::text("name", k)),
emoji: states::marked(k, states::text("emoji", k)),
description: states::marked(k, states::text("description", k)),
notes: states::marked(k, states::text("notes", k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_summary(k: usize, received: bool) -> wire::ProjectSummary {
let mut message = wire::ProjectSummary {
project_id: states::present(states::plain(k, states::text("project_id", k))),
metadata: states::maybe(k, on_wire::project_metadata(k + 1, received)).into(),
problems: states::many(
k,
[
on_wire::project_problem(k + 2, received),
on_wire::project_problem(k + 3, received),
],
),
services: states::many(
k,
[
on_wire::service_summary(k + 3, received),
on_wire::service_summary(k + 4, received),
],
),
url: states::present(states::plain(k, states::text("url", k))),
hosts: states::many(k, [states::text("hosts", k), states::text("hosts", k + 1)]),
http_traffic_last_day: states::maybe(k, on_wire::http_traffic_summary(k + 6, received)).into(),
cpu_used_cores: states::present(states::plain(k, f64::from(states::number(8, k)) + 0.5)),
memory_used_bytes: states::present(states::plain(k, u64::from(states::number(9, k)) << 44)),
deploy_time: states::maybe(k, states::time_on_wire(states::number(10, k + 9))).into(),
running_operations: states::many(
k,
[
on_wire::operation(k + 10, received),
on_wire::operation(k + 11, received),
],
),
pinned: states::present(states::flag(1, k)),
disk_used_bytes: states::present(states::plain(k, u64::from(states::number(13, k)) << 44)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn service_summary(k: usize, received: bool) -> wire::ServiceSummary {
let mut message = wire::ServiceSummary {
service: states::present(states::plain(k, states::text("service", k))),
state: states::set(on_wire::service_state(k + 1)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_problem(k: usize, received: bool) -> wire::ProjectProblem {
let mut message = wire::ProjectProblem {
kind: states::set(on_wire::project_problem_kind(k)),
service: states::present(states::plain(k, states::text("service", k))),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
since_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
problem_message: states::present(states::plain(k, states::text("problem_message", k))),
incident_id: states::present(states::plain(k, states::text("incident_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn get_project_request(k: usize, received: bool) -> wire::GetProjectRequest {
let mut message = wire::GetProjectRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
include_secret_values: states::present(states::flag(1, k)),
snapshots_before: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
snapshots_volume: states::present(states::plain(k, states::text("snapshots_volume", k))),
incidents_before: states::maybe(k, states::time_on_wire(states::number(5, k + 4))).into(),
uptime_day_count: states::present(states::plain(k, states::number(6, k))),
incidents_before_id: states::present(states::plain(k, states::text("incidents_before_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn get_project_response(k: usize, received: bool) -> wire::GetProjectResponse {
let mut message = wire::GetProjectResponse {
project: states::maybe(k, on_wire::project(k, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project(k: usize, received: bool) -> wire::Project {
let mut message = wire::Project {
project_id: states::present(states::plain(k, states::text("project_id", k))),
metadata: states::maybe(k, on_wire::project_metadata(k + 1, received)).into(),
problems: states::many(
k,
[
on_wire::project_problem(k + 2, received),
on_wire::project_problem(k + 3, received),
],
),
url: states::present(states::plain(k, states::text("url", k))),
cpu_used_cores: states::present(states::plain(k, f64::from(states::number(5, k)) + 0.5)),
memory_used_bytes: states::present(states::plain(k, u64::from(states::number(6, k)) << 44)),
deploy_id: states::present(states::plain(k, states::text("deploy_id", k))),
deploy_status: states::set(on_wire::operation_status(k + 7)),
deploy_time: states::maybe(k, states::time_on_wire(states::number(8, k + 8))).into(),
x_pethost_applies_at_once: states::present(states::flag(1, k)),
services: states::many(
k,
[on_wire::service(k + 10, received), on_wire::service(k + 11, received)],
),
volumes: states::many(
k,
[on_wire::volume(k + 11, received), on_wire::volume(k + 12, received)],
),
routes: states::many(k, [on_wire::route(k + 12, received), on_wire::route(k + 13, received)]),
hosts: states::many(k, [on_wire::host(k + 13, received), on_wire::host(k + 14, received)]),
password_protected: states::present(states::flag(2, k)),
operations: states::many(
k,
[
on_wire::operation(k + 15, received),
on_wire::operation(k + 16, received),
],
),
snapshots: states::many(
k,
[on_wire::snapshot(k + 16, received), on_wire::snapshot(k + 17, received)],
),
snapshot_count: states::present(states::plain(k, states::number(15, k))),
snapshot_list_time: states::maybe(k, states::time_on_wire(states::number(20, k + 18))).into(),
http_traffic_last_day: states::maybe(k, on_wire::http_traffic_summary(k + 19, received)).into(),
source: states::maybe(k, on_wire::project_source(k + 20, received)).into(),
running_services_action: states::maybe(k, on_wire::running_services_action(k + 21, received)).into(),
alerts: states::maybe(k, on_wire::project_alerts(k + 22, received)).into(),
incidents: states::many(
k,
[on_wire::incident(k + 23, received), on_wire::incident(k + 24, received)],
),
more_incidents: states::present(states::flag(3, k)),
uptime_days: states::many(
k,
[
on_wire::uptime_day(k + 25, received),
on_wire::uptime_day(k + 26, received),
],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn running_services_action(k: usize, received: bool) -> wire::RunningServicesAction {
let mut message = wire::RunningServicesAction {
kind: states::set(on_wire::services_action_kind(k)),
services: states::many(k, [states::text("services", k), states::text("services", k + 1)]),
start_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_source(k: usize, received: bool) -> wire::ProjectSource {
let mut message = wire::ProjectSource {
kind: match k % 6 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::project_source::Kind::Files(true)),
3 => Some(wire::__buffa::oneof::project_source::Kind::Github(Box::new(
on_wire::github_source(k, received),
))),
4 => Some(wire::__buffa::oneof::project_source::Kind::Files(Default::default())),
_ => Some(wire::__buffa::oneof::project_source::Kind::Github(Default::default())),
},
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn github_source(k: usize, received: bool) -> wire::GithubSource {
let mut message = wire::GithubSource {
repository: states::marked(k, states::text("repository", k)),
branch: states::marked(k, states::text("branch", k)),
directory: states::marked(k, states::text("directory", k)),
auto_deploy: states::marked(k, true),
newest_commit: states::maybe(k, on_wire::github_commit(k + 4, received)).into(),
deployed_commit: states::maybe(k, on_wire::github_commit(k + 5, received)).into(),
pinned: states::present(states::flag(1, k)),
auto_deploy_pending: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn github_commit(k: usize, received: bool) -> wire::GithubCommit {
let mut message = wire::GithubCommit {
sha: states::present(states::plain(k, states::text("sha", k))),
title: states::present(states::plain(k, states::text("title", k))),
url: states::present(states::plain(k, states::text("url", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn service(k: usize, received: bool) -> wire::Service {
let mut message = wire::Service {
service: states::present(states::plain(k, states::text("service", k))),
state: states::set(on_wire::service_state(k + 1)),
container_running: states::present(states::flag(1, k)),
image: states::present(states::plain(k, states::text("image", k))),
builds_image: states::present(states::flag(2, k)),
image_digest: states::present(states::plain(k, states::text("image_digest", k))),
image_size_bytes: states::present(states::plain(k, u64::from(states::number(6, k)) << 44)),
command: states::many(k, [states::text("command", k), states::text("command", k + 1)]),
run_as_user: states::present(states::plain(k, states::text("run_as_user", k))),
start_time: states::maybe(k, states::time_on_wire(states::number(9, k + 9))).into(),
finish_time: states::maybe(k, states::time_on_wire(states::number(10, k + 10))).into(),
exit_code: states::marked(k, -(states::number(11, k) as i32)),
out_of_memory: states::present(states::flag(3, k)),
restart_count: states::present(states::plain(k, states::number(13, k))),
cpu_used_cores: states::present(states::plain(k, f64::from(states::number(14, k)) + 0.5)),
memory_used_bytes: states::present(states::plain(k, u64::from(states::number(15, k)) << 44)),
memory_limit_bytes: states::present(states::plain(k, u64::from(states::number(16, k)) << 44)),
cpu_limit_cores: states::present(states::plain(k, f64::from(states::number(17, k)) + 0.5)),
writable_layer_bytes: states::present(states::plain(k, u64::from(states::number(18, k)) << 44)),
ports: states::many(k, [states::number(19, k), states::number(19, k + 1)]),
listening_ports: states::many(k, [states::number(28, k), states::number(28, k + 1)]),
published_ports: states::many(
k,
[
on_wire::published_port(k + 21, received),
on_wire::published_port(k + 22, received),
],
),
volume_mounts: states::many(
k,
[
on_wire::volume_mount(k + 22, received),
on_wire::volume_mount(k + 23, received),
],
),
restart_policy: states::set(on_wire::restart_policy(k + 23)),
health_check: states::maybe(k, on_wire::health_check(k + 24, received)).into(),
environment: states::many(
k,
[
on_wire::environment_variable(k + 25, received),
on_wire::environment_variable(k + 26, received),
],
),
env_files: states::many(k, [states::text("env_files", k), states::text("env_files", k + 1)]),
ssh_command: states::present(states::plain(k, states::text("ssh_command", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn published_port(k: usize, received: bool) -> wire::PublishedPort {
let mut message = wire::PublishedPort {
machine_port: states::present(states::plain(k, states::number(1, k))),
container_port: states::present(states::plain(k, states::number(2, k))),
protocol: states::present(states::plain(k, states::text("protocol", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn volume_mount(k: usize, received: bool) -> wire::VolumeMount {
let mut message = wire::VolumeMount {
volume: states::present(states::plain(k, states::text("volume", k))),
container_path: states::present(states::plain(k, states::text("container_path", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn health_check(k: usize, received: bool) -> wire::HealthCheck {
let mut message = wire::HealthCheck {
command: states::many(k, [states::text("command", k), states::text("command", k + 1)]),
interval_seconds: states::present(states::plain(k, states::number(2, k))),
status: states::set(on_wire::health_status(k + 2)),
consecutive_failure_count: states::present(states::plain(k, states::number(4, k))),
recent_results_passed: states::many(k, [true, true]),
last_failure_output: states::present(states::plain(k, states::text("last_failure_output", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn environment_variable(k: usize, received: bool) -> wire::EnvironmentVariable {
let mut message = wire::EnvironmentVariable {
name: states::present(states::plain(k, states::text("name", k))),
value: states::present(states::plain(k, states::text("value", k))),
secret: states::present(states::flag(1, k)),
source_file: states::present(states::plain(k, states::text("source_file", k))),
from_env_file_variables: states::many(
k,
[
states::text("from_env_file_variables", k),
states::text("from_env_file_variables", k + 1),
],
),
value_left_out: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn volume(k: usize, received: bool) -> wire::Volume {
let mut message = wire::Volume {
volume: states::present(states::plain(k, states::text("volume", k))),
size_bytes: states::present(states::plain(k, u64::from(states::number(2, k)) << 44)),
mounted_by: states::many(
k,
[
on_wire::volume_mounted_by(k + 2, received),
on_wire::volume_mounted_by(k + 3, received),
],
),
last_backup_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
snapshot_count: states::present(states::plain(k, states::number(6, k))),
declared: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn volume_mounted_by(k: usize, received: bool) -> wire::VolumeMountedBy {
let mut message = wire::VolumeMountedBy {
service: states::present(states::plain(k, states::text("service", k))),
container_path: states::present(states::plain(k, states::text("container_path", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn host(k: usize, received: bool) -> wire::Host {
let mut message = wire::Host {
host: states::present(states::plain(k, states::text("host", k))),
url: states::present(states::plain(k, states::text("url", k))),
certificate_source: states::set(on_wire::certificate_source(k + 2)),
certificate_expire_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
unavailable_message: states::present(states::plain(k, states::text("unavailable_message", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn route(k: usize, received: bool) -> wire::Route {
let mut message = wire::Route {
host: states::present(states::plain(k, states::text("host", k))),
path: states::present(states::plain(k, states::text("path", k))),
service: states::present(states::plain(k, states::text("service", k))),
port: states::present(states::plain(k, states::number(4, k))),
strip_path: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn operation(k: usize, received: bool) -> wire::Operation {
let mut message = wire::Operation {
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
kind: states::set(on_wire::operation_kind(k + 1)),
status: states::set(on_wire::operation_status(k + 2)),
start_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
finish_time: states::maybe(k, states::time_on_wire(states::number(5, k + 4))).into(),
failure_message: states::present(states::plain(k, states::text("failure_message", k))),
deploy_failure_reason: states::set(on_wire::deploy_failure_reason(k + 6)),
made_current: states::present(states::flag(1, k)),
service: states::present(states::plain(k, states::text("service", k))),
failed_exit_code: states::present(states::plain(k, -(states::number(10, k) as i32))),
snapshot_id: states::present(states::plain(k, states::text("snapshot_id", k))),
restored_volumes: states::many(
k,
[
states::text("restored_volumes", k),
states::text("restored_volumes", k + 1),
],
),
undo_snapshot_id: states::present(states::plain(k, states::text("undo_snapshot_id", k))),
github_commit: states::maybe(k, on_wire::github_commit(k + 13, received)).into(),
archive_name: states::present(states::plain(k, states::text("archive_name", k))),
adjustments: states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]),
changed_paths: states::many(
k,
[states::text("changed_paths", k), states::text("changed_paths", k + 1)],
),
changed_path_count: states::present(states::plain(k, states::number(18, k))),
files_kept: states::present(states::flag(2, k)),
files_operation_id: states::present(states::plain(k, states::text("files_operation_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn snapshot(k: usize, received: bool) -> wire::Snapshot {
let mut message = wire::Snapshot {
snapshot_id: states::present(states::plain(k, states::text("snapshot_id", k))),
create_time: states::maybe(k, states::time_on_wire(states::number(2, k + 1))).into(),
size_bytes: states::present(states::plain(k, u64::from(states::number(3, k)) << 44)),
volumes: states::many(k, [states::text("volumes", k), states::text("volumes", k + 1)]),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn http_traffic_summary(k: usize, received: bool) -> wire::HttpTrafficSummary {
let mut message = wire::HttpTrafficSummary {
request_count: states::present(states::plain(k, u64::from(states::number(1, k)) << 44)),
server_error_count: states::present(states::plain(k, u64::from(states::number(2, k)) << 44)),
latency_p50_ms: states::present(states::plain(k, states::number(3, k))),
latency_p95_ms: states::present(states::plain(k, states::number(4, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn create_project_request(k: usize, received: bool) -> wire::CreateProjectRequest {
let mut message = wire::CreateProjectRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
source: states::maybe(k, on_wire::project_source(k + 1, received)).into(),
upload_id: states::present(states::plain(k, states::text("upload_id", k))),
files: states::many(
k,
[
on_wire::file_change(k + 3, received),
on_wire::file_change(k + 4, received),
],
),
x_pethost: states::maybe(k, on_wire::project_extension(k + 4, received)).into(),
timeout_seconds: states::present(states::plain(k, states::number(6, k))),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
wait_seconds: states::marked(k, states::number(9, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn create_project_response(k: usize, received: bool) -> wire::CreateProjectResponse {
let mut message = wire::CreateProjectResponse {
operation: states::maybe(k, on_wire::operation(k, received)).into(),
violations: states::many(
k,
[
on_wire::spec_violation(k + 1, received),
on_wire::spec_violation(k + 2, received),
],
),
adjustments: states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]),
project: states::maybe(k, on_wire::project(k + 3, received)).into(),
log: states::many(
k,
[
on_wire::operation_log_line(k + 4, received),
on_wire::operation_log_line(k + 5, received),
],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn deploy_project_request(k: usize, received: bool) -> wire::DeployProjectRequest {
let mut message = wire::DeployProjectRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
base_deploy_id: states::present(states::plain(k, states::text("base_deploy_id", k))),
files: states::many(
k,
[
on_wire::file_change(k + 2, received),
on_wire::file_change(k + 3, received),
],
),
x_pethost: states::maybe(k, on_wire::project_extension(k + 3, received)).into(),
mount_volume: states::maybe(k, on_wire::mount_volume(k + 4, received)).into(),
timeout_seconds: states::present(states::plain(k, states::number(4, k))),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
version: match k % 10 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::deploy_project_request::Version::UploadId(
states::text("upload_id", k),
)),
3 => Some(wire::__buffa::oneof::deploy_project_request::Version::Commit(
states::text("commit", k),
)),
4 => Some(wire::__buffa::oneof::deploy_project_request::Version::NewestCommit(
true,
)),
5 => Some(wire::__buffa::oneof::deploy_project_request::Version::RollbackDeployId(
states::text("rollback_deploy_id", k),
)),
6 => Some(wire::__buffa::oneof::deploy_project_request::Version::UploadId(
Default::default(),
)),
7 => Some(wire::__buffa::oneof::deploy_project_request::Version::Commit(
Default::default(),
)),
8 => Some(wire::__buffa::oneof::deploy_project_request::Version::NewestCommit(
Default::default(),
)),
_ => Some(wire::__buffa::oneof::deploy_project_request::Version::RollbackDeployId(
Default::default(),
)),
},
wait_seconds: states::marked(k, states::number(13, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn mount_volume(k: usize, received: bool) -> wire::MountVolume {
let mut message = wire::MountVolume {
service: states::present(states::plain(k, states::text("service", k))),
volume: states::present(states::plain(k, states::text("volume", k))),
container_path: states::present(states::plain(k, states::text("container_path", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_extension(k: usize, received: bool) -> wire::ProjectExtension {
let mut message = wire::ProjectExtension {
metadata: states::maybe(k, on_wire::project_metadata(k, received)).into(),
routes: states::many(k, [on_wire::route(k + 1, received), on_wire::route(k + 2, received)]),
remove_routes: states::present(states::flag(1, k)),
password: states::present(states::plain(k, states::text("password", k))),
remove_password: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn file_change(k: usize, received: bool) -> wire::FileChange {
let mut message = wire::FileChange {
path: states::present(states::plain(k, states::text("path", k))),
change: match k % 14 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::file_change::Change::Text(states::text("text", k))),
3 => Some(wire::__buffa::oneof::file_change::Change::Data(
states::text("data", k).into_bytes(),
)),
4 => Some(wire::__buffa::oneof::file_change::Change::MakeDirectory(true)),
5 => Some(wire::__buffa::oneof::file_change::Change::Delete(true)),
6 => Some(wire::__buffa::oneof::file_change::Change::DeleteTree(true)),
7 => Some(wire::__buffa::oneof::file_change::Change::RenameTo(states::text(
"rename_to",
k,
))),
8 => Some(wire::__buffa::oneof::file_change::Change::Text(Default::default())),
9 => Some(wire::__buffa::oneof::file_change::Change::Data(Default::default())),
10 => Some(wire::__buffa::oneof::file_change::Change::MakeDirectory(
Default::default(),
)),
11 => Some(wire::__buffa::oneof::file_change::Change::Delete(Default::default())),
12 => Some(wire::__buffa::oneof::file_change::Change::DeleteTree(Default::default())),
_ => Some(wire::__buffa::oneof::file_change::Change::RenameTo(Default::default())),
},
executable: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn deploy_project_response(k: usize, received: bool) -> wire::DeployProjectResponse {
let mut message = wire::DeployProjectResponse {
operation: states::maybe(k, on_wire::operation(k, received)).into(),
violations: states::many(
k,
[
on_wire::spec_violation(k + 1, received),
on_wire::spec_violation(k + 2, received),
],
),
adjustments: states::many(k, [states::text("adjustments", k), states::text("adjustments", k + 1)]),
project: states::maybe(k, on_wire::project(k + 3, received)).into(),
log: states::many(
k,
[
on_wire::operation_log_line(k + 4, received),
on_wire::operation_log_line(k + 5, received),
],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn spec_violation(k: usize, received: bool) -> wire::SpecViolation {
let mut message = wire::SpecViolation {
service: states::present(states::plain(k, states::text("service", k))),
location: states::present(states::plain(k, states::text("location", k))),
violation_message: states::present(states::plain(k, states::text("violation_message", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn list_commits_request(k: usize, received: bool) -> wire::ListCommitsRequest {
let mut message = wire::ListCommitsRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
before_commit: states::present(states::plain(k, states::text("before_commit", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn list_commits_response(k: usize, received: bool) -> wire::ListCommitsResponse {
let mut message = wire::ListCommitsResponse {
commits: states::many(
k,
[
on_wire::branch_commit(k, received),
on_wire::branch_commit(k + 1, received),
],
),
more: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn branch_commit(k: usize, received: bool) -> wire::BranchCommit {
let mut message = wire::BranchCommit {
commit: states::maybe(k, on_wire::github_commit(k, received)).into(),
author: states::present(states::plain(k, states::text("author", k))),
commit_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
deployed: states::present(states::flag(1, k)),
last_deploy: states::maybe(k, on_wire::operation(k + 4, received)).into(),
newest: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_project_action_request(k: usize, received: bool) -> wire::RunProjectActionRequest {
let mut message = wire::RunProjectActionRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
action: match k % 22 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::run_project_action_request::Action::StartServices(
Box::new(on_wire::services_action(k, received)),
)),
3 => Some(wire::__buffa::oneof::run_project_action_request::Action::StopServices(
Box::new(on_wire::services_action(k, received)),
)),
4 => Some(
wire::__buffa::oneof::run_project_action_request::Action::RestartServices(Box::new(
on_wire::services_action(k, received),
)),
),
5 => Some(
wire::__buffa::oneof::run_project_action_request::Action::RecreateService(Box::new(
on_wire::recreate_service_action(k, received),
)),
),
6 => Some(wire::__buffa::oneof::run_project_action_request::Action::BackUp(
Box::new(on_wire::back_up_action(k, received)),
)),
7 => Some(
wire::__buffa::oneof::run_project_action_request::Action::RestoreSnapshot(Box::new(
on_wire::restore_snapshot_action(k, received),
)),
),
8 => Some(
wire::__buffa::oneof::run_project_action_request::Action::CancelOperation(Box::new(
on_wire::cancel_operation_action(k, received),
)),
),
9 => Some(wire::__buffa::oneof::run_project_action_request::Action::DeleteProject(
Box::new(on_wire::delete_project_action(k, received)),
)),
10 => Some(wire::__buffa::oneof::run_project_action_request::Action::SetSource(
Box::new(on_wire::project_source(k, received)),
)),
11 => Some(wire::__buffa::oneof::run_project_action_request::Action::DeleteVolume(
states::text("delete_volume", k),
)),
12 => Some(wire::__buffa::oneof::run_project_action_request::Action::StartServices(
Default::default(),
)),
13 => Some(wire::__buffa::oneof::run_project_action_request::Action::StopServices(
Default::default(),
)),
14 => {
Some(wire::__buffa::oneof::run_project_action_request::Action::RestartServices(Default::default()))
}
15 => {
Some(wire::__buffa::oneof::run_project_action_request::Action::RecreateService(Default::default()))
}
16 => Some(wire::__buffa::oneof::run_project_action_request::Action::BackUp(
Default::default(),
)),
17 => {
Some(wire::__buffa::oneof::run_project_action_request::Action::RestoreSnapshot(Default::default()))
}
18 => {
Some(wire::__buffa::oneof::run_project_action_request::Action::CancelOperation(Default::default()))
}
19 => Some(wire::__buffa::oneof::run_project_action_request::Action::DeleteProject(
Default::default(),
)),
20 => Some(wire::__buffa::oneof::run_project_action_request::Action::SetSource(
Default::default(),
)),
_ => Some(wire::__buffa::oneof::run_project_action_request::Action::DeleteVolume(
Default::default(),
)),
},
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
wait_seconds: states::marked(k, states::number(13, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn services_action(k: usize, received: bool) -> wire::ServicesAction {
let mut message = wire::ServicesAction {
services: states::many(k, [states::text("services", k), states::text("services", k + 1)]),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn recreate_service_action(k: usize, received: bool) -> wire::RecreateServiceAction {
let mut message = wire::RecreateServiceAction {
service: states::present(states::plain(k, states::text("service", k))),
pull_latest_image: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn back_up_action(k: usize, received: bool) -> wire::BackUpAction {
let mut message = wire::BackUpAction { ..Default::default() };
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn restore_snapshot_action(k: usize, received: bool) -> wire::RestoreSnapshotAction {
let mut message = wire::RestoreSnapshotAction {
snapshot_id: states::present(states::plain(k, states::text("snapshot_id", k))),
volumes: states::many(k, [states::text("volumes", k), states::text("volumes", k + 1)]),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn cancel_operation_action(k: usize, received: bool) -> wire::CancelOperationAction {
let mut message = wire::CancelOperationAction {
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn delete_project_action(k: usize, received: bool) -> wire::DeleteProjectAction {
let mut message = wire::DeleteProjectAction {
skip_final_backup: states::present(states::flag(1, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_project_action_response(k: usize, received: bool) -> wire::RunProjectActionResponse {
let mut message = wire::RunProjectActionResponse {
operation: states::maybe(k, on_wire::operation(k, received)).into(),
project: states::maybe(k, on_wire::project(k + 1, received)).into(),
log: states::many(
k,
[
on_wire::operation_log_line(k + 2, received),
on_wire::operation_log_line(k + 3, received),
],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn set_project_alerts_request(k: usize, received: bool) -> wire::SetProjectAlertsRequest {
let mut message = wire::SetProjectAlertsRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
checks: states::many(
k,
[
on_wire::site_check(k + 1, received),
on_wire::site_check(k + 2, received),
],
),
remove_checks: states::present(states::flag(1, k)),
traffic_rules: states::many(
k,
[
on_wire::traffic_rule(k + 3, received),
on_wire::traffic_rule(k + 4, received),
],
),
remove_traffic_rules: states::present(states::flag(2, k)),
off: states::marked(k, true),
mute_minutes: states::marked(k, states::number(7, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn set_project_alerts_response(k: usize, received: bool) -> wire::SetProjectAlertsResponse {
let mut message = wire::SetProjectAlertsResponse {
alerts: states::maybe(k, on_wire::project_alerts(k, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn site_check(k: usize, received: bool) -> wire::SiteCheck {
let mut message = wire::SiteCheck {
host: states::present(states::plain(k, states::text("host", k))),
path: states::present(states::plain(k, states::text("path", k))),
expect_status: states::present(states::plain(k, states::number(3, k))),
must_contain: states::present(states::plain(k, states::text("must_contain", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn traffic_rule(k: usize, received: bool) -> wire::TrafficRule {
let mut message = wire::TrafficRule {
metric: states::set(on_wire::traffic_metric(k)),
filter: states::maybe(k, on_wire::http_traffic_filter(k + 1, received)).into(),
threshold: states::present(states::plain(k, f64::from(states::number(3, k)) + 0.5)),
window_minutes: states::present(states::plain(k, states::number(4, k))),
min_requests: states::present(states::plain(k, states::number(5, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_alerts(k: usize, received: bool) -> wire::ProjectAlerts {
let mut message = wire::ProjectAlerts {
checks: states::many(
k,
[
on_wire::site_check_state(k, received),
on_wire::site_check_state(k + 1, received),
],
),
traffic_rules: states::many(
k,
[
on_wire::traffic_rule_state(k + 1, received),
on_wire::traffic_rule_state(k + 2, received),
],
),
off: states::present(states::flag(1, k)),
mute_end_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
uptime_percent: states::marked(k, f64::from(states::number(5, k)) + 0.5),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn site_check_state(k: usize, received: bool) -> wire::SiteCheckState {
let mut message = wire::SiteCheckState {
check: states::maybe(k, on_wire::site_check(k, received)).into(),
machine_default: states::present(states::flag(1, k)),
status: states::set(on_wire::alert_status(k + 2)),
last_result: states::maybe(k, on_wire::site_check_result(k + 3, received)).into(),
incident_id: states::present(states::plain(k, states::text("incident_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn site_check_result(k: usize, received: bool) -> wire::SiteCheckResult {
let mut message = wire::SiteCheckResult {
check_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
status: states::present(states::plain(k, states::number(2, k))),
duration_ms: states::present(states::plain(k, states::number(3, k))),
failure_message: states::present(states::plain(k, states::text("failure_message", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn traffic_rule_state(k: usize, received: bool) -> wire::TrafficRuleState {
let mut message = wire::TrafficRuleState {
rule: states::maybe(k, on_wire::traffic_rule(k, received)).into(),
machine_default: states::present(states::flag(1, k)),
status: states::set(on_wire::alert_status(k + 2)),
value: states::present(states::plain(k, f64::from(states::number(4, k)) + 0.5)),
request_count: states::present(states::plain(k, u64::from(states::number(5, k)) << 44)),
incident_id: states::present(states::plain(k, states::text("incident_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn incident(k: usize, received: bool) -> wire::Incident {
let mut message = wire::Incident {
incident_id: states::present(states::plain(k, states::text("incident_id", k))),
kind: states::set(on_wire::project_problem_kind(k + 1)),
service: states::present(states::plain(k, states::text("service", k))),
check: states::maybe(k, on_wire::site_check(k + 3, received)).into(),
traffic_rule: states::maybe(k, on_wire::traffic_rule(k + 4, received)).into(),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
open_time: states::maybe(k, states::time_on_wire(states::number(7, k + 6))).into(),
resolve_time: states::maybe(k, states::time_on_wire(states::number(8, k + 7))).into(),
value: states::present(states::plain(k, f64::from(states::number(9, k)) + 0.5)),
request_count: states::present(states::plain(k, u64::from(states::number(10, k)) << 44)),
after_operation_id: states::present(states::plain(k, states::text("after_operation_id", k))),
after_operation_end_time: states::maybe(k, states::time_on_wire(states::number(12, k + 11))).into(),
joined_incident_id: states::present(states::plain(k, states::text("joined_incident_id", k))),
quiet_reason: states::set(on_wire::incident_quiet_reason(k + 13)),
flapping: states::present(states::flag(1, k)),
incident_message: states::present(states::plain(k, states::text("incident_message", k))),
evidence: states::maybe(k, on_wire::incident_evidence(k + 16, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn incident_evidence(k: usize, received: bool) -> wire::IncidentEvidence {
let mut message = wire::IncidentEvidence {
check_result: states::maybe(k, on_wire::site_check_result(k, received)).into(),
exit_code: states::present(states::plain(k, -(states::number(2, k) as i32))),
oom_killed: states::present(states::flag(1, k)),
restart_count: states::present(states::plain(k, states::number(4, k))),
health_output: states::present(states::plain(k, states::text("health_output", k))),
log_lines: states::many(
k,
[on_wire::log_line(k + 5, received), on_wire::log_line(k + 6, received)],
),
top_path: states::maybe(k, on_wire::http_path_traffic(k + 6, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn uptime_day(k: usize, received: bool) -> wire::UptimeDay {
let mut message = wire::UptimeDay {
start_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
uptime_percent: states::marked(k, f64::from(states::number(2, k)) + 0.5),
down_seconds: states::present(states::plain(k, states::number(3, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn get_operation_request(k: usize, received: bool) -> wire::GetOperationRequest {
let mut message = wire::GetOperationRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
wait_seconds: states::marked(k, states::number(3, k)),
after_log_line: states::marked(k, states::number(4, k)),
log_line_limit: states::marked(k, states::number(5, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn get_operation_response(k: usize, received: bool) -> wire::GetOperationResponse {
let mut message = wire::GetOperationResponse {
operation: states::maybe(k, on_wire::operation(k, received)).into(),
project: states::maybe(k, on_wire::project(k + 1, received)).into(),
log: states::many(
k,
[
on_wire::operation_log_line(k + 2, received),
on_wire::operation_log_line(k + 3, received),
],
),
log_line_count: states::present(states::plain(k, states::number(3, k))),
next_after_log_line: states::present(states::plain(k, states::number(4, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn operation_log_line(k: usize, received: bool) -> wire::OperationLogLine {
let mut message = wire::OperationLogLine {
time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
text: states::present(states::plain(k, states::text("text", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn http_traffic_filter(k: usize, received: bool) -> wire::HttpTrafficFilter {
let mut message = wire::HttpTrafficFilter {
host: states::present(states::plain(k, states::text("host", k))),
method: states::present(states::plain(k, states::text("method", k))),
path_contains: states::present(states::plain(k, states::text("path_contains", k))),
path_pattern: states::present(states::plain(k, states::text("path_pattern", k))),
status_class: states::present(states::plain(k, states::number(5, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn query_http_traffic_request(k: usize, received: bool) -> wire::QueryHttpTrafficRequest {
let mut message = wire::QueryHttpTrafficRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
filter: states::maybe(k, on_wire::http_traffic_filter(k + 1, received)).into(),
start_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
end_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
last_seconds: states::present(states::plain(k, states::number(8, k))),
bucket_width_seconds: states::present(states::plain(k, states::number(5, k))),
request_limit: states::present(states::plain(k, states::number(6, k))),
page_token: states::present(states::plain(k, states::text("page_token", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn query_http_traffic_response(k: usize, received: bool) -> wire::QueryHttpTrafficResponse {
let mut message = wire::QueryHttpTrafficResponse {
start_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
end_time: states::maybe(k, states::time_on_wire(states::number(2, k + 1))).into(),
oldest_kept_time: states::maybe(k, states::time_on_wire(states::number(8, k + 2))).into(),
summary: states::maybe(k, on_wire::http_traffic_summary(k + 3, received)).into(),
buckets: states::many(
k,
[
on_wire::http_traffic_bucket(k + 4, received),
on_wire::http_traffic_bucket(k + 5, received),
],
),
top_paths: states::many(
k,
[
on_wire::http_path_traffic(k + 5, received),
on_wire::http_path_traffic(k + 6, received),
],
),
newest_sequence: states::present(states::plain(k, u64::from(states::number(9, k)) << 44)),
requests: states::many(
k,
[
on_wire::http_request(k + 7, received),
on_wire::http_request(k + 8, received),
],
),
next_page_token: states::present(states::plain(k, states::text("next_page_token", k))),
tail_sequence: states::present(states::plain(k, u64::from(states::number(10, k)) << 44)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn http_traffic_bucket(k: usize, received: bool) -> wire::HttpTrafficBucket {
let mut message = wire::HttpTrafficBucket {
start_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
summary: states::maybe(k, on_wire::http_traffic_summary(k + 1, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn http_path_traffic(k: usize, received: bool) -> wire::HttpPathTraffic {
let mut message = wire::HttpPathTraffic {
method: states::present(states::plain(k, states::text("method", k))),
path_pattern: states::present(states::plain(k, states::text("path_pattern", k))),
summary: states::maybe(k, on_wire::http_traffic_summary(k + 2, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn http_request(k: usize, received: bool) -> wire::HttpRequest {
let mut message = wire::HttpRequest {
sequence: states::present(states::plain(k, u64::from(states::number(1, k)) << 44)),
finish_time: states::maybe(k, states::time_on_wire(states::number(2, k + 1))).into(),
host: states::present(states::plain(k, states::text("host", k))),
method: states::present(states::plain(k, states::text("method", k))),
path: states::present(states::plain(k, states::text("path", k))),
path_pattern: states::present(states::plain(k, states::text("path_pattern", k))),
route_path: states::present(states::plain(k, states::text("route_path", k))),
service: states::present(states::plain(k, states::text("service", k))),
port: states::present(states::plain(k, states::number(9, k))),
status_code: states::present(states::plain(k, states::number(10, k))),
response_size_bytes: states::present(states::plain(k, u64::from(states::number(11, k)) << 44)),
duration_ms: states::present(states::plain(k, states::number(12, k))),
service_duration_ms: states::present(states::plain(k, states::number(13, k))),
client_ip_address: states::present(states::plain(k, states::text("client_ip_address", k))),
user_agent: states::present(states::plain(k, states::text("user_agent", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn container_log_filter(k: usize, received: bool) -> wire::ContainerLogFilter {
let mut message = wire::ContainerLogFilter {
service: states::present(states::plain(k, states::text("service", k))),
stream: states::set(on_wire::output_stream(k + 1)),
text_contains: states::present(states::plain(k, states::text("text_contains", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn query_container_logs_request(k: usize, received: bool) -> wire::QueryContainerLogsRequest {
let mut message = wire::QueryContainerLogsRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
filter: states::maybe(k, on_wire::container_log_filter(k + 1, received)).into(),
start_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
end_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
last_seconds: states::present(states::plain(k, states::number(8, k))),
limit: states::present(states::plain(k, states::number(5, k))),
from_start: states::present(states::flag(1, k)),
page_token: states::present(states::plain(k, states::text("page_token", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn query_container_logs_response(k: usize, received: bool) -> wire::QueryContainerLogsResponse {
let mut message = wire::QueryContainerLogsResponse {
start_time: states::maybe(k, states::time_on_wire(states::number(4, k))).into(),
end_time: states::maybe(k, states::time_on_wire(states::number(5, k + 1))).into(),
oldest_kept_time: states::maybe(k, states::time_on_wire(states::number(6, k + 2))).into(),
lines: states::many(
k,
[on_wire::log_line(k + 3, received), on_wire::log_line(k + 4, received)],
),
next_page_token: states::present(states::plain(k, states::text("next_page_token", k))),
tail_cursor: states::present(states::plain(k, states::text("tail_cursor", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn log_line(k: usize, received: bool) -> wire::LogLine {
let mut message = wire::LogLine {
time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
service: states::present(states::plain(k, states::text("service", k))),
stream: states::set(on_wire::output_stream(k + 2)),
text: states::present(states::plain(k, states::text("text", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_service_command_request(k: usize, received: bool) -> wire::RunServiceCommandRequest {
let mut message = wire::RunServiceCommandRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
service: states::present(states::plain(k, states::text("service", k))),
command: states::many(k, [states::text("command", k), states::text("command", k + 1)]),
stdin: states::present(states::plain(k, states::text("stdin", k))),
run_as_user: states::present(states::plain(k, states::text("run_as_user", k))),
working_directory: states::present(states::plain(k, states::text("working_directory", k))),
timeout_seconds: states::present(states::plain(k, states::number(7, k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn run_service_command_response(k: usize, received: bool) -> wire::RunServiceCommandResponse {
let mut message = wire::RunServiceCommandResponse {
exit_code: states::present(states::plain(k, -(states::number(1, k) as i32))),
timed_out: states::present(states::flag(1, k)),
stdout: states::present(states::plain(k, states::text("stdout", k))),
stderr: states::present(states::plain(k, states::text("stderr", k))),
output_truncated: states::present(states::flag(2, k)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn file_entry(k: usize, received: bool) -> wire::FileEntry {
let mut message = wire::FileEntry {
name: states::present(states::plain(k, states::text("name", k))),
r#type: states::set(on_wire::file_type(k + 1)),
size_bytes: states::present(states::plain(k, u64::from(states::number(3, k)) << 44)),
modify_time: states::maybe(k, states::time_on_wire(states::number(4, k + 3))).into(),
mode: states::present(states::plain(k, states::text("mode", k))),
owner_uid: states::present(states::plain(k, states::number(6, k))),
owner_gid: states::present(states::plain(k, states::number(7, k))),
symlink_target: states::present(states::plain(k, states::text("symlink_target", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn read_path_request(k: usize, received: bool) -> wire::ReadPathRequest {
let mut message = wire::ReadPathRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
root: match k % 6 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::read_path_request::Root::Service(states::text(
"service", k,
))),
3 => Some(wire::__buffa::oneof::read_path_request::Root::Volume(states::text(
"volume", k,
))),
4 => Some(wire::__buffa::oneof::read_path_request::Root::Service(
Default::default(),
)),
_ => Some(wire::__buffa::oneof::read_path_request::Root::Volume(Default::default())),
},
path: states::present(states::plain(k, states::text("path", k))),
entry_limit: states::present(states::plain(k, states::number(6, k))),
offset_bytes: states::present(states::plain(k, u64::from(states::number(7, k)) << 44)),
length_bytes: states::present(states::plain(k, states::number(8, k))),
entry_page_token: states::present(states::plain(k, states::text("entry_page_token", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn read_path_response(k: usize, received: bool) -> wire::ReadPathResponse {
let mut message = wire::ReadPathResponse {
entry: states::maybe(k, on_wire::file_entry(k, received)).into(),
location: states::set(on_wire::file_location(k + 1)),
volume: states::present(states::plain(k, states::text("volume", k))),
entries: states::many(
k,
[
on_wire::file_entry(k + 3, received),
on_wire::file_entry(k + 4, received),
],
),
entry_count: states::present(states::plain(k, states::number(4, k))),
next_entry_page_token: states::present(states::plain(k, states::text("next_entry_page_token", k))),
text: states::present(states::plain(k, states::text("text", k))),
binary: states::present(states::flag(1, k)),
next_offset_bytes: states::present(states::plain(k, u64::from(states::number(7, k)) << 44)),
deploy_id: states::present(states::plain(k, states::text("deploy_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn create_transfer_request(k: usize, received: bool) -> wire::CreateTransferRequest {
let mut message = wire::CreateTransferRequest {
transfer: match k % 8 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadArchive(
Box::new(on_wire::archive_upload(k, received)),
)),
3 => Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadFile(
Box::new(on_wire::file_upload(k, received)),
)),
4 => Some(wire::__buffa::oneof::create_transfer_request::Transfer::Download(
Box::new(on_wire::path_download(k, received)),
)),
5 => Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadArchive(
Default::default(),
)),
6 => Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadFile(
Default::default(),
)),
_ => Some(wire::__buffa::oneof::create_transfer_request::Transfer::Download(
Default::default(),
)),
},
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn archive_upload(k: usize, received: bool) -> wire::ArchiveUpload {
let mut message = wire::ArchiveUpload {
file_name: states::present(states::plain(k, states::text("file_name", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn file_upload(k: usize, received: bool) -> wire::FileUpload {
let mut message = wire::FileUpload {
project_id: states::present(states::plain(k, states::text("project_id", k))),
root: match k % 6 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::file_upload::Root::Service(states::text(
"service", k,
))),
3 => Some(wire::__buffa::oneof::file_upload::Root::Volume(states::text(
"volume", k,
))),
4 => Some(wire::__buffa::oneof::file_upload::Root::Service(Default::default())),
_ => Some(wire::__buffa::oneof::file_upload::Root::Volume(Default::default())),
},
path: states::present(states::plain(k, states::text("path", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn path_download(k: usize, received: bool) -> wire::PathDownload {
let mut message = wire::PathDownload {
project_id: states::present(states::plain(k, states::text("project_id", k))),
root: match k % 6 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::path_download::Root::Service(states::text(
"service", k,
))),
3 => Some(wire::__buffa::oneof::path_download::Root::Volume(states::text(
"volume", k,
))),
4 => Some(wire::__buffa::oneof::path_download::Root::Service(Default::default())),
_ => Some(wire::__buffa::oneof::path_download::Root::Volume(Default::default())),
},
path: states::present(states::plain(k, states::text("path", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn create_transfer_response(k: usize, received: bool) -> wire::CreateTransferResponse {
let mut message = wire::CreateTransferResponse {
url: states::present(states::plain(k, states::text("url", k))),
http_method: states::present(states::plain(k, states::text("http_method", k))),
expire_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
command: states::present(states::plain(k, states::text("command", k))),
upload_id: states::present(states::plain(k, states::text("upload_id", k))),
replaces: states::present(states::flag(1, k)),
file_name: states::present(states::plain(k, states::text("file_name", k))),
exclude_names: states::many(
k,
[states::text("exclude_names", k), states::text("exclude_names", k + 1)],
),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_busy(k: usize, received: bool) -> wire::ProjectBusy {
let mut message = wire::ProjectBusy {
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
kind: states::set(on_wire::operation_kind(k + 1)),
start_time: states::maybe(k, states::time_on_wire(states::number(3, k + 2))).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn project_changed(k: usize, received: bool) -> wire::ProjectChanged {
let mut message = wire::ProjectChanged { ..Default::default() };
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn machine_unreachable(k: usize, received: bool) -> wire::MachineUnreachable {
let mut message = wire::MachineUnreachable {
since_time: states::maybe(k, states::time_on_wire(states::number(1, k))).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn machine_update_pending(k: usize, received: bool) -> wire::MachineUpdatePending {
let mut message = wire::MachineUpdatePending { ..Default::default() };
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn no_machine(k: usize, received: bool) -> wire::NoMachine {
let mut message = wire::NoMachine {
reason: states::set(on_wire::no_machine_reason(k)),
url: states::present(states::plain(k, states::text("url", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn watch_operation_request(k: usize, received: bool) -> wire::WatchOperationRequest {
let mut message = wire::WatchOperationRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
operation_id: states::present(states::plain(k, states::text("operation_id", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn watch_operation_response(k: usize, received: bool) -> wire::WatchOperationResponse {
let mut message = wire::WatchOperationResponse {
message: match k % 6 {
0 | 1 => None,
2 => Some(wire::__buffa::oneof::watch_operation_response::Message::Log(Box::new(
on_wire::operation_log_line(k, received),
))),
3 => Some(
wire::__buffa::oneof::watch_operation_response::Message::FinishedOperation(Box::new(
on_wire::operation(k, received),
)),
),
4 => Some(wire::__buffa::oneof::watch_operation_response::Message::Log(
Default::default(),
)),
_ => {
Some(wire::__buffa::oneof::watch_operation_response::Message::FinishedOperation(Default::default()))
}
},
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn tail_container_logs_request(k: usize, received: bool) -> wire::TailContainerLogsRequest {
let mut message = wire::TailContainerLogsRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
filter: states::maybe(k, on_wire::container_log_filter(k + 1, received)).into(),
after_cursor: states::present(states::plain(k, states::text("after_cursor", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn tail_container_logs_response(k: usize, received: bool) -> wire::TailContainerLogsResponse {
let mut message = wire::TailContainerLogsResponse {
line: states::maybe(k, on_wire::log_line(k, received)).into(),
cursor: states::present(states::plain(k, states::text("cursor", k))),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn tail_http_traffic_request(k: usize, received: bool) -> wire::TailHttpTrafficRequest {
let mut message = wire::TailHttpTrafficRequest {
project_id: states::present(states::plain(k, states::text("project_id", k))),
filter: states::maybe(k, on_wire::http_traffic_filter(k + 1, received)).into(),
after_sequence: states::present(states::plain(k, u64::from(states::number(3, k)) << 44)),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
pub fn tail_http_traffic_response(k: usize, received: bool) -> wire::TailHttpTrafficResponse {
let mut message = wire::TailHttpTrafficResponse {
request: states::maybe(k, on_wire::http_request(k, received)).into(),
..Default::default()
};
if received && k % 2 == 1 {
message.__buffa_unknown_fields.push(states::later_field());
}
message
}
}
#[tokio::test]
async fn get_machine_request_is_sent() {
for k in 0..2 {
let request = samples::get_machine_request(k, true);
let expected = on_wire::get_machine_request(k, false);
let answer = ok(&wire::GetMachineResponse::default());
let call = |client: Client| async move { client.get_machine(request).await };
let (sent, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::GetMachineResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn run_machine_action_request_is_sent() {
for k in 0..12 {
let request = samples::run_machine_action_request(k, true);
let expected = on_wire::run_machine_action_request(k, false);
let answer = ok(&wire::RunMachineActionResponse::default());
let call = |client: Client| async move { client.run_machine_action(request).await };
let (sent, response): (wire::RunMachineActionRequest, _) = exchange("RunMachineAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunMachineActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn get_project_request_is_sent() {
for k in 0..2 {
let request = samples::get_project_request(k, true);
let expected = on_wire::get_project_request(k, false);
let answer = ok(&wire::GetProjectResponse::default());
let call = |client: Client| async move { client.get_project(request).await };
let (sent, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::GetProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn create_project_request_is_sent() {
for k in 0..3 {
let request = samples::create_project_request(k, true);
let expected = on_wire::create_project_request(k, false);
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn deploy_project_request_is_sent() {
for k in 0..10 {
let request = samples::deploy_project_request(k, true);
let expected = on_wire::deploy_project_request(k, false);
let answer = ok(&wire::DeployProjectResponse::default());
let call = |client: Client| async move { client.deploy_project(request).await };
let (sent, response): (wire::DeployProjectRequest, _) = exchange("DeployProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::DeployProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn list_commits_request_is_sent() {
for k in 0..2 {
let request = samples::list_commits_request(k, true);
let expected = on_wire::list_commits_request(k, false);
let answer = ok(&wire::ListCommitsResponse::default());
let call = |client: Client| async move { client.list_commits(request).await };
let (sent, response): (wire::ListCommitsRequest, _) = exchange("ListCommits", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::ListCommitsResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn run_project_action_request_is_sent() {
for k in 0..22 {
let request = samples::run_project_action_request(k, true);
let expected = on_wire::run_project_action_request(k, false);
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn set_project_alerts_request_is_sent() {
for k in 0..3 {
let request = samples::set_project_alerts_request(k, true);
let expected = on_wire::set_project_alerts_request(k, false);
let answer = ok(&wire::SetProjectAlertsResponse::default());
let call = |client: Client| async move { client.set_project_alerts(request).await };
let (sent, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::SetProjectAlertsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn get_operation_request_is_sent() {
for k in 0..3 {
let request = samples::get_operation_request(k, true);
let expected = on_wire::get_operation_request(k, false);
let answer = ok(&wire::GetOperationResponse::default());
let call = |client: Client| async move { client.get_operation(request).await };
let (sent, response): (wire::GetOperationRequest, _) = exchange("GetOperation", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::GetOperationResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn query_http_traffic_request_is_sent() {
for k in 0..2 {
let request = samples::query_http_traffic_request(k, true);
let expected = on_wire::query_http_traffic_request(k, false);
let answer = ok(&wire::QueryHttpTrafficResponse::default());
let call = |client: Client| async move { client.query_http_traffic(request).await };
let (sent, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::QueryHttpTrafficResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn query_container_logs_request_is_sent() {
for k in 0..2 {
let request = samples::query_container_logs_request(k, true);
let expected = on_wire::query_container_logs_request(k, false);
let answer = ok(&wire::QueryContainerLogsResponse::default());
let call = |client: Client| async move { client.query_container_logs(request).await };
let (sent, response): (wire::QueryContainerLogsRequest, _) = exchange("QueryContainerLogs", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::QueryContainerLogsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn run_service_command_request_is_sent() {
for k in 0..2 {
let request = samples::run_service_command_request(k, true);
let expected = on_wire::run_service_command_request(k, false);
let answer = ok(&wire::RunServiceCommandResponse::default());
let call = |client: Client| async move { client.run_service_command(request).await };
let (sent, response): (wire::RunServiceCommandRequest, _) = exchange("RunServiceCommand", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunServiceCommandResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn read_path_request_is_sent() {
for k in 0..6 {
let request = samples::read_path_request(k, true);
let expected = on_wire::read_path_request(k, false);
let answer = ok(&wire::ReadPathResponse::default());
let call = |client: Client| async move { client.read_path(request).await };
let (sent, response): (wire::ReadPathRequest, _) = exchange("ReadPath", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::ReadPathResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn create_transfer_request_is_sent() {
for k in 0..8 {
let request = samples::create_transfer_request(k, true);
let expected = on_wire::create_transfer_request(k, false);
let answer = ok(&wire::CreateTransferResponse::default());
let call = |client: Client| async move { client.create_transfer(request).await };
let (sent, response): (wire::CreateTransferRequest, _) = exchange("CreateTransfer", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::CreateTransferResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn watch_operation_request_is_sent() {
for k in 0..2 {
let request = samples::watch_operation_request(k, true);
let expected = on_wire::watch_operation_request(k, false);
let answer = streamed(&[wire::WatchOperationResponse::default()], End::Clean);
let call = |client: Client| async move { first(client.watch_operation(request)).await };
let (sent, response): (wire::WatchOperationRequest, _) = exchange("WatchOperation", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::WatchOperationResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn tail_container_logs_request_is_sent() {
for k in 0..2 {
let request = samples::tail_container_logs_request(k, true);
let expected = on_wire::tail_container_logs_request(k, false);
let answer = streamed(&[wire::TailContainerLogsResponse::default()], End::Clean);
let call = |client: Client| async move { first(client.tail_container_logs(request)).await };
let (sent, response): (wire::TailContainerLogsRequest, _) = exchange("TailContainerLogs", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::TailContainerLogsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn tail_http_traffic_request_is_sent() {
for k in 0..2 {
let request = samples::tail_http_traffic_request(k, true);
let expected = on_wire::tail_http_traffic_request(k, false);
let answer = streamed(&[wire::TailHttpTrafficResponse::default()], End::Clean);
let call = |client: Client| async move { first(client.tail_http_traffic(request)).await };
let (sent, response): (wire::TailHttpTrafficRequest, _) = exchange("TailHttpTraffic", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::TailHttpTrafficResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn ssh_key_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunMachineActionRequest| {
message.action = Some(types::RunMachineActionRequestAction::AddSshKey(samples::ssh_key(
k, true,
)))
});
let expected = states::make(|message: &mut wire::RunMachineActionRequest| {
message.action = Some(wire::__buffa::oneof::run_machine_action_request::Action::AddSshKey(
Box::new(on_wire::ssh_key(k, false)),
))
});
let answer = ok(&wire::RunMachineActionResponse::default());
let call = |client: Client| async move { client.run_machine_action(request).await };
let (sent, response): (wire::RunMachineActionRequest, _) = exchange("RunMachineAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunMachineActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn restart_machine_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunMachineActionRequest| {
message.action = Some(types::RunMachineActionRequestAction::RestartMachine(
samples::restart_machine_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunMachineActionRequest| {
message.action = Some(
wire::__buffa::oneof::run_machine_action_request::Action::RestartMachine(Box::new(
on_wire::restart_machine_action(k, false),
)),
)
});
let answer = ok(&wire::RunMachineActionResponse::default());
let call = |client: Client| async move { client.run_machine_action(request).await };
let (sent, response): (wire::RunMachineActionRequest, _) = exchange("RunMachineAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunMachineActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn project_source_is_sent() {
for k in 0..6 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.source = Some(samples::project_source(k, true))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.source = Some(on_wire::project_source(k, false)).into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn file_change_is_sent() {
for k in 0..14 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.files = vec![samples::file_change(k, true)]
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.files = vec![on_wire::file_change(k, false)]
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn project_extension_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.x_pethost = Some(samples::project_extension(k, true))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.x_pethost = Some(on_wire::project_extension(k, false)).into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn mount_volume_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::DeployProjectRequest| {
message.mount_volume = Some(samples::mount_volume(k, true))
});
let expected = states::make(|message: &mut wire::DeployProjectRequest| {
message.mount_volume = Some(on_wire::mount_volume(k, false)).into()
});
let answer = ok(&wire::DeployProjectResponse::default());
let call = |client: Client| async move { client.deploy_project(request).await };
let (sent, response): (wire::DeployProjectRequest, _) = exchange("DeployProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::DeployProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn services_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::StartServices(
samples::services_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(wire::__buffa::oneof::run_project_action_request::Action::StartServices(
Box::new(on_wire::services_action(k, false)),
))
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn recreate_service_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::RecreateService(
samples::recreate_service_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(
wire::__buffa::oneof::run_project_action_request::Action::RecreateService(Box::new(
on_wire::recreate_service_action(k, false),
)),
)
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn back_up_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::BackUp(samples::back_up_action(
k, true,
)))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(wire::__buffa::oneof::run_project_action_request::Action::BackUp(
Box::new(on_wire::back_up_action(k, false)),
))
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn restore_snapshot_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::RestoreSnapshot(
samples::restore_snapshot_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(
wire::__buffa::oneof::run_project_action_request::Action::RestoreSnapshot(Box::new(
on_wire::restore_snapshot_action(k, false),
)),
)
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn cancel_operation_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::CancelOperation(
samples::cancel_operation_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(
wire::__buffa::oneof::run_project_action_request::Action::CancelOperation(Box::new(
on_wire::cancel_operation_action(k, false),
)),
)
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn delete_project_action_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::RunProjectActionRequest| {
message.action = Some(types::RunProjectActionRequestAction::DeleteProject(
samples::delete_project_action(k, true),
))
});
let expected = states::make(|message: &mut wire::RunProjectActionRequest| {
message.action = Some(wire::__buffa::oneof::run_project_action_request::Action::DeleteProject(
Box::new(on_wire::delete_project_action(k, false)),
))
});
let answer = ok(&wire::RunProjectActionResponse::default());
let call = |client: Client| async move { client.run_project_action(request).await };
let (sent, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::RunProjectActionResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn site_check_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::SetProjectAlertsRequest| {
message.checks = vec![samples::site_check(k, true)]
});
let expected = states::make(|message: &mut wire::SetProjectAlertsRequest| {
message.checks = vec![on_wire::site_check(k, false)]
});
let answer = ok(&wire::SetProjectAlertsResponse::default());
let call = |client: Client| async move { client.set_project_alerts(request).await };
let (sent, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::SetProjectAlertsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn traffic_rule_is_sent() {
for k in 0..5 {
let request = states::make(|message: &mut types::SetProjectAlertsRequest| {
message.traffic_rules = vec![samples::traffic_rule(k, true)]
});
let expected = states::make(|message: &mut wire::SetProjectAlertsRequest| {
message.traffic_rules = vec![on_wire::traffic_rule(k, false)]
});
let answer = ok(&wire::SetProjectAlertsResponse::default());
let call = |client: Client| async move { client.set_project_alerts(request).await };
let (sent, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::SetProjectAlertsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn http_traffic_filter_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::QueryHttpTrafficRequest| {
message.filter = Some(samples::http_traffic_filter(k, true))
});
let expected = states::make(|message: &mut wire::QueryHttpTrafficRequest| {
message.filter = Some(on_wire::http_traffic_filter(k, false)).into()
});
let answer = ok(&wire::QueryHttpTrafficResponse::default());
let call = |client: Client| async move { client.query_http_traffic(request).await };
let (sent, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::QueryHttpTrafficResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn container_log_filter_is_sent() {
for k in 0..4 {
let request = states::make(|message: &mut types::QueryContainerLogsRequest| {
message.filter = Some(samples::container_log_filter(k, true))
});
let expected = states::make(|message: &mut wire::QueryContainerLogsRequest| {
message.filter = Some(on_wire::container_log_filter(k, false)).into()
});
let answer = ok(&wire::QueryContainerLogsResponse::default());
let call = |client: Client| async move { client.query_container_logs(request).await };
let (sent, response): (wire::QueryContainerLogsRequest, _) = exchange("QueryContainerLogs", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::QueryContainerLogsResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn archive_upload_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::CreateTransferRequest| {
message.transfer = Some(types::CreateTransferRequestTransfer::UploadArchive(
samples::archive_upload(k, true),
))
});
let expected = states::make(|message: &mut wire::CreateTransferRequest| {
message.transfer = Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadArchive(
Box::new(on_wire::archive_upload(k, false)),
))
});
let answer = ok(&wire::CreateTransferResponse::default());
let call = |client: Client| async move { client.create_transfer(request).await };
let (sent, response): (wire::CreateTransferRequest, _) = exchange("CreateTransfer", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::CreateTransferResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn file_upload_is_sent() {
for k in 0..6 {
let request = states::make(|message: &mut types::CreateTransferRequest| {
message.transfer = Some(types::CreateTransferRequestTransfer::UploadFile(samples::file_upload(
k, true,
)))
});
let expected = states::make(|message: &mut wire::CreateTransferRequest| {
message.transfer = Some(wire::__buffa::oneof::create_transfer_request::Transfer::UploadFile(
Box::new(on_wire::file_upload(k, false)),
))
});
let answer = ok(&wire::CreateTransferResponse::default());
let call = |client: Client| async move { client.create_transfer(request).await };
let (sent, response): (wire::CreateTransferRequest, _) = exchange("CreateTransfer", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::CreateTransferResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn path_download_is_sent() {
for k in 0..6 {
let request = states::make(|message: &mut types::CreateTransferRequest| {
message.transfer = Some(types::CreateTransferRequestTransfer::Download(samples::path_download(
k, true,
)))
});
let expected = states::make(|message: &mut wire::CreateTransferRequest| {
message.transfer = Some(wire::__buffa::oneof::create_transfer_request::Transfer::Download(
Box::new(on_wire::path_download(k, false)),
))
});
let answer = ok(&wire::CreateTransferResponse::default());
let call = |client: Client| async move { client.create_transfer(request).await };
let (sent, response): (wire::CreateTransferRequest, _) = exchange("CreateTransfer", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(
response.unwrap(),
types::CreateTransferResponse::default(),
"at k = {k}"
);
}
}
#[tokio::test]
async fn github_source_is_sent() {
for k in 0..3 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.source = Some(states::make(|message: &mut types::ProjectSource| {
message.kind = Some(types::ProjectSourceKind::Github(samples::github_source(k, true)))
}))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.source = Some(states::make(|message: &mut wire::ProjectSource| {
message.kind = Some(wire::__buffa::oneof::project_source::Kind::Github(Box::new(
on_wire::github_source(k, false),
)))
}))
.into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn project_metadata_is_sent() {
for k in 0..3 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.x_pethost = Some(states::make(|message: &mut types::ProjectExtension| {
message.metadata = Some(samples::project_metadata(k, true))
}))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.x_pethost = Some(states::make(|message: &mut wire::ProjectExtension| {
message.metadata = Some(on_wire::project_metadata(k, false)).into()
}))
.into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn route_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.x_pethost = Some(states::make(|message: &mut types::ProjectExtension| {
message.routes = vec![samples::route(k, true)]
}))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.x_pethost = Some(states::make(|message: &mut wire::ProjectExtension| {
message.routes = vec![on_wire::route(k, false)]
}))
.into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn github_commit_is_sent() {
for k in 0..2 {
let request = states::make(|message: &mut types::CreateProjectRequest| {
message.source = Some(states::make(|message: &mut types::ProjectSource| {
message.kind = Some(types::ProjectSourceKind::Github(states::make(
|message: &mut types::GithubSource| message.newest_commit = Some(samples::github_commit(k, true)),
)))
}))
});
let expected = states::make(|message: &mut wire::CreateProjectRequest| {
message.source = Some(states::make(|message: &mut wire::ProjectSource| {
message.kind = Some(wire::__buffa::oneof::project_source::Kind::Github(Box::new(
states::make(|message: &mut wire::GithubSource| {
message.newest_commit = Some(on_wire::github_commit(k, false)).into()
}),
)))
}))
.into()
});
let answer = ok(&wire::CreateProjectResponse::default());
let call = |client: Client| async move { client.create_project(request).await };
let (sent, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(sent, expected, "at k = {k}");
assert_eq!(response.unwrap(), types::CreateProjectResponse::default(), "at k = {k}");
}
}
#[tokio::test]
async fn get_machine_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::get_machine_response(k, true));
let expected = samples::get_machine_response(k, true);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn run_machine_action_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::run_machine_action_response(k, true));
let expected = samples::run_machine_action_response(k, true);
let call = |client: Client| async move {
client
.run_machine_action(types::RunMachineActionRequest::default())
.await
};
let (_, response): (wire::RunMachineActionRequest, _) = exchange("RunMachineAction", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn get_project_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::get_project_response(k, true));
let expected = samples::get_project_response(k, true);
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn create_project_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::create_project_response(k, true));
let expected = samples::create_project_response(k, true);
let call = |client: Client| async move { client.create_project(types::CreateProjectRequest::default()).await };
let (_, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn deploy_project_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::deploy_project_response(k, true));
let expected = samples::deploy_project_response(k, true);
let call = |client: Client| async move { client.deploy_project(types::DeployProjectRequest::default()).await };
let (_, response): (wire::DeployProjectRequest, _) = exchange("DeployProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn list_commits_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::list_commits_response(k, true));
let expected = samples::list_commits_response(k, true);
let call = |client: Client| async move { client.list_commits(types::ListCommitsRequest::default()).await };
let (_, response): (wire::ListCommitsRequest, _) = exchange("ListCommits", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn run_project_action_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::run_project_action_response(k, true));
let expected = samples::run_project_action_response(k, true);
let call = |client: Client| async move {
client
.run_project_action(types::RunProjectActionRequest::default())
.await
};
let (_, response): (wire::RunProjectActionRequest, _) = exchange("RunProjectAction", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn set_project_alerts_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::set_project_alerts_response(k, true));
let expected = samples::set_project_alerts_response(k, true);
let call = |client: Client| async move {
client
.set_project_alerts(types::SetProjectAlertsRequest::default())
.await
};
let (_, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn get_operation_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::get_operation_response(k, true));
let expected = samples::get_operation_response(k, true);
let call = |client: Client| async move { client.get_operation(types::GetOperationRequest::default()).await };
let (_, response): (wire::GetOperationRequest, _) = exchange("GetOperation", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn query_http_traffic_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::query_http_traffic_response(k, true));
let expected = samples::query_http_traffic_response(k, true);
let call = |client: Client| async move {
client
.query_http_traffic(types::QueryHttpTrafficRequest::default())
.await
};
let (_, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn query_container_logs_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::query_container_logs_response(k, true));
let expected = samples::query_container_logs_response(k, true);
let call = |client: Client| async move {
client
.query_container_logs(types::QueryContainerLogsRequest::default())
.await
};
let (_, response): (wire::QueryContainerLogsRequest, _) = exchange("QueryContainerLogs", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn run_service_command_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::run_service_command_response(k, true));
let expected = samples::run_service_command_response(k, true);
let call = |client: Client| async move {
client
.run_service_command(types::RunServiceCommandRequest::default())
.await
};
let (_, response): (wire::RunServiceCommandRequest, _) = exchange("RunServiceCommand", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn read_path_response_is_received() {
for k in 0..5 {
let answer = ok(&on_wire::read_path_response(k, true));
let expected = samples::read_path_response(k, true);
let call = |client: Client| async move { client.read_path(types::ReadPathRequest::default()).await };
let (_, response): (wire::ReadPathRequest, _) = exchange("ReadPath", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn create_transfer_response_is_received() {
for k in 0..2 {
let answer = ok(&on_wire::create_transfer_response(k, true));
let expected = samples::create_transfer_response(k, true);
let call =
|client: Client| async move { client.create_transfer(types::CreateTransferRequest::default()).await };
let (_, response): (wire::CreateTransferRequest, _) = exchange("CreateTransfer", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn watch_operation_response_is_received() {
for k in 0..6 {
let answer = streamed(&[on_wire::watch_operation_response(k, true)], End::Clean);
let expected = samples::watch_operation_response(k, true);
let call = |client: Client| async move {
first(client.watch_operation(types::WatchOperationRequest::default())).await
};
let (_, response): (wire::WatchOperationRequest, _) = exchange("WatchOperation", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn tail_container_logs_response_is_received() {
for k in 0..2 {
let answer = streamed(&[on_wire::tail_container_logs_response(k, true)], End::Clean);
let expected = samples::tail_container_logs_response(k, true);
let call = |client: Client| async move {
first(client.tail_container_logs(types::TailContainerLogsRequest::default())).await
};
let (_, response): (wire::TailContainerLogsRequest, _) = exchange("TailContainerLogs", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn tail_http_traffic_response_is_received() {
for k in 0..2 {
let answer = streamed(&[on_wire::tail_http_traffic_response(k, true)], End::Clean);
let expected = samples::tail_http_traffic_response(k, true);
let call = |client: Client| async move {
first(client.tail_http_traffic(types::TailHttpTrafficRequest::default())).await
};
let (_, response): (wire::TailHttpTrafficRequest, _) = exchange("TailHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_busy_is_received() {
for k in 0..7 {
let detail = on_wire::project_busy(k, true).encode_to_vec();
let expected = ErrorDetail::ProjectBusy(samples::project_busy(k, true));
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.ProjectBusy", detail.as_slice())],
&STANDARD_NO_PAD,
);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap_err().details(), [expected], "at k = {k}");
}
}
#[tokio::test]
async fn project_changed_is_received() {
for k in 0..2 {
let detail = on_wire::project_changed(k, true).encode_to_vec();
let expected = ErrorDetail::ProjectChanged(samples::project_changed(k, true));
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.ProjectChanged", detail.as_slice())],
&STANDARD_NO_PAD,
);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap_err().details(), [expected], "at k = {k}");
}
}
#[tokio::test]
async fn machine_unreachable_is_received() {
for k in 0..2 {
let detail = on_wire::machine_unreachable(k, true).encode_to_vec();
let expected = ErrorDetail::MachineUnreachable(samples::machine_unreachable(k, true));
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.MachineUnreachable", detail.as_slice())],
&STANDARD_NO_PAD,
);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap_err().details(), [expected], "at k = {k}");
}
}
#[tokio::test]
async fn machine_update_pending_is_received() {
for k in 0..2 {
let detail = on_wire::machine_update_pending(k, true).encode_to_vec();
let expected = ErrorDetail::MachineUpdatePending(samples::machine_update_pending(k, true));
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.MachineUpdatePending", detail.as_slice())],
&STANDARD_NO_PAD,
);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap_err().details(), [expected], "at k = {k}");
}
}
#[tokio::test]
async fn no_machine_is_received() {
for k in 0..4 {
let detail = on_wire::no_machine(k, true).encode_to_vec();
let expected = ErrorDetail::NoMachine(samples::no_machine(k, true));
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.NoMachine", detail.as_slice())],
&STANDARD_NO_PAD,
);
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap_err().details(), [expected], "at k = {k}");
}
}
#[tokio::test]
async fn machine_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.machine = Some(on_wire::machine(k, true)).into()
}));
let expected =
states::make(|message: &mut types::GetMachineResponse| message.machine = Some(samples::machine(k, true)));
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_summary_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.projects = vec![on_wire::project_summary(k, true)]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.projects = vec![samples::project_summary(k, true)]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn deleted_project_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.deleted_projects = vec![on_wire::deleted_project(k, true)]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.deleted_projects = vec![samples::deleted_project(k, true)]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn github_connection_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.github = Some(on_wire::github_connection(k, true)).into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.github = Some(samples::github_connection(k, true))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_is_received() {
for k in 0..6 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(on_wire::project(k, true)).into()
}));
let expected =
states::make(|message: &mut types::GetProjectResponse| message.project = Some(samples::project(k, true)));
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn operation_is_received() {
for k in 0..13 {
let answer = ok(&states::make(|message: &mut wire::CreateProjectResponse| {
message.operation = Some(on_wire::operation(k, true)).into()
}));
let expected = states::make(|message: &mut types::CreateProjectResponse| {
message.operation = Some(samples::operation(k, true))
});
let call = |client: Client| async move { client.create_project(types::CreateProjectRequest::default()).await };
let (_, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn spec_violation_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::CreateProjectResponse| {
message.violations = vec![on_wire::spec_violation(k, true)]
}));
let expected = states::make(|message: &mut types::CreateProjectResponse| {
message.violations = vec![samples::spec_violation(k, true)]
});
let call = |client: Client| async move { client.create_project(types::CreateProjectRequest::default()).await };
let (_, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn operation_log_line_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::CreateProjectResponse| {
message.log = vec![on_wire::operation_log_line(k, true)]
}));
let expected = states::make(|message: &mut types::CreateProjectResponse| {
message.log = vec![samples::operation_log_line(k, true)]
});
let call = |client: Client| async move { client.create_project(types::CreateProjectRequest::default()).await };
let (_, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn branch_commit_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::ListCommitsResponse| {
message.commits = vec![on_wire::branch_commit(k, true)]
}));
let expected = states::make(|message: &mut types::ListCommitsResponse| {
message.commits = vec![samples::branch_commit(k, true)]
});
let call = |client: Client| async move { client.list_commits(types::ListCommitsRequest::default()).await };
let (_, response): (wire::ListCommitsRequest, _) = exchange("ListCommits", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_alerts_is_received() {
for k in 0..3 {
let answer = ok(&states::make(|message: &mut wire::SetProjectAlertsResponse| {
message.alerts = Some(on_wire::project_alerts(k, true)).into()
}));
let expected = states::make(|message: &mut types::SetProjectAlertsResponse| {
message.alerts = Some(samples::project_alerts(k, true))
});
let call = |client: Client| async move {
client
.set_project_alerts(types::SetProjectAlertsRequest::default())
.await
};
let (_, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn http_traffic_summary_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::QueryHttpTrafficResponse| {
message.summary = Some(on_wire::http_traffic_summary(k, true)).into()
}));
let expected = states::make(|message: &mut types::QueryHttpTrafficResponse| {
message.summary = Some(samples::http_traffic_summary(k, true))
});
let call = |client: Client| async move {
client
.query_http_traffic(types::QueryHttpTrafficRequest::default())
.await
};
let (_, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn http_traffic_bucket_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::QueryHttpTrafficResponse| {
message.buckets = vec![on_wire::http_traffic_bucket(k, true)]
}));
let expected = states::make(|message: &mut types::QueryHttpTrafficResponse| {
message.buckets = vec![samples::http_traffic_bucket(k, true)]
});
let call = |client: Client| async move {
client
.query_http_traffic(types::QueryHttpTrafficRequest::default())
.await
};
let (_, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn http_path_traffic_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::QueryHttpTrafficResponse| {
message.top_paths = vec![on_wire::http_path_traffic(k, true)]
}));
let expected = states::make(|message: &mut types::QueryHttpTrafficResponse| {
message.top_paths = vec![samples::http_path_traffic(k, true)]
});
let call = |client: Client| async move {
client
.query_http_traffic(types::QueryHttpTrafficRequest::default())
.await
};
let (_, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn http_request_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::QueryHttpTrafficResponse| {
message.requests = vec![on_wire::http_request(k, true)]
}));
let expected = states::make(|message: &mut types::QueryHttpTrafficResponse| {
message.requests = vec![samples::http_request(k, true)]
});
let call = |client: Client| async move {
client
.query_http_traffic(types::QueryHttpTrafficRequest::default())
.await
};
let (_, response): (wire::QueryHttpTrafficRequest, _) = exchange("QueryHttpTraffic", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn log_line_is_received() {
for k in 0..4 {
let answer = ok(&states::make(|message: &mut wire::QueryContainerLogsResponse| {
message.lines = vec![on_wire::log_line(k, true)]
}));
let expected = states::make(|message: &mut types::QueryContainerLogsResponse| {
message.lines = vec![samples::log_line(k, true)]
});
let call = |client: Client| async move {
client
.query_container_logs(types::QueryContainerLogsRequest::default())
.await
};
let (_, response): (wire::QueryContainerLogsRequest, _) = exchange("QueryContainerLogs", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn file_entry_is_received() {
for k in 0..6 {
let answer = ok(&states::make(|message: &mut wire::ReadPathResponse| {
message.entry = Some(on_wire::file_entry(k, true)).into()
}));
let expected =
states::make(|message: &mut types::ReadPathResponse| message.entry = Some(samples::file_entry(k, true)));
let call = |client: Client| async move { client.read_path(types::ReadPathRequest::default()).await };
let (_, response): (wire::ReadPathRequest, _) = exchange("ReadPath", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn disk_usage_is_received() {
for k in 0..3 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut wire::Machine| {
message.disk_usage = Some(on_wire::disk_usage(k, true)).into()
}))
.into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut types::Machine| {
message.disk_usage = Some(samples::disk_usage(k, true))
}))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn ssh_key_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut wire::Machine| {
message.ssh_keys = vec![on_wire::ssh_key(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut types::Machine| {
message.ssh_keys = vec![samples::ssh_key(k, true)]
}))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn machine_session_is_received() {
for k in 0..7 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut wire::Machine| {
message.sessions = vec![on_wire::machine_session(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut types::Machine| {
message.sessions = vec![samples::machine_session(k, true)]
}))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn alert_destination_is_received() {
for k in 0..5 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut wire::Machine| {
message.alert_channels = vec![on_wire::alert_destination(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.machine = Some(states::make(|message: &mut types::Machine| {
message.alert_channels = vec![samples::alert_destination(k, true)]
}))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_metadata_is_received() {
for k in 0..3 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut wire::ProjectSummary| {
message.metadata = Some(on_wire::project_metadata(k, true)).into()
})]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut types::ProjectSummary| {
message.metadata = Some(samples::project_metadata(k, true))
})]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_problem_is_received() {
for k in 0..15 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut wire::ProjectSummary| {
message.problems = vec![on_wire::project_problem(k, true)]
})]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut types::ProjectSummary| {
message.problems = vec![samples::project_problem(k, true)]
})]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn service_summary_is_received() {
for k in 0..10 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut wire::ProjectSummary| {
message.services = vec![on_wire::service_summary(k, true)]
})]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.projects = vec![states::make(|message: &mut types::ProjectSummary| {
message.services = vec![samples::service_summary(k, true)]
})]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn snapshot_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.deleted_projects = vec![states::make(|message: &mut wire::DeletedProject| {
message.newest_snapshot = Some(on_wire::snapshot(k, true)).into()
})]
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.deleted_projects = vec![states::make(|message: &mut types::DeletedProject| {
message.newest_snapshot = Some(samples::snapshot(k, true))
})]
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn github_repository_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetMachineResponse| {
message.github = Some(states::make(|message: &mut wire::GithubConnection| {
message.repositories = vec![on_wire::github_repository(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetMachineResponse| {
message.github = Some(states::make(|message: &mut types::GithubConnection| {
message.repositories = vec![samples::github_repository(k, true)]
}))
});
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn service_is_received() {
for k in 0..10 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.services = vec![on_wire::service(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.services = vec![samples::service(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn volume_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.volumes = vec![on_wire::volume(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.volumes = vec![samples::volume(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn route_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.routes = vec![on_wire::route(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.routes = vec![samples::route(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn host_is_received() {
for k in 0..5 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.hosts = vec![on_wire::host(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.hosts = vec![samples::host(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn project_source_is_received() {
for k in 0..6 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.source = Some(on_wire::project_source(k, true)).into()
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.source = Some(samples::project_source(k, true))
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn running_services_action_is_received() {
for k in 0..5 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.running_services_action = Some(on_wire::running_services_action(k, true)).into()
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.running_services_action = Some(samples::running_services_action(k, true))
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn incident_is_received() {
for k in 0..15 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.incidents = vec![on_wire::incident(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.incidents = vec![samples::incident(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn uptime_day_is_received() {
for k in 0..3 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.uptime_days = vec![on_wire::uptime_day(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.uptime_days = vec![samples::uptime_day(k, true)]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn github_commit_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::CreateProjectResponse| {
message.operation = Some(states::make(|message: &mut wire::Operation| {
message.github_commit = Some(on_wire::github_commit(k, true)).into()
}))
.into()
}));
let expected = states::make(|message: &mut types::CreateProjectResponse| {
message.operation = Some(states::make(|message: &mut types::Operation| {
message.github_commit = Some(samples::github_commit(k, true))
}))
});
let call = |client: Client| async move { client.create_project(types::CreateProjectRequest::default()).await };
let (_, response): (wire::CreateProjectRequest, _) = exchange("CreateProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn site_check_state_is_received() {
for k in 0..7 {
let answer = ok(&states::make(|message: &mut wire::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut wire::ProjectAlerts| {
message.checks = vec![on_wire::site_check_state(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut types::ProjectAlerts| {
message.checks = vec![samples::site_check_state(k, true)]
}))
});
let call = |client: Client| async move {
client
.set_project_alerts(types::SetProjectAlertsRequest::default())
.await
};
let (_, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn traffic_rule_state_is_received() {
for k in 0..7 {
let answer = ok(&states::make(|message: &mut wire::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut wire::ProjectAlerts| {
message.traffic_rules = vec![on_wire::traffic_rule_state(k, true)]
}))
.into()
}));
let expected = states::make(|message: &mut types::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut types::ProjectAlerts| {
message.traffic_rules = vec![samples::traffic_rule_state(k, true)]
}))
});
let call = |client: Client| async move {
client
.set_project_alerts(types::SetProjectAlertsRequest::default())
.await
};
let (_, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn published_port_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.services = vec![states::make(|message: &mut wire::Service| {
message.published_ports = vec![on_wire::published_port(k, true)]
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.services = vec![states::make(|message: &mut types::Service| {
message.published_ports = vec![samples::published_port(k, true)]
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn volume_mount_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.services = vec![states::make(|message: &mut wire::Service| {
message.volume_mounts = vec![on_wire::volume_mount(k, true)]
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.services = vec![states::make(|message: &mut types::Service| {
message.volume_mounts = vec![samples::volume_mount(k, true)]
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn health_check_is_received() {
for k in 0..5 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.services = vec![states::make(|message: &mut wire::Service| {
message.health_check = Some(on_wire::health_check(k, true)).into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.services = vec![states::make(|message: &mut types::Service| {
message.health_check = Some(samples::health_check(k, true))
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn environment_variable_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.services = vec![states::make(|message: &mut wire::Service| {
message.environment = vec![on_wire::environment_variable(k, true)]
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.services = vec![states::make(|message: &mut types::Service| {
message.environment = vec![samples::environment_variable(k, true)]
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn volume_mounted_by_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.volumes = vec![states::make(|message: &mut wire::Volume| {
message.mounted_by = vec![on_wire::volume_mounted_by(k, true)]
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.volumes = vec![states::make(|message: &mut types::Volume| {
message.mounted_by = vec![samples::volume_mounted_by(k, true)]
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn github_source_is_received() {
for k in 0..3 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.source = Some(states::make(|message: &mut wire::ProjectSource| {
message.kind = Some(wire::__buffa::oneof::project_source::Kind::Github(Box::new(
on_wire::github_source(k, true),
)))
}))
.into()
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.source = Some(states::make(|message: &mut types::ProjectSource| {
message.kind = Some(types::ProjectSourceKind::Github(samples::github_source(k, true)))
}))
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn site_check_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.incidents = vec![states::make(|message: &mut wire::Incident| {
message.check = Some(on_wire::site_check(k, true)).into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.incidents = vec![states::make(|message: &mut types::Incident| {
message.check = Some(samples::site_check(k, true))
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn traffic_rule_is_received() {
for k in 0..5 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.incidents = vec![states::make(|message: &mut wire::Incident| {
message.traffic_rule = Some(on_wire::traffic_rule(k, true)).into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.incidents = vec![states::make(|message: &mut types::Incident| {
message.traffic_rule = Some(samples::traffic_rule(k, true))
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn incident_evidence_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.incidents = vec![states::make(|message: &mut wire::Incident| {
message.evidence = Some(on_wire::incident_evidence(k, true)).into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.incidents = vec![states::make(|message: &mut types::Incident| {
message.evidence = Some(samples::incident_evidence(k, true))
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn site_check_result_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut wire::ProjectAlerts| {
message.checks = vec![states::make(|message: &mut wire::SiteCheckState| {
message.last_result = Some(on_wire::site_check_result(k, true)).into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::SetProjectAlertsResponse| {
message.alerts = Some(states::make(|message: &mut types::ProjectAlerts| {
message.checks = vec![states::make(|message: &mut types::SiteCheckState| {
message.last_result = Some(samples::site_check_result(k, true))
})]
}))
});
let call = |client: Client| async move {
client
.set_project_alerts(types::SetProjectAlertsRequest::default())
.await
};
let (_, response): (wire::SetProjectAlertsRequest, _) = exchange("SetProjectAlerts", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
#[tokio::test]
async fn http_traffic_filter_is_received() {
for k in 0..2 {
let answer = ok(&states::make(|message: &mut wire::GetProjectResponse| {
message.project = Some(states::make(|message: &mut wire::Project| {
message.incidents = vec![states::make(|message: &mut wire::Incident| {
message.traffic_rule = Some(states::make(|message: &mut wire::TrafficRule| {
message.filter = Some(on_wire::http_traffic_filter(k, true)).into()
}))
.into()
})]
}))
.into()
}));
let expected = states::make(|message: &mut types::GetProjectResponse| {
message.project = Some(states::make(|message: &mut types::Project| {
message.incidents = vec![states::make(|message: &mut types::Incident| {
message.traffic_rule = Some(states::make(|message: &mut types::TrafficRule| {
message.filter = Some(samples::http_traffic_filter(k, true))
}))
})]
}))
});
let call = |client: Client| async move { client.get_project(types::GetProjectRequest::default()).await };
let (_, response): (wire::GetProjectRequest, _) = exchange("GetProject", answer, call).await;
assert_eq!(response.unwrap(), expected, "at k = {k}");
}
}
const LATER_FIELD: &str = "a_later_field";
const LATER_NAME: &str = "A_LATER_NAME";
fn with_a_later_field(json: &Value) -> Vec<Value> {
fn with<Key: serde_json::value::Index>(json: &Value, key: Key, inner: Value) -> Value {
let mut copy = json.clone();
copy[key] = inner;
copy
}
match json {
Value::Object(fields) => {
let deeper = fields.iter().flat_map(|(name, value)| {
let copies = with_a_later_field(value).into_iter();
copies.map(move |inner| with(json, name, inner))
});
std::iter::once(with(json, LATER_FIELD, Value::from(1)))
.chain(deeper)
.collect()
}
Value::Array(items) => {
let deeper = items.iter().enumerate().flat_map(|(place, item)| {
let copies = with_a_later_field(item).into_iter();
copies.map(move |inner| with(json, place, inner))
});
deeper.collect()
}
_ => Vec::new(),
}
}
fn with_wide_numbers(json: &Value) -> Value {
match json {
Value::String(digits) => match (digits.parse::<u64>(), digits.parse::<i64>()) {
(Ok(number), _) => Value::from(number),
(_, Ok(number)) => Value::from(number),
_ => json.clone(),
},
Value::Array(items) => items.iter().map(with_wide_numbers).collect(),
Value::Object(fields) => {
let fields = fields
.iter()
.map(|(name, value)| (name.clone(), with_wide_numbers(value)));
fields.collect()
}
_ => json.clone(),
}
}
fn a_message_is_json<Public, Wire>(
states: usize,
names: &[&str],
public: fn(usize, bool) -> Public,
wire: fn(usize, bool) -> Wire,
) where
Public: Serialize + DeserializeOwned + PartialEq + std::fmt::Debug,
Wire: Serialize,
{
let mut written = BTreeSet::new();
for k in 0..states {
let json = serde_json::to_value(wire(k, false)).unwrap();
assert_eq!(serde_json::to_value(public(k, true)).unwrap(), json, "at k = {k}");
assert_eq!(
serde_json::from_value::<Public>(json.clone()).unwrap(),
public(k, false),
"at k = {k}"
);
assert_eq!(
serde_json::from_value::<Public>(with_wide_numbers(&json)).unwrap(),
public(k, false),
"at k = {k}"
);
written.extend(json.as_object().unwrap().keys().cloned());
for later in with_a_later_field(&json) {
let refusal = serde_json::from_value::<Public>(later).unwrap_err().to_string();
assert!(refusal.contains(LATER_FIELD), "at k = {k}: {refusal}");
}
}
let names: BTreeSet<String> = names.iter().map(|name| name.to_string()).collect();
assert_eq!(written, names);
assert!(
serde_json::from_value::<Public>(Value::Array(Vec::new())).is_err(),
"a list was read as the message"
);
}
fn an_enum_is_json<Public>(names: &[&str], later: i32, sample: fn(usize) -> Public)
where
Public: Serialize + DeserializeOwned + PartialEq + std::fmt::Debug,
{
let forms = names.iter().map(|name| Value::from(*name)).chain([Value::from(later)]);
for (k, json) in forms.enumerate() {
assert_eq!(serde_json::to_value(sample(k)).unwrap(), json);
assert_eq!(serde_json::from_value::<Public>(json).unwrap(), sample(k));
}
assert!(serde_json::from_value::<Public>(Value::from(LATER_NAME)).is_err());
}
#[test]
fn alert_channel_kind_is_json() {
let names = [
"ALERT_CHANNEL_KIND_UNSPECIFIED",
"ALERT_CHANNEL_KIND_EMAIL",
"ALERT_CHANNEL_KIND_TELEGRAM",
"ALERT_CHANNEL_KIND_SLACK",
];
an_enum_is_json(&names, 4, samples::alert_channel_kind);
}
#[test]
fn machine_session_kind_is_json() {
let names = [
"MACHINE_SESSION_KIND_UNSPECIFIED",
"MACHINE_SESSION_KIND_WEB_TERMINAL",
"MACHINE_SESSION_KIND_SSH_TERMINAL",
"MACHINE_SESSION_KIND_SSH_COMMAND",
"MACHINE_SESSION_KIND_SFTP",
"MACHINE_SESSION_KIND_TUNNEL",
];
an_enum_is_json(&names, 6, samples::machine_session_kind);
}
#[test]
fn project_problem_kind_is_json() {
let names = [
"PROJECT_PROBLEM_KIND_UNSPECIFIED",
"PROJECT_PROBLEM_KIND_DEPLOY_FAILED",
"PROJECT_PROBLEM_KIND_SERVICE_UNHEALTHY",
"PROJECT_PROBLEM_KIND_SERVICE_RESTARTING",
"PROJECT_PROBLEM_KIND_SERVICE_OUT_OF_MEMORY",
"PROJECT_PROBLEM_KIND_BACKUP_FAILED",
"PROJECT_PROBLEM_KIND_DEPLOY_CANCELLED",
"PROJECT_PROBLEM_KIND_SERVICE_EXITED",
"PROJECT_PROBLEM_KIND_RESTORE_FAILED",
"PROJECT_PROBLEM_KIND_AUTO_DEPLOY_REFUSED",
"PROJECT_PROBLEM_KIND_SERVICE_PORT_CLOSED",
"PROJECT_PROBLEM_KIND_SITE_DOWN",
"PROJECT_PROBLEM_KIND_HTTP_ERRORS",
"PROJECT_PROBLEM_KIND_HTTP_SLOW",
];
an_enum_is_json(&names, 14, samples::project_problem_kind);
}
#[test]
fn services_action_kind_is_json() {
let names = [
"SERVICES_ACTION_KIND_UNSPECIFIED",
"SERVICES_ACTION_KIND_START",
"SERVICES_ACTION_KIND_STOP",
"SERVICES_ACTION_KIND_RESTART",
];
an_enum_is_json(&names, 4, samples::services_action_kind);
}
#[test]
fn service_state_is_json() {
let names = [
"SERVICE_STATE_UNSPECIFIED",
"SERVICE_STATE_NOT_CREATED",
"SERVICE_STATE_STARTING",
"SERVICE_STATE_RUNNING",
"SERVICE_STATE_HEALTHY",
"SERVICE_STATE_UNHEALTHY",
"SERVICE_STATE_RESTARTING",
"SERVICE_STATE_STOPPED",
"SERVICE_STATE_EXITED",
];
an_enum_is_json(&names, 9, samples::service_state);
}
#[test]
fn restart_policy_is_json() {
let names = [
"RESTART_POLICY_UNSPECIFIED",
"RESTART_POLICY_NO",
"RESTART_POLICY_ON_FAILURE",
"RESTART_POLICY_UNLESS_STOPPED",
"RESTART_POLICY_ALWAYS",
];
an_enum_is_json(&names, 5, samples::restart_policy);
}
#[test]
fn health_status_is_json() {
let names = [
"HEALTH_STATUS_UNSPECIFIED",
"HEALTH_STATUS_STARTING",
"HEALTH_STATUS_HEALTHY",
"HEALTH_STATUS_UNHEALTHY",
];
an_enum_is_json(&names, 4, samples::health_status);
}
#[test]
fn certificate_source_is_json() {
let names = [
"CERTIFICATE_SOURCE_UNSPECIFIED",
"CERTIFICATE_SOURCE_NONE",
"CERTIFICATE_SOURCE_INSTALLED",
"CERTIFICATE_SOURCE_AUTOMATIC",
];
an_enum_is_json(&names, 4, samples::certificate_source);
}
#[test]
fn operation_kind_is_json() {
let names = [
"OPERATION_KIND_UNSPECIFIED",
"OPERATION_KIND_DEPLOY",
"OPERATION_KIND_RECREATE_SERVICE",
"OPERATION_KIND_BACKUP",
"OPERATION_KIND_RESTORE",
"OPERATION_KIND_DELETE",
];
an_enum_is_json(&names, 6, samples::operation_kind);
}
#[test]
fn operation_status_is_json() {
let names = [
"OPERATION_STATUS_UNSPECIFIED",
"OPERATION_STATUS_IN_PROGRESS",
"OPERATION_STATUS_SUCCEEDED",
"OPERATION_STATUS_FAILED",
"OPERATION_STATUS_CANCELLED",
];
an_enum_is_json(&names, 5, samples::operation_status);
}
#[test]
fn deploy_failure_reason_is_json() {
let names = [
"DEPLOY_FAILURE_REASON_UNSPECIFIED",
"DEPLOY_FAILURE_REASON_IMAGE_PULL_FAILED",
"DEPLOY_FAILURE_REASON_IMAGE_BUILD_FAILED",
"DEPLOY_FAILURE_REASON_CONTAINER_START_FAILED",
"DEPLOY_FAILURE_REASON_DISK_FULL",
"DEPLOY_FAILURE_REASON_INTERNAL",
"DEPLOY_FAILURE_REASON_PORT_UNAVAILABLE",
"DEPLOY_FAILURE_REASON_CONTAINER_EXITED",
"DEPLOY_FAILURE_REASON_CONTAINER_UNHEALTHY",
"DEPLOY_FAILURE_REASON_TIMED_OUT",
"DEPLOY_FAILURE_REASON_UNCOVERED_IMAGE_VOLUME",
"DEPLOY_FAILURE_REASON_BUILD_MEMORY_UNAVAILABLE",
];
an_enum_is_json(&names, 12, samples::deploy_failure_reason);
}
#[test]
fn traffic_metric_is_json() {
let names = [
"TRAFFIC_METRIC_UNSPECIFIED",
"TRAFFIC_METRIC_SERVER_ERRORS",
"TRAFFIC_METRIC_SERVER_ERROR_PERCENT",
"TRAFFIC_METRIC_LATENCY_P95_MS",
];
an_enum_is_json(&names, 4, samples::traffic_metric);
}
#[test]
fn alert_status_is_json() {
let names = [
"ALERT_STATUS_UNSPECIFIED",
"ALERT_STATUS_OK",
"ALERT_STATUS_PENDING",
"ALERT_STATUS_FIRING",
"ALERT_STATUS_PAUSED",
"ALERT_STATUS_NO_DATA",
];
an_enum_is_json(&names, 6, samples::alert_status);
}
#[test]
fn incident_quiet_reason_is_json() {
let names = [
"INCIDENT_QUIET_REASON_UNSPECIFIED",
"INCIDENT_QUIET_REASON_MUTED",
"INCIDENT_QUIET_REASON_OFF",
"INCIDENT_QUIET_REASON_FIRST_EVALUATION",
"INCIDENT_QUIET_REASON_MANUAL_DEPLOY",
];
an_enum_is_json(&names, 5, samples::incident_quiet_reason);
}
#[test]
fn output_stream_is_json() {
let names = [
"OUTPUT_STREAM_UNSPECIFIED",
"OUTPUT_STREAM_STDOUT",
"OUTPUT_STREAM_STDERR",
];
an_enum_is_json(&names, 3, samples::output_stream);
}
#[test]
fn file_type_is_json() {
let names = [
"FILE_TYPE_UNSPECIFIED",
"FILE_TYPE_FILE",
"FILE_TYPE_DIRECTORY",
"FILE_TYPE_SYMLINK",
"FILE_TYPE_OTHER",
];
an_enum_is_json(&names, 5, samples::file_type);
}
#[test]
fn file_location_is_json() {
let names = [
"FILE_LOCATION_UNSPECIFIED",
"FILE_LOCATION_CONTAINER",
"FILE_LOCATION_VOLUME",
"FILE_LOCATION_PROJECT_FILES",
];
an_enum_is_json(&names, 4, samples::file_location);
}
#[test]
fn no_machine_reason_is_json() {
let names = [
"NO_MACHINE_REASON_UNSPECIFIED",
"NO_MACHINE_REASON_NO_PLAN",
"NO_MACHINE_REASON_BEING_PREPARED",
];
an_enum_is_json(&names, 3, samples::no_machine_reason);
}
#[test]
fn get_machine_request_is_json() {
let names = [];
a_message_is_json(2, &names, samples::get_machine_request, on_wire::get_machine_request);
}
#[test]
fn get_machine_response_is_json() {
let names = ["machine", "projects", "deleted_projects", "github"];
a_message_is_json(2, &names, samples::get_machine_response, on_wire::get_machine_response);
}
#[test]
fn machine_is_json() {
let names = [
"name",
"location",
"sample_time",
"cpu_used_cores",
"cpu_total_cores",
"memory_used_bytes",
"memory_total_bytes",
"disk_used_bytes",
"disk_total_bytes",
"disk_usage",
"hostname",
"ssh_host_key_fingerprint",
"ssh_keys",
"backups_enabled",
"snapshot_list_time",
"snapshot_list_failure_message",
"backup_retention_hours",
"acme_enabled",
"apps_domain",
"daemon_version",
"docker_version",
"boot_time",
"restart_required_time",
"scheduled_restart_time",
"sessions",
"alert_channels",
];
a_message_is_json(2, &names, samples::machine, on_wire::machine);
}
#[test]
fn alert_destination_is_json() {
let names = ["kind", "label"];
a_message_is_json(5, &names, samples::alert_destination, on_wire::alert_destination);
}
#[test]
fn machine_session_is_json() {
let names = [
"session_id",
"kind",
"project_id",
"service",
"port",
"start_time",
"client_address",
"ssh_key_label",
"ssh_key_fingerprint",
];
a_message_is_json(7, &names, samples::machine_session, on_wire::machine_session);
}
#[test]
fn disk_usage_is_json() {
let names = [
"images_bytes",
"build_cache_bytes",
"volumes_bytes",
"container_layers_bytes",
"project_files_bytes",
"container_logs_bytes",
"http_traffic_bytes",
];
a_message_is_json(3, &names, samples::disk_usage, on_wire::disk_usage);
}
#[test]
fn ssh_key_is_json() {
let names = ["public_key", "label", "fingerprint"];
a_message_is_json(2, &names, samples::ssh_key, on_wire::ssh_key);
}
#[test]
fn github_connection_is_json() {
let names = [
"app_name",
"install_url",
"repositories",
"repository_count",
"webhooks_enabled",
];
a_message_is_json(2, &names, samples::github_connection, on_wire::github_connection);
}
#[test]
fn github_repository_is_json() {
let names = ["repository", "default_branch", "private", "push_time"];
a_message_is_json(2, &names, samples::github_repository, on_wire::github_repository);
}
#[test]
fn deleted_project_is_json() {
let names = ["project_id", "newest_snapshot", "snapshot_count"];
a_message_is_json(2, &names, samples::deleted_project, on_wire::deleted_project);
}
#[test]
fn run_machine_action_request_is_json() {
let names = [
"add_ssh_key",
"remove_ssh_key_fingerprint",
"restart_machine",
"cancel_restart",
"end_session_id",
];
a_message_is_json(
12,
&names,
samples::run_machine_action_request,
on_wire::run_machine_action_request,
);
}
#[test]
fn restart_machine_action_is_json() {
let names = ["restart_time", "at_maintenance_window", "interrupt_operations"];
a_message_is_json(
2,
&names,
samples::restart_machine_action,
on_wire::restart_machine_action,
);
}
#[test]
fn run_machine_action_response_is_json() {
let names = ["machine"];
a_message_is_json(
2,
&names,
samples::run_machine_action_response,
on_wire::run_machine_action_response,
);
}
#[test]
fn project_metadata_is_json() {
let names = ["name", "emoji", "description", "notes"];
a_message_is_json(3, &names, samples::project_metadata, on_wire::project_metadata);
}
#[test]
fn project_summary_is_json() {
let names = [
"project_id",
"metadata",
"problems",
"services",
"url",
"hosts",
"http_traffic_last_day",
"cpu_used_cores",
"memory_used_bytes",
"deploy_time",
"running_operations",
"pinned",
"disk_used_bytes",
];
a_message_is_json(2, &names, samples::project_summary, on_wire::project_summary);
}
#[test]
fn service_summary_is_json() {
let names = ["service", "state"];
a_message_is_json(10, &names, samples::service_summary, on_wire::service_summary);
}
#[test]
fn project_problem_is_json() {
let names = [
"kind",
"service",
"operation_id",
"since_time",
"problem_message",
"incident_id",
];
a_message_is_json(15, &names, samples::project_problem, on_wire::project_problem);
}
#[test]
fn get_project_request_is_json() {
let names = [
"project_id",
"include_secret_values",
"snapshots_before",
"snapshots_volume",
"incidents_before",
"uptime_day_count",
"incidents_before_id",
];
a_message_is_json(2, &names, samples::get_project_request, on_wire::get_project_request);
}
#[test]
fn get_project_response_is_json() {
let names = ["project"];
a_message_is_json(2, &names, samples::get_project_response, on_wire::get_project_response);
}
#[test]
fn project_is_json() {
let names = [
"project_id",
"metadata",
"problems",
"url",
"cpu_used_cores",
"memory_used_bytes",
"deploy_id",
"deploy_status",
"deploy_time",
"x_pethost_applies_at_once",
"services",
"volumes",
"routes",
"hosts",
"password_protected",
"operations",
"snapshots",
"snapshot_count",
"snapshot_list_time",
"http_traffic_last_day",
"source",
"running_services_action",
"alerts",
"incidents",
"more_incidents",
"uptime_days",
];
a_message_is_json(6, &names, samples::project, on_wire::project);
}
#[test]
fn running_services_action_is_json() {
let names = ["kind", "services", "start_time"];
a_message_is_json(
5,
&names,
samples::running_services_action,
on_wire::running_services_action,
);
}
#[test]
fn project_source_is_json() {
let names = ["files", "github"];
a_message_is_json(6, &names, samples::project_source, on_wire::project_source);
}
#[test]
fn github_source_is_json() {
let names = [
"repository",
"branch",
"directory",
"auto_deploy",
"newest_commit",
"deployed_commit",
"pinned",
"auto_deploy_pending",
];
a_message_is_json(3, &names, samples::github_source, on_wire::github_source);
}
#[test]
fn github_commit_is_json() {
let names = ["sha", "title", "url"];
a_message_is_json(2, &names, samples::github_commit, on_wire::github_commit);
}
#[test]
fn service_is_json() {
let names = [
"service",
"state",
"container_running",
"image",
"builds_image",
"image_digest",
"image_size_bytes",
"command",
"run_as_user",
"start_time",
"finish_time",
"exit_code",
"out_of_memory",
"restart_count",
"cpu_used_cores",
"memory_used_bytes",
"memory_limit_bytes",
"cpu_limit_cores",
"writable_layer_bytes",
"ports",
"listening_ports",
"published_ports",
"volume_mounts",
"restart_policy",
"health_check",
"environment",
"env_files",
"ssh_command",
];
a_message_is_json(10, &names, samples::service, on_wire::service);
}
#[test]
fn published_port_is_json() {
let names = ["machine_port", "container_port", "protocol"];
a_message_is_json(2, &names, samples::published_port, on_wire::published_port);
}
#[test]
fn volume_mount_is_json() {
let names = ["volume", "container_path"];
a_message_is_json(2, &names, samples::volume_mount, on_wire::volume_mount);
}
#[test]
fn health_check_is_json() {
let names = [
"command",
"interval_seconds",
"status",
"consecutive_failure_count",
"recent_results_passed",
"last_failure_output",
];
a_message_is_json(5, &names, samples::health_check, on_wire::health_check);
}
#[test]
fn environment_variable_is_json() {
let names = [
"name",
"value",
"secret",
"source_file",
"from_env_file_variables",
"value_left_out",
];
a_message_is_json(2, &names, samples::environment_variable, on_wire::environment_variable);
}
#[test]
fn volume_is_json() {
let names = [
"volume",
"size_bytes",
"mounted_by",
"last_backup_time",
"snapshot_count",
"declared",
];
a_message_is_json(2, &names, samples::volume, on_wire::volume);
}
#[test]
fn volume_mounted_by_is_json() {
let names = ["service", "container_path"];
a_message_is_json(2, &names, samples::volume_mounted_by, on_wire::volume_mounted_by);
}
#[test]
fn host_is_json() {
let names = [
"host",
"url",
"certificate_source",
"certificate_expire_time",
"unavailable_message",
];
a_message_is_json(5, &names, samples::host, on_wire::host);
}
#[test]
fn route_is_json() {
let names = ["host", "path", "service", "port", "strip_path"];
a_message_is_json(2, &names, samples::route, on_wire::route);
}
#[test]
fn operation_is_json() {
let names = [
"operation_id",
"kind",
"status",
"start_time",
"finish_time",
"failure_message",
"deploy_failure_reason",
"made_current",
"service",
"failed_exit_code",
"snapshot_id",
"restored_volumes",
"undo_snapshot_id",
"github_commit",
"archive_name",
"adjustments",
"changed_paths",
"changed_path_count",
"files_kept",
"files_operation_id",
];
a_message_is_json(13, &names, samples::operation, on_wire::operation);
}
#[test]
fn snapshot_is_json() {
let names = ["snapshot_id", "create_time", "size_bytes", "volumes"];
a_message_is_json(2, &names, samples::snapshot, on_wire::snapshot);
}
#[test]
fn http_traffic_summary_is_json() {
let names = [
"request_count",
"server_error_count",
"latency_p50_ms",
"latency_p95_ms",
];
a_message_is_json(2, &names, samples::http_traffic_summary, on_wire::http_traffic_summary);
}
#[test]
fn create_project_request_is_json() {
let names = [
"project_id",
"source",
"upload_id",
"files",
"x_pethost",
"timeout_seconds",
"operation_id",
"wait_seconds",
];
a_message_is_json(
3,
&names,
samples::create_project_request,
on_wire::create_project_request,
);
}
#[test]
fn create_project_response_is_json() {
let names = ["operation", "violations", "adjustments", "project", "log"];
a_message_is_json(
2,
&names,
samples::create_project_response,
on_wire::create_project_response,
);
}
#[test]
fn deploy_project_request_is_json() {
let names = [
"project_id",
"base_deploy_id",
"files",
"x_pethost",
"mount_volume",
"timeout_seconds",
"operation_id",
"upload_id",
"commit",
"newest_commit",
"rollback_deploy_id",
"wait_seconds",
];
a_message_is_json(
10,
&names,
samples::deploy_project_request,
on_wire::deploy_project_request,
);
}
#[test]
fn mount_volume_is_json() {
let names = ["service", "volume", "container_path"];
a_message_is_json(2, &names, samples::mount_volume, on_wire::mount_volume);
}
#[test]
fn project_extension_is_json() {
let names = ["metadata", "routes", "remove_routes", "password", "remove_password"];
a_message_is_json(2, &names, samples::project_extension, on_wire::project_extension);
}
#[test]
fn file_change_is_json() {
let names = [
"path",
"text",
"data",
"make_directory",
"delete",
"delete_tree",
"rename_to",
"executable",
];
a_message_is_json(14, &names, samples::file_change, on_wire::file_change);
}
#[test]
fn deploy_project_response_is_json() {
let names = ["operation", "violations", "adjustments", "project", "log"];
a_message_is_json(
2,
&names,
samples::deploy_project_response,
on_wire::deploy_project_response,
);
}
#[test]
fn spec_violation_is_json() {
let names = ["service", "location", "violation_message"];
a_message_is_json(2, &names, samples::spec_violation, on_wire::spec_violation);
}
#[test]
fn list_commits_request_is_json() {
let names = ["project_id", "before_commit"];
a_message_is_json(2, &names, samples::list_commits_request, on_wire::list_commits_request);
}
#[test]
fn list_commits_response_is_json() {
let names = ["commits", "more"];
a_message_is_json(
2,
&names,
samples::list_commits_response,
on_wire::list_commits_response,
);
}
#[test]
fn branch_commit_is_json() {
let names = ["commit", "author", "commit_time", "deployed", "last_deploy", "newest"];
a_message_is_json(2, &names, samples::branch_commit, on_wire::branch_commit);
}
#[test]
fn run_project_action_request_is_json() {
let names = [
"project_id",
"start_services",
"stop_services",
"restart_services",
"recreate_service",
"back_up",
"restore_snapshot",
"cancel_operation",
"delete_project",
"set_source",
"delete_volume",
"operation_id",
"wait_seconds",
];
a_message_is_json(
22,
&names,
samples::run_project_action_request,
on_wire::run_project_action_request,
);
}
#[test]
fn services_action_is_json() {
let names = ["services"];
a_message_is_json(2, &names, samples::services_action, on_wire::services_action);
}
#[test]
fn recreate_service_action_is_json() {
let names = ["service", "pull_latest_image"];
a_message_is_json(
2,
&names,
samples::recreate_service_action,
on_wire::recreate_service_action,
);
}
#[test]
fn back_up_action_is_json() {
let names = [];
a_message_is_json(2, &names, samples::back_up_action, on_wire::back_up_action);
}
#[test]
fn restore_snapshot_action_is_json() {
let names = ["snapshot_id", "volumes"];
a_message_is_json(
2,
&names,
samples::restore_snapshot_action,
on_wire::restore_snapshot_action,
);
}
#[test]
fn cancel_operation_action_is_json() {
let names = ["operation_id"];
a_message_is_json(
2,
&names,
samples::cancel_operation_action,
on_wire::cancel_operation_action,
);
}
#[test]
fn delete_project_action_is_json() {
let names = ["skip_final_backup"];
a_message_is_json(
2,
&names,
samples::delete_project_action,
on_wire::delete_project_action,
);
}
#[test]
fn run_project_action_response_is_json() {
let names = ["operation", "project", "log"];
a_message_is_json(
2,
&names,
samples::run_project_action_response,
on_wire::run_project_action_response,
);
}
#[test]
fn set_project_alerts_request_is_json() {
let names = [
"project_id",
"checks",
"remove_checks",
"traffic_rules",
"remove_traffic_rules",
"off",
"mute_minutes",
];
a_message_is_json(
3,
&names,
samples::set_project_alerts_request,
on_wire::set_project_alerts_request,
);
}
#[test]
fn set_project_alerts_response_is_json() {
let names = ["alerts"];
a_message_is_json(
2,
&names,
samples::set_project_alerts_response,
on_wire::set_project_alerts_response,
);
}
#[test]
fn site_check_is_json() {
let names = ["host", "path", "expect_status", "must_contain"];
a_message_is_json(2, &names, samples::site_check, on_wire::site_check);
}
#[test]
fn traffic_rule_is_json() {
let names = ["metric", "filter", "threshold", "window_minutes", "min_requests"];
a_message_is_json(5, &names, samples::traffic_rule, on_wire::traffic_rule);
}
#[test]
fn project_alerts_is_json() {
let names = ["checks", "traffic_rules", "off", "mute_end_time", "uptime_percent"];
a_message_is_json(3, &names, samples::project_alerts, on_wire::project_alerts);
}
#[test]
fn site_check_state_is_json() {
let names = ["check", "machine_default", "status", "last_result", "incident_id"];
a_message_is_json(7, &names, samples::site_check_state, on_wire::site_check_state);
}
#[test]
fn site_check_result_is_json() {
let names = ["check_time", "status", "duration_ms", "failure_message"];
a_message_is_json(2, &names, samples::site_check_result, on_wire::site_check_result);
}
#[test]
fn traffic_rule_state_is_json() {
let names = [
"rule",
"machine_default",
"status",
"value",
"request_count",
"incident_id",
];
a_message_is_json(7, &names, samples::traffic_rule_state, on_wire::traffic_rule_state);
}
#[test]
fn incident_is_json() {
let names = [
"incident_id",
"kind",
"service",
"check",
"traffic_rule",
"operation_id",
"open_time",
"resolve_time",
"value",
"request_count",
"after_operation_id",
"after_operation_end_time",
"joined_incident_id",
"quiet_reason",
"flapping",
"incident_message",
"evidence",
];
a_message_is_json(15, &names, samples::incident, on_wire::incident);
}
#[test]
fn incident_evidence_is_json() {
let names = [
"check_result",
"exit_code",
"oom_killed",
"restart_count",
"health_output",
"log_lines",
"top_path",
];
a_message_is_json(2, &names, samples::incident_evidence, on_wire::incident_evidence);
}
#[test]
fn uptime_day_is_json() {
let names = ["start_time", "uptime_percent", "down_seconds"];
a_message_is_json(3, &names, samples::uptime_day, on_wire::uptime_day);
}
#[test]
fn get_operation_request_is_json() {
let names = [
"project_id",
"operation_id",
"wait_seconds",
"after_log_line",
"log_line_limit",
];
a_message_is_json(
3,
&names,
samples::get_operation_request,
on_wire::get_operation_request,
);
}
#[test]
fn get_operation_response_is_json() {
let names = ["operation", "project", "log", "log_line_count", "next_after_log_line"];
a_message_is_json(
2,
&names,
samples::get_operation_response,
on_wire::get_operation_response,
);
}
#[test]
fn operation_log_line_is_json() {
let names = ["time", "text"];
a_message_is_json(2, &names, samples::operation_log_line, on_wire::operation_log_line);
}
#[test]
fn http_traffic_filter_is_json() {
let names = ["host", "method", "path_contains", "path_pattern", "status_class"];
a_message_is_json(2, &names, samples::http_traffic_filter, on_wire::http_traffic_filter);
}
#[test]
fn query_http_traffic_request_is_json() {
let names = [
"project_id",
"filter",
"start_time",
"end_time",
"last_seconds",
"bucket_width_seconds",
"request_limit",
"page_token",
];
a_message_is_json(
2,
&names,
samples::query_http_traffic_request,
on_wire::query_http_traffic_request,
);
}
#[test]
fn query_http_traffic_response_is_json() {
let names = [
"start_time",
"end_time",
"oldest_kept_time",
"summary",
"buckets",
"top_paths",
"newest_sequence",
"requests",
"next_page_token",
"tail_sequence",
];
a_message_is_json(
2,
&names,
samples::query_http_traffic_response,
on_wire::query_http_traffic_response,
);
}
#[test]
fn http_traffic_bucket_is_json() {
let names = ["start_time", "summary"];
a_message_is_json(2, &names, samples::http_traffic_bucket, on_wire::http_traffic_bucket);
}
#[test]
fn http_path_traffic_is_json() {
let names = ["method", "path_pattern", "summary"];
a_message_is_json(2, &names, samples::http_path_traffic, on_wire::http_path_traffic);
}
#[test]
fn http_request_is_json() {
let names = [
"sequence",
"finish_time",
"host",
"method",
"path",
"path_pattern",
"route_path",
"service",
"port",
"status_code",
"response_size_bytes",
"duration_ms",
"service_duration_ms",
"client_ip_address",
"user_agent",
];
a_message_is_json(2, &names, samples::http_request, on_wire::http_request);
}
#[test]
fn container_log_filter_is_json() {
let names = ["service", "stream", "text_contains"];
a_message_is_json(4, &names, samples::container_log_filter, on_wire::container_log_filter);
}
#[test]
fn query_container_logs_request_is_json() {
let names = [
"project_id",
"filter",
"start_time",
"end_time",
"last_seconds",
"limit",
"from_start",
"page_token",
];
a_message_is_json(
2,
&names,
samples::query_container_logs_request,
on_wire::query_container_logs_request,
);
}
#[test]
fn query_container_logs_response_is_json() {
let names = [
"start_time",
"end_time",
"oldest_kept_time",
"lines",
"next_page_token",
"tail_cursor",
];
a_message_is_json(
2,
&names,
samples::query_container_logs_response,
on_wire::query_container_logs_response,
);
}
#[test]
fn log_line_is_json() {
let names = ["time", "service", "stream", "text"];
a_message_is_json(4, &names, samples::log_line, on_wire::log_line);
}
#[test]
fn run_service_command_request_is_json() {
let names = [
"project_id",
"service",
"command",
"stdin",
"run_as_user",
"working_directory",
"timeout_seconds",
];
a_message_is_json(
2,
&names,
samples::run_service_command_request,
on_wire::run_service_command_request,
);
}
#[test]
fn run_service_command_response_is_json() {
let names = ["exit_code", "timed_out", "stdout", "stderr", "output_truncated"];
a_message_is_json(
2,
&names,
samples::run_service_command_response,
on_wire::run_service_command_response,
);
}
#[test]
fn file_entry_is_json() {
let names = [
"name",
"type",
"size_bytes",
"modify_time",
"mode",
"owner_uid",
"owner_gid",
"symlink_target",
];
a_message_is_json(6, &names, samples::file_entry, on_wire::file_entry);
}
#[test]
fn read_path_request_is_json() {
let names = [
"project_id",
"service",
"volume",
"path",
"entry_limit",
"offset_bytes",
"length_bytes",
"entry_page_token",
];
a_message_is_json(6, &names, samples::read_path_request, on_wire::read_path_request);
}
#[test]
fn read_path_response_is_json() {
let names = [
"entry",
"location",
"volume",
"entries",
"entry_count",
"next_entry_page_token",
"text",
"binary",
"next_offset_bytes",
"deploy_id",
];
a_message_is_json(5, &names, samples::read_path_response, on_wire::read_path_response);
}
#[test]
fn create_transfer_request_is_json() {
let names = ["upload_archive", "upload_file", "download"];
a_message_is_json(
8,
&names,
samples::create_transfer_request,
on_wire::create_transfer_request,
);
}
#[test]
fn archive_upload_is_json() {
let names = ["file_name"];
a_message_is_json(2, &names, samples::archive_upload, on_wire::archive_upload);
}
#[test]
fn file_upload_is_json() {
let names = ["project_id", "service", "volume", "path"];
a_message_is_json(6, &names, samples::file_upload, on_wire::file_upload);
}
#[test]
fn path_download_is_json() {
let names = ["project_id", "service", "volume", "path"];
a_message_is_json(6, &names, samples::path_download, on_wire::path_download);
}
#[test]
fn create_transfer_response_is_json() {
let names = [
"url",
"http_method",
"expire_time",
"command",
"upload_id",
"replaces",
"file_name",
"exclude_names",
];
a_message_is_json(
2,
&names,
samples::create_transfer_response,
on_wire::create_transfer_response,
);
}
#[test]
fn project_busy_is_json() {
let names = ["operation_id", "kind", "start_time"];
a_message_is_json(7, &names, samples::project_busy, on_wire::project_busy);
}
#[test]
fn project_changed_is_json() {
let names = [];
a_message_is_json(2, &names, samples::project_changed, on_wire::project_changed);
}
#[test]
fn machine_unreachable_is_json() {
let names = ["since_time"];
a_message_is_json(2, &names, samples::machine_unreachable, on_wire::machine_unreachable);
}
#[test]
fn machine_update_pending_is_json() {
let names = [];
a_message_is_json(
2,
&names,
samples::machine_update_pending,
on_wire::machine_update_pending,
);
}
#[test]
fn no_machine_is_json() {
let names = ["reason", "url"];
a_message_is_json(4, &names, samples::no_machine, on_wire::no_machine);
}
#[test]
fn watch_operation_request_is_json() {
let names = ["project_id", "operation_id"];
a_message_is_json(
2,
&names,
samples::watch_operation_request,
on_wire::watch_operation_request,
);
}
#[test]
fn watch_operation_response_is_json() {
let names = ["log", "finished_operation"];
a_message_is_json(
6,
&names,
samples::watch_operation_response,
on_wire::watch_operation_response,
);
}
#[test]
fn tail_container_logs_request_is_json() {
let names = ["project_id", "filter", "after_cursor"];
a_message_is_json(
2,
&names,
samples::tail_container_logs_request,
on_wire::tail_container_logs_request,
);
}
#[test]
fn tail_container_logs_response_is_json() {
let names = ["line", "cursor"];
a_message_is_json(
2,
&names,
samples::tail_container_logs_response,
on_wire::tail_container_logs_response,
);
}
#[test]
fn tail_http_traffic_request_is_json() {
let names = ["project_id", "filter", "after_sequence"];
a_message_is_json(
2,
&names,
samples::tail_http_traffic_request,
on_wire::tail_http_traffic_request,
);
}
#[test]
fn tail_http_traffic_response_is_json() {
let names = ["request"];
a_message_is_json(
2,
&names,
samples::tail_http_traffic_response,
on_wire::tail_http_traffic_response,
);
}
#[test]
fn a_time_is_json() {
let time = Timestamp {
seconds: 1_791_279_000,
nanos: 1,
};
let json = Value::from("2026-10-06T09:30:00.000000001Z");
assert_eq!(serde_json::to_value(time).unwrap(), json);
assert_eq!(serde_json::from_value::<Timestamp>(json).unwrap(), time);
}
async fn first<T: Default>(mut responses: ResponseStream<T>) -> Result<T, Error> {
let mut first = None;
while let Some(response) = responses.next().await {
first.get_or_insert(response?);
}
Ok(first.unwrap_or_default())
}
async fn polled<T>(responses: &mut ResponseStream<T>) -> Option<Result<T, Error>> {
std::future::poll_fn(|context| futures_core::Stream::poll_next(Pin::new(&mut *responses), context)).await
}
async fn items<T>(mut responses: ResponseStream<T>) -> Vec<Result<T, Error>> {
let mut items = Vec::new();
while let Some(item) = polled(&mut responses).await {
items.push(item);
assert!(
items.len() < 100,
"the stream yields on and on: the fake sends a few responses"
);
}
assert!(
polled(&mut responses).await.is_none(),
"a stream that ended yields again"
);
items
}
async fn a_stream_is_read<Request, Wire, Response, Open>(
rpc: &str,
open: Open,
sample: impl Fn(usize) -> (Wire, Response),
) where
Request: buffa::Message,
Wire: buffa::Message + Default,
Response: PartialEq + std::fmt::Debug,
Open: Fn(Client) -> ResponseStream<Response> + Copy,
{
let (said, expected): (Vec<Wire>, Vec<Response>) = [1, 3, 5].into_iter().map(sample).unzip();
let pulse = Wire::default();
assert!(
pulse.encode_to_vec().is_empty(),
"a response with nothing set has bytes on the wire"
);
let sent: Vec<Wire> = said
.iter()
.flat_map(|response| [pulse.clone(), response.clone()])
.chain([pulse.clone()])
.collect();
let all = |client| items(open(client));
let responses = |items: Vec<Result<Response, Error>>| items.into_iter().map(Result::unwrap).collect::<Vec<_>>();
let (_, got): (Request, _) = exchange(rpc, streamed(&sent, End::Clean), all).await;
assert_eq!(responses(got), expected);
let silence = [pulse.clone(), pulse];
let (_, got): (Request, _) = exchange(rpc, streamed(&silence, End::Clean), all).await;
assert!(got.is_empty(), "a stream of pulses alone yielded {got:?}");
let failed = error(
"out_of_range",
&[("pethost.panel.v1.ProjectBusy", b"")],
&STANDARD_NO_PAD,
);
let (_, mut got): (Request, _) = exchange(rpc, streamed(&sent, End::Failed(failed)), all).await;
let last = got.pop().expect("a stream that failed yielded nothing").unwrap_err();
assert_eq!(
(last.code(), last.message(), last.details().len()),
(ErrorCode::OutOfRange, MESSAGE, 1)
);
assert_eq!(responses(got), expected);
let refused = error("not_found", &[], &STANDARD_NO_PAD);
let (_, got): (Request, _) = exchange(rpc, streamed(&sent[..0], End::Failed(refused)), all).await;
let [Err(only)] = got.as_slice() else {
panic!("a refused call yielded {got:?}")
};
assert_eq!((only.code(), only.message()), (ErrorCode::NotFound, MESSAGE));
let count = expected.len();
let leave = |client| async move {
let mut responses = open(client);
let mut came = Vec::new();
for _ in 0..count {
match tokio::time::timeout(SOON, responses.next()).await {
Ok(Some(item)) => came.push(item),
_ => break,
}
}
came
};
let (_, got): (Request, _) = exchange(rpc, streamed(&sent, End::Open), leave).await;
assert_eq!(
responses(got),
expected,
"what the API sent did not all come while the stream went on"
);
}
#[tokio::test]
async fn a_stream_left_before_the_apis_first_word_ends_its_call() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let address = listener.local_addr().unwrap();
let client = Client::with_base_url(TOKEN, &format!("http://{address}")).unwrap();
let fake = tokio::spawn(take(listener));
let mut responses = client.watch_operation(types::WatchOperationRequest::default());
let taken = tokio::select! {
taken = fake => taken.unwrap(),
item = responses.next() => panic!("the fake said nothing, and the stream yielded {item:?}"),
};
drop(responses);
tokio::time::timeout(SOON, taken.unanswered())
.await
.expect("the API still has the caller that left its stream");
}
#[tokio::test]
async fn watch_operation_is_a_stream() {
let open = |client: Client| client.watch_operation(types::WatchOperationRequest::default());
let sample = |k| {
(
on_wire::watch_operation_response(k, true),
samples::watch_operation_response(k, true),
)
};
a_stream_is_read::<wire::WatchOperationRequest, _, _, _>("WatchOperation", open, sample).await;
}
#[tokio::test]
async fn tail_container_logs_is_a_stream() {
let open = |client: Client| client.tail_container_logs(types::TailContainerLogsRequest::default());
let sample = |k| {
(
on_wire::tail_container_logs_response(k, true),
samples::tail_container_logs_response(k, true),
)
};
a_stream_is_read::<wire::TailContainerLogsRequest, _, _, _>("TailContainerLogs", open, sample).await;
}
#[tokio::test]
async fn tail_http_traffic_is_a_stream() {
let open = |client: Client| client.tail_http_traffic(types::TailHttpTrafficRequest::default());
let sample = |k| {
(
on_wire::tail_http_traffic_response(k, true),
samples::tail_http_traffic_response(k, true),
)
};
a_stream_is_read::<wire::TailHttpTrafficRequest, _, _, _>("TailHttpTraffic", open, sample).await;
}
async fn failed(answer: Answer) -> Error {
let call = |client: Client| async move { client.get_machine(types::GetMachineRequest::default()).await };
let (_, response): (wire::GetMachineRequest, _) = exchange("GetMachine", answer, call).await;
response.unwrap_err()
}
#[tokio::test]
async fn each_code_of_the_protocol_is_its_error_code() {
let codes = [
("canceled", 499, ErrorCode::Canceled),
("unknown", 500, ErrorCode::Unknown),
("invalid_argument", 400, ErrorCode::InvalidArgument),
("deadline_exceeded", 504, ErrorCode::DeadlineExceeded),
("not_found", 404, ErrorCode::NotFound),
("already_exists", 409, ErrorCode::AlreadyExists),
("permission_denied", 403, ErrorCode::PermissionDenied),
("resource_exhausted", 429, ErrorCode::ResourceExhausted),
("failed_precondition", 400, ErrorCode::FailedPrecondition),
("aborted", 409, ErrorCode::Aborted),
("out_of_range", 400, ErrorCode::OutOfRange),
("unimplemented", 501, ErrorCode::Unimplemented),
("internal", 500, ErrorCode::Internal),
("unavailable", 503, ErrorCode::Unavailable),
("data_loss", 500, ErrorCode::DataLoss),
("unauthenticated", 401, ErrorCode::Unauthenticated),
];
for (name, status, code) in codes {
let error = failed(failure(name, status, &[], &STANDARD_NO_PAD)).await;
assert_eq!(error.code(), code);
assert_eq!(error.code().as_str(), name);
assert_eq!(error.message(), MESSAGE);
assert_eq!(error.to_string(), format!("{name}: {MESSAGE}"));
assert!(error.details().is_empty(), "{name}");
}
}
#[tokio::test]
async fn a_detail_the_crate_cannot_read_is_left_out() {
let details: [(&str, &[u8]); 2] = [
("pethost.panel.v1.NoSuchDetailYet", b""),
("pethost.panel.v1.ProjectBusy", b"\x0a\x7f"),
];
let error = failed(failure("aborted", 409, &details, &STANDARD_NO_PAD)).await;
assert_eq!(error.code(), ErrorCode::Aborted);
assert!(error.details().is_empty(), "{:?}", error.details());
}
#[tokio::test]
async fn a_detail_is_read_with_padding_and_without() {
for length in 0..3 {
let mut detail = wire::ProjectBusy::default();
detail.__buffa_unknown_fields.push(buffa::UnknownField {
number: 29,
data: buffa::UnknownFieldData::LengthDelimited(vec![0; length]),
});
let detail = detail.encode_to_vec();
for encode in [&STANDARD, &STANDARD_NO_PAD] {
let answer = failure(
"unavailable",
503,
&[("pethost.panel.v1.ProjectBusy", detail.as_slice())],
encode,
);
assert_eq!(failed(answer).await.details().len(), 1, "{length} more bytes");
}
}
}
#[tokio::test]
async fn a_call_that_reaches_nothing_is_unavailable() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let address = listener.local_addr().unwrap();
drop(listener);
let client = Client::with_base_url(TOKEN, &format!("http://{address}")).unwrap();
let error = client
.get_machine(types::GetMachineRequest::default())
.await
.unwrap_err();
assert_eq!(error.code(), ErrorCode::Unavailable);
assert!(std::error::Error::source(&error).is_some());
}
#[tokio::test]
async fn a_call_given_up_ends() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let address = listener.local_addr().unwrap();
let client = Client::with_base_url(TOKEN, &format!("http://{address}")).unwrap();
let fake = tokio::spawn(take(listener));
let mut call = Box::pin(async { client.get_machine(types::GetMachineRequest::default()).await });
let taken = tokio::select! {
taken = fake => taken.unwrap(),
response = &mut call => panic!("the fake said nothing, and the call returned {response:?}"),
};
drop(call);
tokio::time::timeout(SOON, taken.unanswered())
.await
.expect("the API still has the call its caller gave up on");
}
#[test]
fn a_base_url_that_is_none_is_refused() {
for base_url in ["not a url", "console.pethost.dev", "ftp://console.pethost.dev"] {
let error = Client::with_base_url(TOKEN, base_url).unwrap_err();
assert_eq!(error.code(), ErrorCode::InvalidArgument, "{base_url}");
}
}
#[tokio::test]
async fn a_client_prints_without_its_token() {
let printed = format!("{:?}", Client::new(TOKEN));
assert!(printed.contains("https://console.pethost.dev"), "{printed}");
assert!(!printed.contains(TOKEN), "{printed}");
}
#[tokio::test]
async fn a_client_and_its_calls_cross_threads() {
fn shared<T: Clone + Send + Sync>() {}
fn sent<T: Send>(_: &T) {}
fn stream<T, S: futures_core::Stream<Item = Result<T, Error>> + Send + Unpin + 'static>(_: &S) {}
shared::<Client>();
shared::<Error>();
let client = Client::new(TOKEN);
sent(&async { client.get_machine(types::GetMachineRequest::default()).await });
let mut responses = client.watch_operation(types::WatchOperationRequest::default());
stream(&responses);
sent(&responses.next());
let mut responses = client.tail_container_logs(types::TailContainerLogsRequest::default());
stream(&responses);
sent(&responses.next());
let mut responses = client.tail_http_traffic(types::TailHttpTrafficRequest::default());
stream(&responses);
sent(&responses.next());
}
#[test]
fn a_time_prints_as_rfc_3339() {
let print = |seconds, nanos| Timestamp { seconds, nanos }.to_string();
assert_eq!(print(0, 0), "1970-01-01T00:00:00Z");
assert_eq!(print(-1, 500_000_000), "1969-12-31T23:59:59.5Z");
assert_eq!(print(951_782_400, 250_000_000), "2000-02-29T00:00:00.25Z");
assert_eq!(print(1_791_279_000, 1), "2026-10-06T09:30:00.000000001Z");
}
#[test]
fn a_time_is_the_system_clocks_both_ways() {
let before_1970 = std::time::UNIX_EPOCH - Duration::from_millis(1500);
let time = Timestamp::from(before_1970);
assert_eq!((time.seconds, time.nanos), (-2, 500_000_000));
assert_eq!(time.to_system_time(), Some(before_1970));
}