@@ -8,12 +8,11 @@ namespace cloudevents {
8
8
namespace cloudevents_util {
9
9
10
10
using ::io::cloudevents::v1::CloudEvent;
11
- using ::io::cloudevents::v1::CloudEvent_CloudEventAttribute;
12
11
using ::google::protobuf::Timestamp;
13
12
using ::google::protobuf::util::TimeUtil;
14
13
15
- typedef absl::flat_hash_map<std::string, CloudEvent_CloudEventAttribute>
16
- CeAttrMap;
14
+ typedef io::cloudevents::v1:: CloudEvent_CloudEventAttribute CeAttr;
15
+ typedef absl::flat_hash_map<std::string, CeAttr> CeAttrMap;
17
16
18
17
TEST (CloudEventsUtilTest, IsValid_NoSource) {
19
18
CloudEvent cloud_event;
@@ -100,7 +99,7 @@ TEST(CloudEventsUtilTest, GetMetadata_OneOptional) {
100
99
cloud_event.set_source (" /test" );
101
100
cloud_event.set_spec_version (" 1.0" );
102
101
cloud_event.set_type (" test" );
103
- CloudEvent_CloudEventAttribute attr;
102
+ CeAttr attr;
104
103
attr.set_ce_string (" test_val" );
105
104
(*cloud_event.mutable_attributes ())[" test_key" ] = attr;
106
105
@@ -121,7 +120,7 @@ TEST(CloudEventsUtilTest, GetMetadata_TwoOptional) {
121
120
cloud_event.set_source (" /test" );
122
121
cloud_event.set_spec_version (" 1.0" );
123
122
cloud_event.set_type (" test" );
124
- CloudEvent_CloudEventAttribute attr;
123
+ CeAttr attr;
125
124
attr.set_ce_string (" test_val1" );
126
125
(*cloud_event.mutable_attributes ())[" test_key1" ] = attr;
127
126
attr.set_ce_string (" test_val2" );
@@ -185,7 +184,7 @@ TEST(CloudEventsUtilTest, SetMetadata_Optional) {
185
184
absl::Status set_meta = CloudEventsUtil::SetMetadata (" opt" , " arbitrary" ,
186
185
cloud_event);
187
186
188
- CloudEvent_CloudEventAttribute attr = cloud_event.attributes ().at (" opt" );
187
+ CeAttr attr = cloud_event.attributes ().at (" opt" );
189
188
190
189
ASSERT_TRUE (set_meta.ok ());
191
190
ASSERT_EQ (attr.ce_string (), " arbitrary" );
@@ -198,12 +197,46 @@ TEST(CloudEventsUtilTest, SetMetadata_Time) {
198
197
199
198
absl::Status set_meta = CloudEventsUtil::SetMetadata (" time" , timestamp_str,
200
199
cloud_event);
201
- CloudEvent_CloudEventAttribute attr = cloud_event.attributes ().at (" time" );
200
+ CeAttr attr = cloud_event.attributes ().at (" time" );
202
201
203
202
ASSERT_TRUE (set_meta.ok ());
204
203
ASSERT_EQ (TimeUtil::ToString (attr.ce_timestamp ()), timestamp_str);
205
204
}
206
205
206
+ TEST (CloudEventsUtilTest, SetMetadata_DataschemaValid) {
207
+ std::string valid_dataschema = " http:www/test.com?query" ;
208
+ CloudEvent cloud_event;
209
+
210
+ absl::Status set_meta = CloudEventsUtil::SetMetadata (" dataschema" ,
211
+ valid_dataschema, cloud_event);
212
+
213
+ ASSERT_TRUE (set_meta.ok ());
214
+ ASSERT_EQ (cloud_event.attributes ().at (" dataschema" ).ce_uri (),
215
+ valid_dataschema);
216
+ }
217
+
218
+ TEST (CloudEventsUtilTest, SetMetadata_DataschemaFragment) {
219
+ std::string valid_dataschema = " http:www/test.com?query#fragment" ;
220
+ CloudEvent cloud_event;
221
+
222
+ absl::Status set_meta = CloudEventsUtil::SetMetadata (" dataschema" ,
223
+ valid_dataschema, cloud_event);
224
+
225
+ ASSERT_FALSE (set_meta.ok ());
226
+ ASSERT_TRUE (absl::IsInvalidArgument (set_meta));
227
+ }
228
+
229
+ TEST (CloudEventsUtilTest, SetMetadata_DataschemaNoScheme) {
230
+ std::string valid_dataschema = " www/test.com?query" ;
231
+ CloudEvent cloud_event;
232
+
233
+ absl::Status set_meta = CloudEventsUtil::SetMetadata (" dataschema" ,
234
+ valid_dataschema, cloud_event);
235
+
236
+ ASSERT_FALSE (set_meta.ok ());
237
+ ASSERT_TRUE (absl::IsInvalidArgument (set_meta));
238
+ }
239
+
207
240
TEST (CloudEventsUtilTest, SetContentType) {
208
241
std::string type = " test" ;
209
242
CloudEvent cloud_event;
@@ -216,7 +249,7 @@ TEST(CloudEventsUtilTest, SetContentType) {
216
249
}
217
250
218
251
TEST (CloudEventsUtilTest, ToString_BoolFalse) {
219
- CloudEvent_CloudEventAttribute attr;
252
+ CeAttr attr;
220
253
attr.set_ce_boolean (false );
221
254
222
255
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -227,7 +260,7 @@ TEST(CloudEventsUtilTest, ToString_BoolFalse) {
227
260
}
228
261
229
262
TEST (CloudEventsUtilTest, ToString_BoolTrue) {
230
- CloudEvent_CloudEventAttribute attr;
263
+ CeAttr attr;
231
264
attr.set_ce_boolean (true );
232
265
233
266
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -238,7 +271,7 @@ TEST(CloudEventsUtilTest, ToString_BoolTrue) {
238
271
}
239
272
240
273
TEST (CloudEventsUtilTest, ToString_Integer) {
241
- CloudEvent_CloudEventAttribute attr;
274
+ CeAttr attr;
242
275
attr.set_ce_integer (88 );
243
276
244
277
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -249,7 +282,7 @@ TEST(CloudEventsUtilTest, ToString_Integer) {
249
282
}
250
283
251
284
TEST (CloudEventsUtilTest, ToString_String) {
252
- CloudEvent_CloudEventAttribute attr;
285
+ CeAttr attr;
253
286
attr.set_ce_string (" test" );
254
287
255
288
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -260,7 +293,7 @@ TEST(CloudEventsUtilTest, ToString_String) {
260
293
}
261
294
262
295
TEST (CloudEventsUtilTest, ToString_URI) {
263
- CloudEvent_CloudEventAttribute attr;
296
+ CeAttr attr;
264
297
attr.set_ce_uri (" https://google.com" );
265
298
266
299
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -271,7 +304,7 @@ TEST(CloudEventsUtilTest, ToString_URI) {
271
304
}
272
305
273
306
TEST (CloudEventsUtilTest, ToString_URIRef) {
274
- CloudEvent_CloudEventAttribute attr;
307
+ CeAttr attr;
275
308
attr.set_ce_uri_reference (" https://www.google.com/#fragment" );
276
309
277
310
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -284,7 +317,7 @@ TEST(CloudEventsUtilTest, ToString_URIRef) {
284
317
TEST (CloudEventsUtilTest, ToString_Timestamp) {
285
318
Timestamp timestamp = TimeUtil::GetCurrentTime ();
286
319
std::string timestamp_str = TimeUtil::ToString (timestamp);
287
- CloudEvent_CloudEventAttribute attr;
320
+ CeAttr attr;
288
321
attr.mutable_ce_timestamp ()-> MergeFrom (timestamp);
289
322
290
323
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
@@ -294,7 +327,7 @@ TEST(CloudEventsUtilTest, ToString_Timestamp) {
294
327
}
295
328
296
329
TEST (CloudEventsUtilTest, ToString_NotSet) {
297
- CloudEvent_CloudEventAttribute attr;
330
+ CeAttr attr;
298
331
299
332
cloudevents_absl::StatusOr<std::string> stringify_ce_type =
300
333
CloudEventsUtil::ToString (attr);
0 commit comments