Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
env/
env/
*.lock
46 changes: 46 additions & 0 deletions workflow-with-state-management-poc/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
[package]
name = "test_util"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2.49"
serde = { version = "1.0.81", features = ["derive"] }
serde_json = "1.0.81"
serde_derive = "1.0.81"
anyhow = "1.0.56"
wasmtime = "0.36.0"
wasmtime-wasi = "0.36.0"
wasi-common = "0.36.0"
bytes = "1"
futures = "0.3"
http = "0.2"
reqwest = { version = "0.11", default-features = true, features = [
"json",
"blocking",
] }
thiserror = "1.0"
tokio = { version = "1.4.0", features = ["full"] }
tracing = { version = "0.1", features = ["log"] }
url = "2.2.1"
openssl = { version = "0.10", features = ["vendored"] }
openwhisk-client-rust = { git = "https://github.com/HugoByte/openwhisk-client-rust.git", branch = "master" }
wiremock = "0.5.17"
async-std = { version = "1.12.0", features = ["attributes"] }
dyn-clone = "1.0.7"
184 changes: 184 additions & 0 deletions workflow-with-state-management-poc/runtime/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
};

async fn create_server(add: &str) -> MockServer {
let listener = std::net::TcpListener::bind(add).unwrap();
MockServer::builder().listener(listener).start().await
}

pub async fn post(address: &str) -> MockServer {
let server = create_server(address).await;

let mut r = HashMap::new();
r.insert(
"maruthi".to_string(),
vec!["800".to_string(), "alto".to_string()],
);

let res = Cartype {
car_company_list: r,
};

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/cartype"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;
let res = ModelAvail {
models: vec!["800".to_string(), "alto".to_string()],
};

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/modelavail"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let mut r = HashMap::new();
r.insert("800".to_string(), 1200000);
r.insert("alto".to_string(), 1800000);

// let asd = serde_json::json!({
// "result" : r
// });

let res = ModelPrice {
model_price_list: r,
};
Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/modelsprice"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let res = Purchase {
message: String::from("Thank you for the purchase"),
};
Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/purchase"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let res = EmplyeeIds {
ids: vec![1, 2, 3, 4, 5],
};

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/employee_ids"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;
let res = GetSalary { salary: 10000000 };
Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/getsalaries"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let res = GetAddress {
address: "HugoByte".to_string(),
};

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/getaddress"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let res = vec!["Salary creditted for emp id 1 from Hugobyte "];

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/salary"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

let res = serde_json::json!({
"company" : "Hugobyte-Ai-Labs",
"company_reg_id": "851-Hugobyte-Ai-Labs",
});

Mock::given(method("POST"))
.and(path("/api/v1/namespaces/guest/actions/get_company_name"))
.respond_with(
ResponseTemplate::new(200)
.insert_header("Content-Type", "application/json")
.set_body_json(res),
)
.mount(&server)
.await;

server
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Cartype {
car_company_list: HashMap<String, Vec<String>>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ModelAvail {
models: Vec<String>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct ModelPrice {
model_price_list: HashMap<String, i32>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Purchase {
message: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct EmplyeeIds {
ids: Vec<i32>,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GetSalary {
salary: i32,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct GetAddress {
address: String,
}
Loading