marine/fluence-faas/tests/call_parameters.rs

68 lines
2.5 KiB
Rust
Raw Normal View History

2020-09-14 11:22:56 +00:00
/*
* Copyright 2020 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use fluence_faas::FluenceFaaS;
use fluence_faas::IValue;
2020-10-21 19:21:16 +00:00
use pretty_assertions::assert_eq;
2020-09-14 11:22:56 +00:00
#[test]
pub fn call_parameters() {
let call_parameters_config_path = "../examples/call_parameters/Config.toml";
let call_parameters_config_raw = std::fs::read(call_parameters_config_path)
.expect("../examples/call_parameters/Config.toml should presence");
2020-10-01 09:19:38 +00:00
let mut call_parameters_config: fluence_faas::TomlFaaSConfig =
2020-09-14 11:22:56 +00:00
toml::from_slice(&call_parameters_config_raw)
.expect("call_parameters config should be well-formed");
call_parameters_config.modules_dir =
Some(String::from("../examples/call_parameters/artifacts"));
let mut faas = FluenceFaaS::with_raw_config(call_parameters_config)
2021-03-16 10:51:59 +00:00
.unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e));
2020-09-14 11:22:56 +00:00
2020-12-22 13:06:49 +00:00
let init_peer_id = "init_peer_id";
let service_id = "service_id";
let service_creator_peer_id = "service_creator_peer_id";
let host_id = "host_id";
let particle_id = "particle_id";
2020-09-14 11:22:56 +00:00
2020-12-21 16:34:25 +00:00
let tetraplet = fluence_sdk_main::SecurityTetraplet::default();
2020-12-22 13:06:49 +00:00
let tetraplets = vec![vec![tetraplet]];
2020-12-21 16:34:25 +00:00
let call_parameters = fluence_sdk_main::CallParameters {
2020-12-22 13:06:49 +00:00
init_peer_id: init_peer_id.to_string(),
service_id: service_id.to_string(),
service_creator_peer_id: service_creator_peer_id.to_string(),
host_id: host_id.to_string(),
particle_id: particle_id.to_string(),
tetraplets: tetraplets.clone(),
2020-12-21 16:34:25 +00:00
};
2020-09-14 11:22:56 +00:00
let result = faas
2020-12-21 16:34:25 +00:00
.call_with_ivalues("call_parameters", "call_parameters", &[], call_parameters)
2020-09-14 11:22:56 +00:00
.unwrap_or_else(|e| panic!("can't invoke call_parameters: {:?}", e));
assert_eq!(
result,
vec![IValue::String(format!(
2020-12-22 13:06:49 +00:00
"{}\n{}\n{}\n{}\n{}\n{:?}",
init_peer_id, service_id, service_creator_peer_id, host_id, particle_id, tetraplets
2020-09-14 11:22:56 +00:00
))]
);
}