Skip to main content

MockHost

Struct MockHost 

Source
pub struct MockHost {
Show 40 fields pub config: String, pub values: BTreeMap<String, String>, pub secrets: BTreeMap<String, String>, pub account: AccountState, pub driving: bool, pub theme: Theme, pub capabilities: Capabilities, pub focused_pane: Option<String>, pub claimed_elsewhere: BTreeSet<String>, pub claims: BTreeSet<String>, pub emitted: Vec<(String, String, Target)>, pub published: Vec<(String, String)>, pub live_deleted: Vec<String>, pub listening: BTreeSet<String>, pub call_answers: BTreeMap<String, String>, pub calls: Vec<MockCall>, pub denials: Vec<String>, pub panes: Vec<Pane>, pub frame_request: Option<u64>, pub opened: Vec<String>, pub opened_urls: Vec<String>, pub focused_panes: Vec<String>, pub now_ms: u64, pub url_gesture_ms: Option<u64>, pub closed: Vec<String>, pub gesture: bool, pub machine_id: Option<String>, pub account_id: Option<String>, pub lease_epoch: Option<u64>, pub release: Option<Release>, pub instance_id: String, pub environment: Vec<(String, String)>, pub wall_ms: u64, pub utc_offset_minutes: i32, pub time_zone: Option<String>, pub health: Option<(Health, String)>, pub tints: BTreeMap<String, u32>, pub requested: BTreeMap<String, (u32, u32)>, pub labels: BTreeMap<String, String>, pub carets: BTreeMap<String, (u32, u32)>, /* private fields */
}
Expand description

The in-process host. Build one, install it (or hand it to a Harness), and inspect it after the plugin ran.

Fields§

§config: String§values: BTreeMap<String, String>§secrets: BTreeMap<String, String>§account: AccountState§driving: bool§theme: Theme§capabilities: Capabilities§focused_pane: Option<String>§claimed_elsewhere: BTreeSet<String>

Claims another viewer holds: claiming these fails.

§claims: BTreeSet<String>

Claims this instance holds.

§emitted: Vec<(String, String, Target)>

events.emit calls: name, payload, target.

§published: Vec<(String, String)>

live.publish calls: key, payload.

§live_deleted: Vec<String>

live.delete calls: the keys withdrawn, in order.

§listening: BTreeSet<String>

Patterns events.on registered.

§call_answers: BTreeMap<String, String>

calls.call and call-async answers by method (the companion’s side); a method without one answers invalid.

§calls: Vec<MockCall>

Every calls.call, send and call-async, in order.

§denials: Vec<String>

Grants the plugin was denied, in order.

§panes: Vec<Pane>§frame_request: Option<u64>

A frame the plugin asked for outside frame() (crate::Context::request_frame or wake_at): the earliest viewer instant, 0 for “the next frame”.

§opened: Vec<String>

Surfaces open opened, in order.

§opened_urls: Vec<String>

URLs url::open opened, in order.

§focused_panes: Vec<String>

Panes focus_pane asked the viewer to focus, in order.

§now_ms: u64

The viewer clock of the last Harness::frame, for the url.open input window.

§url_gesture_ms: Option<u64>

When the last user input was delivered (now_ms then), until a URL opened for it.

§closed: Vec<String>

Surfaces close closed, in order.

§gesture: bool

Whether the plugin is handling a user gesture now (the harness sets it around key, paste, pointer-press and command events).

§machine_id: Option<String>

The machine the plugin runs on: a daemon’s Context::machine_id, a viewer’s view::machine_id.

§account_id: Option<String>

A daemon’s Context::account_id.

§lease_epoch: Option<u64>

daemon-context.lease-epoch: a singleton’s epoch, None for fleet (MockHost::singleton).

§release: Option<Release>

The build daemon::Context::release reports.

§instance_id: String

A viewer’s view::instance_id.

§environment: Vec<(String, String)>

A daemon plugin’s environment (daemon::env).

§wall_ms: u64

view::wall_ms: milliseconds since the Unix epoch.

§utc_offset_minutes: i32

view::utc_offset_minutes.

§time_zone: Option<String>

