Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from golemcloud/versioned-interface-example
Browse files Browse the repository at this point in the history
Test for exported interface with version
  • Loading branch information
vigoo authored Feb 27, 2024
2 parents 9627c06 + 91c9252 commit 12b9ebf
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
153 changes: 153 additions & 0 deletions tests/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,156 @@ fn exports_shopping_cart_resource_component() {

pretty_assertions::assert_eq!(metadata, expected);
}

#[test]
fn exports_shopping_cart_resource_versioned_component() {
let source_bytes = include_bytes!("../wasm/shopping-cart-resource-versioned.wasm");
let component: Component<IgnoreAllButMetadata> = Component::from_bytes(source_bytes).unwrap();

let state = AnalysisContext::new(component);
let metadata = state.get_top_level_exports().unwrap();

let expected = vec![AnalysedExport::Instance(AnalysedInstance {
name: "golem:it/[email protected]".to_string(),
funcs: vec![
AnalysedFunction {
name: "[constructor]cart".to_string(),
params: vec![AnalysedFunctionParameter {
name: "user-id".to_string(),
typ: AnalysedType::Str,
}],
results: vec![AnalysedFunctionResult {
name: None,
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Owned,
},
}],
},
AnalysedFunction {
name: "[method]cart.add-item".to_string(),
params: vec![
AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
},
AnalysedFunctionParameter {
name: "item".to_string(),
typ: AnalysedType::Record(vec![
("product-id".to_string(), AnalysedType::Str),
("name".to_string(), AnalysedType::Str),
("price".to_string(), AnalysedType::F32),
("quantity".to_string(), AnalysedType::U32),
]),
},
],
results: vec![],
},
AnalysedFunction {
name: "[method]cart.remove-item".to_string(),
params: vec![
AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
},
AnalysedFunctionParameter {
name: "product-id".to_string(),
typ: AnalysedType::Str,
},
],
results: vec![],
},
AnalysedFunction {
name: "[method]cart.update-item-quantity".to_string(),
params: vec![
AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
},
AnalysedFunctionParameter {
name: "product-id".to_string(),
typ: AnalysedType::Str,
},
AnalysedFunctionParameter {
name: "quantity".to_string(),
typ: AnalysedType::U32,
},
],
results: vec![],
},
AnalysedFunction {
name: "[method]cart.checkout".to_string(),
params: vec![AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
}],
results: vec![AnalysedFunctionResult {
name: None,
typ: AnalysedType::Variant(vec![
("error".to_string(), Some(AnalysedType::Str)),
(
"success".to_string(),
Some(AnalysedType::Record(vec![(
"order-id".to_string(),
AnalysedType::Str,
)])),
),
]),
}],
},
AnalysedFunction {
name: "[method]cart.get-cart-contents".to_string(),
params: vec![AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
}],
results: vec![AnalysedFunctionResult {
name: None,
typ: AnalysedType::List(Box::new(AnalysedType::Record(vec![
("product-id".to_string(), AnalysedType::Str),
("name".to_string(), AnalysedType::Str),
("price".to_string(), AnalysedType::F32),
("quantity".to_string(), AnalysedType::U32),
]))),
}],
},
AnalysedFunction {
name: "[method]cart.merge-with".to_string(),
params: vec![
AnalysedFunctionParameter {
name: "self".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
},
AnalysedFunctionParameter {
name: "other-cart".to_string(),
typ: AnalysedType::Resource {
id: AnalysedResourceId { value: 0 },
resource_mode: AnalysedResourceMode::Borrowed,
},
},
],
results: vec![],
},
],
})];

pretty_assertions::assert_eq!(metadata, expected);
}
Binary file added wasm/shopping-cart-resource-versioned.wasm
Binary file not shown.

0 comments on commit 12b9ebf

Please sign in to comment.