-
Notifications
You must be signed in to change notification settings - Fork 37
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 * Apply suggestions from code review Rename object_stores to kv_stores Co-authored-by: Kevin P. Fleming <[email protected]> * changed author block, broadened error assertion on file not found errors, and renamed Object store to KVStore one place * CHANGELOG entry --------- Co-authored-by: Kevin P. Fleming <[email protected]> Co-authored-by: Kevin P. Fleming <[email protected]>
- Loading branch information
1 parent
7aedece
commit 0596f51
Showing
5 changed files
with
216 additions
and
5 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
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 |
---|---|---|
|
@@ -61,6 +61,36 @@ 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 a KV Store | ||
// and have the KV Store populated with it. | ||
const FASTLY_TOML: &str = r#" | ||
name = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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 | ||
|
@@ -232,6 +262,83 @@ viceroy_test!(kv_store_bad_configs, |is_component| { | |
_ => panic!(), | ||
} | ||
|
||
const BAD_10_FASTLY_TOML: &str = r#" | ||
name = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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 = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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 = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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 = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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) => { | ||
// We can't assert on the whole error message here as the next part of the string is platform-specific | ||
// where it says that it cannot find the file. | ||
assert!(e | ||
.to_string() | ||
.contains("invalid configuration for 'store_one'")); | ||
} | ||
_ => panic!(), | ||
} | ||
|
||
// Not a valid JSON file | ||
const BAD_14_FASTLY_TOML: &str = r#" | ||
name = "kv-store-test" | ||
description = "kv store test" | ||
authors = ["Gustav Wengel <[email protected]>"] | ||
language = "rust" | ||
[local_server] | ||
kv_stores.empty_store = [] | ||
kv_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" | ||
} |