Skip to content

Commit dfe2bcc

Browse files
authored
Fix tests after refactoring URIRef (#116)
Signed-off-by: Jens Reimann <[email protected]>
1 parent 62ca1cd commit dfe2bcc

File tree

16 files changed

+74
-48
lines changed

16 files changed

+74
-48
lines changed

cloudevents-sdk-actix-web/src/server_request.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,10 @@ mod private {
144144
mod tests {
145145
use super::*;
146146
use actix_web::test;
147-
use url::Url;
148147

149148
use chrono::Utc;
150149
use cloudevents::{EventBuilder, EventBuilderV10};
151150
use serde_json::json;
152-
use std::str::FromStr;
153151

154152
#[actix_rt::test]
155153
async fn test_request() {
@@ -186,7 +184,7 @@ mod tests {
186184
let expected = EventBuilderV10::new()
187185
.id("0001")
188186
.ty("example.test")
189-
.source(Url::from_str("http://localhost").unwrap())
187+
.source("http://localhost")
190188
//TODO this is required now because the message deserializer implictly set default values
191189
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
192190
.time(time)

cloudevents-sdk-actix-web/src/server_response.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,19 @@ mod private {
107107
#[cfg(test)]
108108
mod tests {
109109
use super::*;
110-
use url::Url;
111110

112111
use actix_web::http::StatusCode;
113112
use actix_web::test;
114113
use cloudevents::{EventBuilder, EventBuilderV10};
115114
use futures::TryStreamExt;
116115
use serde_json::json;
117-
use std::str::FromStr;
118116

119117
#[actix_rt::test]
120118
async fn test_response() {
121119
let input = EventBuilderV10::new()
122120
.id("0001")
123121
.ty("example.test")
124-
.source(Url::from_str("http://localhost/").unwrap())
122+
.source("http://localhost/")
125123
.extension("someint", "10")
126124
.build()
127125
.unwrap();
@@ -164,7 +162,7 @@ mod tests {
164162
let input = EventBuilderV10::new()
165163
.id("0001")
166164
.ty("example.test")
167-
.source(Url::from_str("http://localhost").unwrap())
165+
.source("http://localhost")
168166
.data("application/json", j.clone())
169167
.extension("someint", "10")
170168
.build()
@@ -193,7 +191,7 @@ mod tests {
193191
);
194192
assert_eq!(
195193
resp.headers().get("ce-source").unwrap().to_str().unwrap(),
196-
"http://localhost/"
194+
"http://localhost"
197195
);
198196
assert_eq!(
199197
resp.headers()

cloudevents-sdk-reqwest/src/client_request.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ mod tests {
9595
use cloudevents::message::StructuredDeserializer;
9696
use cloudevents::{EventBuilder, EventBuilderV10};
9797
use serde_json::json;
98-
use url::Url;
9998

10099
#[tokio::test]
101100
async fn test_request() {
@@ -112,7 +111,7 @@ mod tests {
112111
let input = EventBuilderV10::new()
113112
.id("0001")
114113
.ty("example.test")
115-
.source(Url::from_str("http://localhost/").unwrap())
114+
.source("http://localhost/")
116115
.extension("someint", "10")
117116
.build()
118117
.unwrap();
@@ -147,7 +146,7 @@ mod tests {
147146
let input = EventBuilderV10::new()
148147
.id("0001")
149148
.ty("example.test")
150-
.source(Url::from_str("http://localhost").unwrap())
149+
.source("http://localhost/")
151150
.data("application/json", j.clone())
152151
.extension("someint", "10")
153152
.build()
@@ -173,7 +172,7 @@ mod tests {
173172
let input = EventBuilderV10::new()
174173
.id("0001")
175174
.ty("example.test")
176-
.source(Url::from_str("http://localhost").unwrap())
175+
.source("http://localhost")
177176
.data("application/json", j.clone())
178177
.extension("someint", "10")
179178
.build()

cloudevents-sdk-reqwest/src/client_response.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ mod tests {
139139
use chrono::Utc;
140140
use cloudevents::{EventBuilder, EventBuilderV10};
141141
use serde_json::json;
142-
use std::str::FromStr;
143-
use url::Url;
144142

145143
#[tokio::test]
146144
async fn test_response() {
@@ -162,7 +160,7 @@ mod tests {
162160
//TODO this is required now because the message deserializer implictly set default values
163161
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
164162
.time(time)
165-
.source(Url::from_str("http://localhost").unwrap())
163+
.source("http://localhost")
166164
.extension("someint", "10")
167165
.build()
168166
.unwrap();
@@ -204,7 +202,7 @@ mod tests {
204202
//TODO this is required now because the message deserializer implictly set default values
205203
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
206204
.time(time)
207-
.source(Url::from_str("http://localhost").unwrap())
205+
.source("http://localhost/")
208206
.data("application/json", j.to_string().into_bytes())
209207
.extension("someint", "10")
210208
.build()
@@ -234,7 +232,7 @@ mod tests {
234232
//TODO this is required now because the message deserializer implictly set default values
235233
// As soon as this defaulting doesn't happen anymore, we can remove it (Issues #40/#41)
236234
.time(time)
237-
.source(Url::from_str("http://localhost").unwrap())
235+
.source("http://localhost")
238236
.data("application/json", j.clone())
239237
.extension("someint", "10")
240238
.build()

cloudevents-sdk-warp/src/filter.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ async fn create_event(headers: HeaderMap, body: bytes::Bytes) -> Result<Event, R
4242
#[cfg(test)]
4343
mod tests {
4444
use super::to_event;
45-
use url::Url;
4645
use warp::test;
4746

4847
use chrono::Utc;
4948
use cloudevents::{EventBuilder, EventBuilderV10};
5049
use serde_json::json;
51-
use std::str::FromStr;
5250

5351
#[tokio::test]
5452
async fn test_request() {
@@ -110,7 +108,7 @@ mod tests {
110108
let expected = EventBuilderV10::new()
111109
.id("0001")
112110
.ty("example.test")
113-
.source(Url::from_str("http://localhost").unwrap())
111+
.source("http://localhost")
114112
.time(time)
115113
.data("application/json", j.to_string().into_bytes())
116114
.extension("someint", "10")

cloudevents-sdk-warp/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//! let routes = warp::any().map(|| {
3232
//! let event = EventBuilderV10::new()
3333
//! .id("1")
34-
//! .source(url::Url::parse("url://example_response/").unwrap())
34+
//! .source("url://example_response/")
3535
//! .ty("example.ce")
3636
//! .data(
3737
//! mime::APPLICATION_JSON.to_string(),

cloudevents-sdk-warp/src/reply.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ mod tests {
3131

3232
use cloudevents::{EventBuilder, EventBuilderV10};
3333
use serde_json::json;
34-
use std::str::FromStr;
35-
use url::Url;
3634

3735
#[test]
3836
fn test_response() {
3937
let input = EventBuilderV10::new()
4038
.id("0001")
4139
.ty("example.test")
42-
.source(Url::from_str("http://localhost/").unwrap())
40+
.source("http://localhost/")
4341
.extension("someint", "10")
4442
.build()
4543
.unwrap();
@@ -79,7 +77,7 @@ mod tests {
7977
let input = EventBuilderV10::new()
8078
.id("0001")
8179
.ty("example.test")
82-
.source(Url::from_str("http://localhost").unwrap())
80+
.source("http://localhost")
8381
.data("application/json", j.clone())
8482
.extension("someint", "10")
8583
.build()
@@ -105,7 +103,7 @@ mod tests {
105103
);
106104
assert_eq!(
107105
resp.headers().get("ce-source").unwrap().to_str().unwrap(),
108-
"http://localhost/"
106+
"http://localhost"
109107
);
110108
assert_eq!(
111109
resp.headers()

src/event/builder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,17 @@ pub enum Error {
4444
source: chrono::ParseError,
4545
},
4646
#[snafu(display(
47-
"Error while setting attribute '{}' with uri/uriref type: {}",
47+
"Error while setting attribute '{}' with uri type: {}",
4848
attribute_name,
4949
source
5050
))]
5151
ParseUrlError {
5252
attribute_name: &'static str,
5353
source: url::ParseError,
5454
},
55+
#[snafu(display(
56+
"Invalid value setting attribute '{}' with uriref type",
57+
attribute_name,
58+
))]
59+
InvalidUriRefError { attribute_name: &'static str },
5560
}

src/event/v03/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod tests {
251251
assert_eq!(
252252
(
253253
"source",
254-
AttributeValue::URIRef(&Url::parse("https://example.net").unwrap())
254+
AttributeValue::URIRef(&"https://example.net".to_string())
255255
),
256256
b.next().unwrap()
257257
);

src/event/v03/builder.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ impl EventBuilder {
3131
}
3232

3333
pub fn source(mut self, source: impl Into<String>) -> Self {
34-
self.source = Some(source.into());
34+
let source = source.into();
35+
if source.is_empty() {
36+
self.error = Some(EventBuilderError::InvalidUriRefError {
37+
attribute_name: "source",
38+
});
39+
} else {
40+
self.source = Some(source);
41+
}
3542
self
3643
}
3744

0 commit comments

Comments
 (0)