Skip to content

Commit

Permalink
Fix formatting issues via cargo fmt --all
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Aug 17, 2021
1 parent 9782342 commit 0d641bd
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
5 changes: 1 addition & 4 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Fastly-specific configuration utilities.

use {
self::{
backends::BackendsConfig,
dictionaries::DictionariesConfig
},
self::{backends::BackendsConfig, dictionaries::DictionariesConfig},
crate::error::FastlyConfigError,
serde_derive::Deserialize,
std::{collections::HashMap, convert::TryInto, fs, path::Path, str::FromStr, sync::Arc},
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/limits.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// From https://docs.fastly.com/en/guides/resource-limits#vcl-and-configuration-limits
pub const DICTIONARY_MAX_LEN: usize = 1000;
pub const DICTIONARY_ITEM_KEY_MAX_LEN: usize = 256;
pub const DICTIONARY_ITEM_VALUE_MAX_LEN: usize = 8000;
pub const DICTIONARY_ITEM_VALUE_MAX_LEN: usize = 8000;
43 changes: 26 additions & 17 deletions lib/src/config/unit_tests.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use crate::config::dictionaries::DictionaryFormat;

use {
crate::config::DictionaryName,
std::{
fs::File,
io::Write,
},
super::{FastlyConfig, LocalServerConfig, RawLocalServerConfig},
crate::config::DictionaryName,
std::{fs::File, io::Write},
tempfile::tempdir,
};


#[test]
fn fastly_toml_files_can_be_read() {
// Parse a valid `fastly.toml`, check that it succeeds.
Expand Down Expand Up @@ -134,7 +130,7 @@ fn fastly_toml_files_with_simple_dictionary_configurations_can_be_read() {
/// the tests above.
mod local_server_config_tests {
use std::fs::File;
use std::io::Write;
use std::io::Write;
use tempfile::tempdir;

use {
Expand Down Expand Up @@ -336,10 +332,13 @@ mod local_server_config_tests {
writeln!(file, "{{}}").unwrap();

use DictionaryConfigError::UnrecognizedKey;
let bad_default = format!(r#"
let bad_default = format!(
r#"
[dictionaries]
thing = {{ file = "{}", format = "json", shrimp = true }}
"#, file_path.to_str().unwrap());
"#,
file_path.to_str().unwrap()
);
match read_toml_config(&bad_default) {
Err(InvalidDictionaryDefinition {
err: UnrecognizedKey(key),
Expand Down Expand Up @@ -373,10 +372,13 @@ mod local_server_config_tests {
let mut file = File::create(&file_path).unwrap();
writeln!(file, "{{}}").unwrap();

let no_format_field = format!(r#"
let no_format_field = format!(
r#"
[dictionaries]
"thing" = {{ file = "{}" }}
"#, file_path.to_str().unwrap());
"#,
file_path.to_str().unwrap()
);
match read_toml_config(&no_format_field) {
Err(InvalidDictionaryDefinition {
err: MissingFormat, ..
Expand All @@ -393,10 +395,13 @@ mod local_server_config_tests {
let mut file = File::create(&file_path).unwrap();
writeln!(file, "{{}}").unwrap();

let bad_name_field = format!(r#"
let bad_name_field = format!(
r#"
[dictionaries]
"1" = {{ file = "{}", format = "json" }}
"#, file_path.to_str().unwrap());
"#,
file_path.to_str().unwrap()
);
match read_toml_config(&bad_name_field) {
Err(InvalidDictionaryDefinition {
err: InvalidName(_),
Expand Down Expand Up @@ -477,11 +482,15 @@ mod local_server_config_tests {
let mut file = File::create(&file_path).unwrap();
writeln!(file, "{{}}").unwrap();

let dictionary = format!(r#"
let dictionary = format!(
r#"
[dictionaries]
"thing" = {{ file = "{}", format = "json" }}
"#, file_path.to_str().unwrap());
read_toml_config(&dictionary)
.expect("can read toml data containing local dictionary configurations using json format");
"#,
file_path.to_str().unwrap()
);
read_toml_config(&dictionary).expect(
"can read toml data containing local dictionary configurations using json format",
);
}
}
33 changes: 20 additions & 13 deletions lib/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use {
crate::{
config::DictionaryName,
wiggle_abi::types::{DictionaryHandle, FastlyStatus}
wiggle_abi::types::{DictionaryHandle, FastlyStatus},
},
url::Url,
wiggle::GuestError,
Expand Down Expand Up @@ -284,11 +284,8 @@ pub enum BackendConfigError {
pub enum DictionaryConfigError {
/// An I/O error that occured while reading the file.
#[error("error reading `{name}`: {error}")]
IoError {
name: String,
error: String,
},

IoError { name: String, error: String },

#[error("definition was not provided as a TOML table")]
InvalidEntryType,

Expand All @@ -303,7 +300,7 @@ pub enum DictionaryConfigError {

#[error("'file' field is empty")]
EmptyFileEntry,

#[error("'format' field is empty")]
EmptyFormatEntry,

Expand All @@ -329,19 +326,29 @@ pub enum DictionaryConfigError {
UnrecognizedKey(String),

#[error("Item key named '{key}' in dictionary named '{name}' is too long, max size is {size}")]
DictionaryItemKeyTooLong{ key: String, name: String, size: i32 },
DictionaryItemKeyTooLong {
key: String,
name: String,
size: i32,
},

#[error("The dictionary named '{name}' has too many items, max amount is {size}")]
DictionaryCountTooLong{ name: String, size: i32 },
DictionaryCountTooLong { name: String, size: i32 },

#[error("Item value under key named '{key}' in dictionary named '{name}' is of the wrong format. The value is expected to be a JSON String")]
DictionaryItemValueWrongFormat{ key: String, name: String },
DictionaryItemValueWrongFormat { key: String, name: String },

#[error("Item value named '{key}' in dictionary named '{name}' is too long, max size is {size}")]
DictionaryItemValueTooLong{ key: String, name: String, size: i32 },
#[error(
"Item value named '{key}' in dictionary named '{name}' is too long, max size is {size}"
)]
DictionaryItemValueTooLong {
key: String,
name: String,
size: i32,
},

#[error("The file for the dictionary named '{name}' is of the wrong format. The file is expected to contain a single JSON Object")]
DictionaryFileWrongFormat{ name: String},
DictionaryFileWrongFormat { name: String },
}

/// Errors related to the downstream request.
Expand Down
5 changes: 1 addition & 4 deletions lib/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use {
crate::{
body::Body,
config::{
Backends,
Dictionaries
},
config::{Backends, Dictionaries},
downstream::prepare_request,
error::ExecutionError,
linking::{create_store, dummy_store, link_host_functions, WasmCtx},
Expand Down
15 changes: 7 additions & 8 deletions lib/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use {
streaming_body::StreamingBody,
upstream::{PendingRequest, SelectTarget},
wiggle_abi::types::{
BodyHandle, DictionaryHandle, EndpointHandle, PendingRequestHandle, RequestHandle, ResponseHandle,
BodyHandle, DictionaryHandle, EndpointHandle, PendingRequestHandle, RequestHandle,
ResponseHandle,
},
},
cranelift_entity::PrimaryMap,
Expand Down Expand Up @@ -505,23 +506,21 @@ impl Session {
pub fn backend(&self, name: &str) -> Option<&Backend> {
self.backends.get(name).map(std::ops::Deref::deref)
}

// ----- Dictionaries API -----

/// Look up a dictionary-handle by name.
pub fn dictionary_handle(&mut self, name: &str) -> Result<DictionaryHandle, Error> {
let name = DictionaryName::new(name.to_string());
Ok(self.dictionaries_by_name.push(name))
}

/// Look up a dictionary by dictionary-handle.
pub fn dictionary(&self, handle: DictionaryHandle) -> Result<&Dictionary, Error> {
match self.dictionaries_by_name.get(handle) {
Some(name) => {
match self.dictionaries.get(name) {
Some(dictionary) => Ok(dictionary),
None => Err(Error::UnknownDictionaryHandle(handle)),
}
Some(name) => match self.dictionaries.get(name) {
Some(dictionary) => Ok(dictionary),
None => Err(Error::UnknownDictionaryHandle(handle)),
},
None => Err(Error::UnknownDictionaryHandle(handle)),
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/wiggle_abi/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//! [ref]: https://docs.rs/cranelift-entity/latest/cranelift_entity/trait.EntityRef.html

use super::types::{
BodyHandle, DictionaryHandle, EndpointHandle, PendingRequestHandle, RequestHandle, ResponseHandle,
BodyHandle, DictionaryHandle, EndpointHandle, PendingRequestHandle, RequestHandle,
ResponseHandle,
};

/// Macro which implements a 32-bit entity reference for handles generated by Wiggle.
Expand Down

0 comments on commit 0d641bd

Please sign in to comment.