mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-17 18:27:49 +00:00
test: expand snapshot coverage (#4024)
This commit is contained in:
@@ -210,6 +210,7 @@ serial_test = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
aws-config = { workspace = true }
|
||||
anyhow = { workspace = true }
|
||||
insta = { workspace = true }
|
||||
proptest = "1"
|
||||
tokio = { workspace = true, features = ["test-util"] }
|
||||
temp-env = { workspace = true, features = ["async_closure"] }
|
||||
|
||||
@@ -382,9 +382,26 @@ mod tests {
|
||||
PluginInstanceDetail, PluginInstanceDiagnostic, PluginInstanceDiagnosticCode, PluginInstanceDiagnosticCount,
|
||||
PluginInstanceEntry, PluginInstanceSource, PluginInstancesResponse, PluginRuntimeContract, PluginRuntimeTransport,
|
||||
};
|
||||
use serde_json::json;
|
||||
use serde_json::{Value, json};
|
||||
use std::collections::HashMap;
|
||||
|
||||
fn sorted_json_value(value: Value) -> Value {
|
||||
match value {
|
||||
Value::Array(values) => Value::Array(values.into_iter().map(sorted_json_value).collect()),
|
||||
Value::Object(map) => {
|
||||
let mut entries = map.into_iter().collect::<Vec<_>>();
|
||||
entries.sort_by(|(left, _), (right, _)| left.cmp(right));
|
||||
Value::Object(
|
||||
entries
|
||||
.into_iter()
|
||||
.map(|(key, value)| (key, sorted_json_value(value)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
value => value,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plugin_catalog_contract_serializes_stable_json_shape() {
|
||||
let response = PluginCatalogResponse {
|
||||
@@ -418,7 +435,8 @@ mod tests {
|
||||
},
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(response).expect("catalog response should serialize");
|
||||
let value = sorted_json_value(serde_json::to_value(response).expect("catalog response should serialize"));
|
||||
insta::assert_json_snapshot!("plugin_catalog_contract", value);
|
||||
assert_eq!(
|
||||
value,
|
||||
json!({
|
||||
@@ -481,7 +499,8 @@ mod tests {
|
||||
next_marker: None,
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(response).expect("instance response should serialize");
|
||||
let value = sorted_json_value(serde_json::to_value(response).expect("instance response should serialize"));
|
||||
insta::assert_json_snapshot!("plugin_instance_contract", value);
|
||||
assert_eq!(
|
||||
value,
|
||||
json!({
|
||||
@@ -534,7 +553,8 @@ mod tests {
|
||||
}],
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(detail).expect("instance detail should serialize");
|
||||
let value = sorted_json_value(serde_json::to_value(detail).expect("instance detail should serialize"));
|
||||
insta::assert_json_snapshot!("plugin_instance_detail_contract", value);
|
||||
assert_eq!(
|
||||
value,
|
||||
json!({
|
||||
@@ -591,7 +611,8 @@ mod tests {
|
||||
installation: None,
|
||||
};
|
||||
|
||||
let value = serde_json::to_value(entry).expect("catalog entry should serialize");
|
||||
let value = sorted_json_value(serde_json::to_value(entry).expect("catalog entry should serialize"));
|
||||
insta::assert_json_snapshot!("plugin_catalog_distribution_contract", value);
|
||||
assert_eq!(value["distribution"]["artifacts"][0]["artifact_id"], "sidecar-linux-amd64");
|
||||
assert_eq!(value["distribution"]["artifacts"][0]["target_triple"], "x86_64-unknown-linux-gnu");
|
||||
assert_eq!(
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
---
|
||||
source: rustfs/src/admin/plugin_contract.rs
|
||||
expression: value
|
||||
---
|
||||
{
|
||||
"admin_discovery": {
|
||||
"clusterSnapshot": "/rustfs/admin/v4/cluster/snapshot",
|
||||
"extensionsCatalog": "/rustfs/admin/v4/extensions/catalog",
|
||||
"runtimeCapabilities": "/rustfs/admin/v4/runtime/capabilities"
|
||||
},
|
||||
"plugins": [
|
||||
{
|
||||
"api_compatibility_version": "rustfs.target-plugin.v1",
|
||||
"display_name": "Webhook",
|
||||
"distribution": null,
|
||||
"domain_configs": [
|
||||
{
|
||||
"domain": "notify",
|
||||
"subsystem": "notify_webhook",
|
||||
"valid_fields": [
|
||||
"endpoint",
|
||||
"auth_token"
|
||||
]
|
||||
}
|
||||
],
|
||||
"entrypoint_kind": "builtin",
|
||||
"packaging": "builtin",
|
||||
"plugin_id": "builtin:webhook",
|
||||
"provider": "rustfs",
|
||||
"runtime_contract": {
|
||||
"protocol_version": "rustfs.target-runtime.v1",
|
||||
"transport": "in_process"
|
||||
},
|
||||
"secret_fields": [
|
||||
"auth_token"
|
||||
],
|
||||
"supported_domains": [
|
||||
"audit",
|
||||
"notify"
|
||||
],
|
||||
"target_type": "webhook",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
---
|
||||
source: rustfs/src/admin/plugin_contract.rs
|
||||
expression: value
|
||||
---
|
||||
{
|
||||
"api_compatibility_version": "rustfs.target-plugin.v1",
|
||||
"display_name": "Webhook+",
|
||||
"distribution": {
|
||||
"artifacts": [
|
||||
{
|
||||
"artifact_id": "sidecar-linux-amd64",
|
||||
"digest_sha256": "0123456789abcdef",
|
||||
"download_uri": "https://plugins.example.test/webhook.tar.zst",
|
||||
"provenance_uri": "https://plugins.example.test/webhook.tar.zst.intoto.jsonl",
|
||||
"signature_uri": "https://plugins.example.test/webhook.tar.zst.sig",
|
||||
"size_bytes": 4096,
|
||||
"target_triple": "x86_64-unknown-linux-gnu"
|
||||
}
|
||||
]
|
||||
},
|
||||
"domain_configs": [],
|
||||
"entrypoint_kind": "sidecar",
|
||||
"packaging": "builtin",
|
||||
"plugin_id": "external:webhook",
|
||||
"provider": "example",
|
||||
"runtime_contract": {
|
||||
"protocol_version": "rustfs.target-runtime.v1",
|
||||
"transport": "grpc"
|
||||
},
|
||||
"secret_fields": [],
|
||||
"supported_domains": [
|
||||
"notify"
|
||||
],
|
||||
"target_type": "webhook",
|
||||
"version": "1.2.3"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
---
|
||||
source: rustfs/src/admin/plugin_contract.rs
|
||||
expression: value
|
||||
---
|
||||
{
|
||||
"diagnostic_counts": [
|
||||
{
|
||||
"code": "not_loaded_in_runtime",
|
||||
"count": 1
|
||||
}
|
||||
],
|
||||
"instances": [
|
||||
{
|
||||
"account_id": "primary",
|
||||
"config": {
|
||||
"enable": "on",
|
||||
"endpoint": "https://example.com/hook"
|
||||
},
|
||||
"diagnostic_codes": [
|
||||
"not_loaded_in_runtime"
|
||||
],
|
||||
"domain": "notify",
|
||||
"enabled": true,
|
||||
"id": "builtin:webhook:notify:primary",
|
||||
"plugin_id": "builtin:webhook",
|
||||
"service": "webhook",
|
||||
"source": "config",
|
||||
"status": "offline",
|
||||
"subsystem": "notify_webhook"
|
||||
}
|
||||
],
|
||||
"next_marker": null,
|
||||
"truncated": false
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
---
|
||||
source: rustfs/src/admin/plugin_contract.rs
|
||||
expression: value
|
||||
---
|
||||
{
|
||||
"account_id": "primary",
|
||||
"config": {
|
||||
"endpoint": "https://example.com/hook"
|
||||
},
|
||||
"diagnostic_codes": [
|
||||
"not_loaded_in_runtime"
|
||||
],
|
||||
"diagnostics": [
|
||||
{
|
||||
"code": "not_loaded_in_runtime",
|
||||
"message": "plugin instance is enabled in config but not currently loaded in runtime"
|
||||
}
|
||||
],
|
||||
"domain": "notify",
|
||||
"enabled": true,
|
||||
"id": "builtin:webhook:notify:primary",
|
||||
"plugin_id": "builtin:webhook",
|
||||
"service": "webhook",
|
||||
"source": "config",
|
||||
"status": "offline",
|
||||
"subsystem": "notify_webhook"
|
||||
}
|
||||
Reference in New Issue
Block a user