Skip to content

Commit

Permalink
Fixed tests in reqwest integration
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
  • Loading branch information
slinkydeveloper committed May 26, 2020
1 parent 0469153 commit 508213b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cloudevents-sdk-reqwest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ repository = "https://github.com/cloudevents/sdk-rust"
cloudevents-sdk = { version = "0.1.0", path = ".." }
lazy_static = "1.4.0"
bytes = "^0.5"
serde_json = "^1.0"

[dependencies.reqwest]
version = "0.10.4"
Expand All @@ -24,4 +23,6 @@ features = ["rustls-tls"]
[dev-dependencies]
mockito = "0.25.1"
tokio = { version = "^0.2", features = ["full"] }
url = { version = "^2.1" }
url = { version = "^2.1" }
serde_json = "^1.0"
chrono = { version = "^0.4", features = ["serde"] }
16 changes: 16 additions & 0 deletions cloudevents-sdk-reqwest/src/client_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ mod tests {
use super::*;
use mockito::mock;

use chrono::Utc;
use cloudevents::{EventBuilder, EventBuilderV10};
use serde_json::json;
use std::str::FromStr;
use url::Url;

#[tokio::test]
async fn test_response() {
let time = Utc::now();
let url = mockito::server_url();
let _m = mock("GET", "/")
.with_status(200)
Expand All @@ -129,11 +131,15 @@ mod tests {
.with_header("ce-type", "example.test")
.with_header("ce-source", "http://localhost")
.with_header("ce-someint", "10")
.with_header("ce-time", &time.to_rfc3339())
.create();

let expected = EventBuilderV10::new()
.id("0001")
.ty("example.test")
//TODO this is required now because the message deserializer implictly set default values
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
.time(time)
.source(Url::from_str("http://localhost").unwrap())
.extension("someint", "10")
.build()
Expand All @@ -148,6 +154,7 @@ mod tests {

#[tokio::test]
async fn test_response_with_full_data() {
let time = Utc::now();
let j = json!({"hello": "world"});

let url = mockito::server_url();
Expand All @@ -159,12 +166,16 @@ mod tests {
.with_header("ce-source", "http://localhost/")
.with_header("content-type", "application/json")
.with_header("ce-someint", "10")
.with_header("ce-time", &time.to_rfc3339())
.with_body(j.to_string())
.create();

let expected = EventBuilderV10::new()
.id("0001")
.ty("example.test")
//TODO this is required now because the message deserializer implictly set default values
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
.time(time)
.source(Url::from_str("http://localhost").unwrap())
.data("application/json", j.clone())
.extension("someint", "10")
Expand All @@ -180,10 +191,15 @@ mod tests {

#[tokio::test]
async fn test_structured_response_with_full_data() {
let time = Utc::now();

let j = json!({"hello": "world"});
let expected = EventBuilderV10::new()
.id("0001")
.ty("example.test")
//TODO this is required now because the message deserializer implictly set default values
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
.time(time)
.source(Url::from_str("http://localhost").unwrap())
.data("application/json", j.clone())
.extension("someint", "10")
Expand Down

0 comments on commit 508213b

Please sign in to comment.