view::time_zone.

§health: Option<(Health, String)>

The plugin’s last health::set: its state and message.

§tints: BTreeMap<String, u32>

Identity tints by machine or project id (view::surface_tint, view::identity_tint).

§requested: BTreeMap<String, (u32, u32)>

Sizes the plugin asked for, by surface (request_size), bounded as the host bounds them.

§labels: BTreeMap<String, String>

Labels the plugin set, by surface (set_label).

§carets: BTreeMap<String, (u32, u32)>

Carets the plugin set, by surface (set_caret): column and row.

Implementations§

Source§

impl MockHost

Source

pub fn http(self, method: &str, url_prefix: &str, response: Response) -> Self

Queues response for the next request of method (GET, POST, …; * for any) whose URL starts with url_prefix. Each queued answer is used once, in the order queued; a request nothing matches fails with Error::Unavailable.

Source

pub fn queue_http( &mut self, method: &str, url_prefix: &str, answer: Result<Response>, )

Queues an answer, a failure included (Error::Unavailable("timeout") is what a request past its timeout gets), on a running host: harness.host(|host| host.queue_http(...)).

Source

pub fn http_requests(&self) -> &[Request]

Every request the grants let through, in order, as the plugin built it (method, URL, headers, body, timeout, body cap).

Source

pub fn http_pending(&self) -> usize

Answers queued and not used yet.

Source§

impl MockHost

Source

pub fn websockets(&self) -> &[MockWebSocket]

The WebSockets the plugin opened, in order.

Source

pub fn websocket_event(&mut self, socket: u32, kind: &str, text: &str)

Delivers a socket’s news to the plugin as the host would (system.net.websocket): kind open, message (with text) or closed (with text as the reason).

Source

pub fn script(self, program: &str, script: ProcessScript) -> Self

Answers every spawn of program (as spawned, any arguments) with script. A later script for the same program wins.

Source

pub fn script_args( self, program: &str, args: &[&str], script: ProcessScript, ) -> Self

Answers spawns of program whose arguments start with args.

Source

pub fn processes(&self) -> &[MockProcess]

Every child the plugin spawned, in order.

Source

pub fn pane_launches(&self) -> &[MockPaneLaunch]

The watches the plugin holds. The panes the plugin opened, in order.

Source

pub fn watches(&self) -> &[MockWatch]

Source§

impl MockHost

Source

pub fn new(plugin_id: &str) -> Self

A host for plugin plugin_id with no grants, not driving.

Source

pub fn clock( self, wall_ms: u64, utc_offset_minutes: i32, time_zone: Option<&str>, ) -> Self

The viewer’s wall clock and time zone.

Source

pub fn singleton(self, epoch: u64) -> Self

Runs a daemon plugin as a singleton under lease epoch.

Source

pub fn machine(self, machine_id: &str) -> Self

The machine the plugin runs on.

Source

pub fn env(self, name: &str, value: &str) -> Self

Sets one variable of a daemon plugin’s environment.

Source

pub fn grant(self, grants: &[&str]) -> Self

Adds grants (the manifest’s grant keys).

Source

pub fn surface(self, id: &str, model: Model) -> Self

Declares a surface the way a manifest does, with no size yet.

Source

pub fn machine_surface(self, id: &str, model: Model) -> Self

Declares a machine.after surface: its instances are <surface>@<machine>.

Source

pub fn project_surface(self, id: &str, model: Model) -> Self

Declares a project.after surface: its instances are <surface>@<project>.

Source

pub fn driving(self, driving: bool) -> Self

Source

pub fn set_geometry(&mut self, id: &str, geometry: Geometry) -> Option<Event>

Sets a surface’s size, as the viewer’s layout does. Returns the resize event to deliver (the Harness delivers it).

Source

pub fn set_model(&mut self, id: &str, model: Model) -> Option<Event>

Switches the model the viewer uses for a surface that lists several: the plugin sees it as a resize.

Source

pub fn commits(&self, id: &str) -> Vec<MockCommit>

Every commit of a surface, oldest first.

Trait Implementations§

Source§

impl Clone for MockHost

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockHost

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.