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

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
- Replace test server
- Closes #46
- Closes #45
- Closes #43
  • Loading branch information
ChriFo committed Apr 12, 2021
1 parent dcd5434 commit 37e163b
Show file tree
Hide file tree
Showing 13 changed files with 1,379 additions and 1,715 deletions.
2,299 changes: 945 additions & 1,354 deletions Cargo.lock

Large diffs are not rendered by default.

37 changes: 18 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,31 @@ crate-type = ["cdylib"]

[dependencies]
antidote = "1.0.0"
anyhow = "1.0.32"
chrono = "0.4.15"
data-encoding = "2.3.0"
anyhow = "1.0.40"
chrono = "0.4.19"
data-encoding = "2.3.2"
fern = "0.6.0"
log = "0.4.11"
once_cell = "1.4.1"
serde = "1.0.115"
serde_derive = "1.0.115"
serde_json = "1.0.57"
ureq = { version = "1.4.0", features = ["json"] }
url = "2.1.1"
log = "0.4.14"
once_cell = "1.7.2"
serde = "1.0.125"
serde_derive = "1.0.125"
serde_json = "1.0.64"
ureq = { version = "2.1.0", features = ["json"] }
url = "2.2.1"

[dependencies.config]
version = "0.10.1"
version = "0.11.0"
default-features = false
features = ["ini", "json", "yaml"]

[dev-dependencies]
const-cstr = "0.3.0"
dlopen = "0.1.8"
futures-timer = "3.0.2"
rand = "0.7.3"
serial_test = "0.5.0"
spectral = "0.6.0"
tempfile = "3.1.0"
test-server = { git = "https://github.com/ChriFo/test-server-rs", tag = "0.9.0" }
async-std = { version = "*", features = ["attributes"] }
dlopen = "*"
rand = "*"
serial_test = "*"
spectral = "*"
tempfile = "*"
wiremock = "*"

