-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0;9uAllow specifying a top-level file and format fields for KVStore.
This change allows keeping KVStore key/values in a separate file for easier sharing between environments, and allowing users to only gitignore the actual KVStore content without needing to ignore the whole fastly.toml file.0;9u
- Loading branch information
Showing
4 changed files
with
214 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ use crate::{ | |
viceroy_test, | ||
}; | ||
use hyper::{body::to_bytes, StatusCode}; | ||
use viceroy_lib::adapt::is_component; | ||
|
||
viceroy_test!(kv_store, |is_component| { | ||
const FASTLY_TOML: &str = r#" | ||
|
@@ -36,7 +37,7 @@ viceroy_test!(object_stores_backward_compat, |is_component| { | |
// the "file" key was named "path". This test ensures that both | ||
// still work. | ||
const FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
name = "kv-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
|
@@ -61,12 +62,42 @@ viceroy_test!(object_stores_backward_compat, |is_component| { | |
Ok(()) | ||
}); | ||
|
||
viceroy_test!(kv_store_allows_fetching_of_key_from_file, |is_component| { | ||
// This test checks that we can provide a "format" and a "file" | ||
// with a JSON dictionary inside it for an object store (aka KV Store) | ||
// and have the KV Store populated with it.git | ||
const FASTLY_TOML: &str = r#" | ||
name = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { file = "../test-fixtures/data/json-kv_store.json", format = "json" } | ||
"#; | ||
|
||
let resp = Test::using_fixture("kv_store.wasm") | ||
.adapt_component(is_component) | ||
.using_fastly_toml(FASTLY_TOML)? | ||
.against_empty() | ||
.await?; | ||
|
||
assert_eq!(resp.status(), StatusCode::OK); | ||
assert!(to_bytes(resp.into_body()) | ||
.await | ||
.expect("can read body") | ||
.to_vec() | ||
.is_empty()); | ||
|
||
Ok(()) | ||
}); | ||
|
||
viceroy_test!(object_store_backward_compat, |is_component| { | ||
// Previously the "object_stores" key was named "object_store" and | ||
// the "file" key was named "path". This test ensures that both | ||
// still work. | ||
const FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
name = "kv-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
|
@@ -232,6 +263,80 @@ viceroy_test!(kv_store_bad_configs, |is_component| { | |
_ => panic!(), | ||
} | ||
|
||
const BAD_10_FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { file = "../test-fixtures/data/json-kv_store.json" } | ||
"#; | ||
match Test::using_fixture("kv_store.wasm").using_fastly_toml(BAD_10_FASTLY_TOML) { | ||
Err(e) => assert_eq!("invalid configuration for 'store_one': When using a top-level 'file' to load data, both 'file' and 'format' must be set.", &e.to_string()), | ||
_ => panic!(), | ||
} | ||
|
||
const BAD_11_FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { format = "json" } | ||
"#; | ||
match Test::using_fixture("kv_store.wasm").using_fastly_toml(BAD_11_FASTLY_TOML) { | ||
Err(e) => assert_eq!("invalid configuration for 'store_one': When using a top-level 'file' to load data, both 'file' and 'format' must be set.", &e.to_string()), | ||
_ => panic!(), | ||
} | ||
|
||
const BAD_12_FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { file = "../test-fixtures/data/json-kv_store.json", format = "INVALID" } | ||
"#; | ||
match Test::using_fixture("kv_store.wasm").using_fastly_toml(BAD_12_FASTLY_TOML) { | ||
Err(e) => assert_eq!("invalid configuration for 'store_one': 'INVALID' is not a valid format for the config store. Supported format(s) are: 'json'.", &e.to_string()), | ||
_ => panic!(), | ||
} | ||
|
||
const BAD_13_FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { file = "../test-fixtures/data/ABSOLUTELY_NOT_A_REAL_PATH", format = "json" } | ||
"#; | ||
match Test::using_fixture("kv_store.wasm").using_fastly_toml(BAD_13_FASTLY_TOML) { | ||
Err(e) => assert_eq!( | ||
"invalid configuration for 'store_one': No such file or directory (os error 2)", | ||
&e.to_string() | ||
), | ||
_ => panic!(), | ||
} | ||
|
||
// Not a valid JSON file | ||
const BAD_14_FASTLY_TOML: &str = r#" | ||
name = "object-store-test" | ||
description = "object store test" | ||
authors = ["Jill Bryson <[email protected]>", "Rose McDowall <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
object_stores.empty_store = [] | ||
object_stores.store_one = { file = "../test-fixtures/data/kv-store.txt", format = "json" } | ||
"#; | ||
match Test::using_fixture("kv_store.wasm").using_fastly_toml(BAD_14_FASTLY_TOML) { | ||
Err(e) => assert_eq!("invalid configuration for 'store_one': The file is of the wrong format. The file is expected to contain a single JSON Object.", &e.to_string()), | ||
_ => panic!(), | ||
} | ||
|
||
Ok(()) | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"first": "This is some data", | ||
"second": "More data" | ||
} |