[target.'cfg(windows)'.build-dependencies]
winres = "0.1.11"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 eHealth Experts GmbH
Copyright (c) 2021 eHealth Experts GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
124 changes: 67 additions & 57 deletions src/ctapi/close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ mod tests {

use super::close;
use crate::{ctapi::MAP, Status};
use std::env;
use test_server::{self, HttpResponse};
use std::env::{remove_var, set_var};
use wiremock::{matchers, Mock, MockServer, ResponseTemplate};

#[test]
#[serial]
fn returns_err_if_no_server() {
env::set_var("K2_BASE_URL", "http://127.0.0.1:65432");
set_var("K2_BASE_URL", "http://127.0.0.1:65432");
crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
Expand All @@ -58,8 +58,7 @@ mod tests {
let _ = MAP.write().insert(ctn, pn);

assert!(close(ctn).is_err());

env::remove_var("K2_BASE_URL");
remove_var("K2_BASE_URL");
}

#[test]
Expand All @@ -69,78 +68,85 @@ mod tests {
assert_eq!(Some(Status::ERR_INVALID), close(ctn).ok());
}

#[test]
#[async_std::test]
#[serial]
fn use_ctn_and_pn_in_request_path() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", HttpResponse::BadRequest)?;
env::set_var("K2_BASE_URL", server.url());
async fn use_ctn_and_pn_in_request_path() {
crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
let pn = rand::random::<u16>();
let _ = MAP.write().insert(ctn, pn);

let _ = close(ctn);
let mock_server = MockServer::start().await;
let mock = Mock::given(matchers::path(format!("/ct_close/{}/{}", ctn, pn)))
.respond_with(ResponseTemplate::new(200));
mock_server.register(mock).await;

let req = server.requests.next().unwrap();
assert_eq!(req.uri().path(), &format!("/ct_close/{}/{}", ctn, pn));
set_var("K2_BASE_URL", mock_server.uri());

env::remove_var("K2_BASE_URL");
let _ = close(ctn);

Ok(())
remove_var("K2_BASE_URL");
}

#[test]
#[async_std::test]
#[serial]
fn use_ctn_and_pn_from_config() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", HttpResponse::BadRequest)?;
env::set_var("K2_BASE_URL", server.url());
async fn use_ctn_and_pn_from_config() {
let ctn = rand::random::<u16>();
env::set_var("K2_CTN", format!("{}", ctn));
set_var("K2_CTN", format!("{}", ctn));
let pn = rand::random::<u16>();
env::set_var("K2_PN", format!("{}", pn));
crate::tests::init_config_clear_map();
set_var("K2_PN", format!("{}", pn));

crate::tests::init_config_clear_map();
let _ = MAP.write().insert(ctn, pn);

let mock_server = MockServer::start().await;
let mock = Mock::given(matchers::path(format!("/ct_close/{}/{}", ctn, pn)))
.respond_with(ResponseTemplate::new(200));
mock_server.register(mock).await;
set_var("K2_BASE_URL", mock_server.uri());

let unused_ctn = rand::random::<u16>();

let _ = close(unused_ctn);

let req = server.requests.next().unwrap();
assert_eq!(req.uri().path(), &format!("/ct_close/{}/{}", ctn, pn));

env::remove_var("K2_BASE_URL");
env::remove_var("K2_CTN");
env::remove_var("K2_PN");

Ok(())
remove_var("K2_BASE_URL");
remove_var("K2_CTN");
remove_var("K2_PN");
}

#[test]
#[async_std::test]
#[serial]
fn returns_err_htsi_if_server_response_is_not_200() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", HttpResponse::BadRequest)?;
env::set_var("K2_BASE_URL", server.url());
async fn returns_err_htsi_if_server_response_is_not_200() {
crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
let pn = rand::random::<u16>();
let _ = MAP.write().insert(ctn, pn);

let mock_server = MockServer::start().await;
Mock::given(matchers::any())
.respond_with(ResponseTemplate::new(400))
.mount(&mock_server)
.await;
set_var("K2_BASE_URL", mock_server.uri());

assert!(close(ctn).is_err());
assert_eq!(true, MAP.read().contains_key(&ctn));

env::remove_var("K2_BASE_URL");

Ok(())
remove_var("K2_BASE_URL");
}

#[test]
#[async_std::test]
#[serial]
fn returns_err_htsi_if_server_response_not_contains_status() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", || HttpResponse::Ok().body("hello world"))?;
env::set_var("K2_BASE_URL", server.url());
async fn returns_err_htsi_if_server_response_not_contains_status() {
let mock_server = MockServer::start().await;
Mock::given(matchers::any())
.respond_with(ResponseTemplate::new(200).set_body_string("hello world"))
.mount(&mock_server)
.await;
set_var("K2_BASE_URL", mock_server.uri());

crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
Expand All @@ -150,16 +156,19 @@ mod tests {
assert!(close(ctn).is_err());
assert_eq!(true, MAP.read().contains_key(&ctn));

env::remove_var("K2_BASE_URL");

Ok(())
remove_var("K2_BASE_URL");
}

#[test]
#[async_std::test]
#[serial]
fn returns_response_status_from_server() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", || HttpResponse::Ok().body("-11"))?;
env::set_var("K2_BASE_URL", server.url());
async fn returns_response_status_from_server() {
let mock_server = MockServer::start().await;
Mock::given(matchers::any())
.respond_with(ResponseTemplate::new(200).set_body_json(-11))
.mount(&mock_server)
.await;
set_var("K2_BASE_URL", mock_server.uri());

crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
Expand All @@ -169,16 +178,19 @@ mod tests {
assert_eq!(Some(Status::ERR_MEMORY), close(ctn).ok());
assert_eq!(true, MAP.read().contains_key(&ctn));

env::remove_var("K2_BASE_URL");

Ok(())
remove_var("K2_BASE_URL");
}

#[test]
#[async_std::test]
#[serial]
fn return_ok_and_close_ctn_if_server_returns_ok() -> anyhow::Result<()> {
let server = test_server::new("127.0.0.1:0", || HttpResponse::Ok().body("0"))?;
env::set_var("K2_BASE_URL", server.url());
async fn return_ok_and_close_ctn_if_server_returns_ok() {
let mock_server = MockServer::start().await;
Mock::given(matchers::any())
.respond_with(ResponseTemplate::new(200).set_body_json(0))
.mount(&mock_server)
.await;
set_var("K2_BASE_URL", mock_server.uri());

crate::tests::init_config_clear_map();

let ctn = rand::random::<u16>();
Expand All @@ -188,8 +200,6 @@ mod tests {
assert_eq!(Some(Status::OK), close(ctn).ok());
assert_eq!(false, MAP.read().contains_key(&ctn));

env::remove_var("K2_BASE_URL");

Ok(())
remove_var("K2_BASE_URL");
}
}
Loading

0 comments on commit 37e163b

Please # to comment.