Skip to content

Commit 78894a1

Browse files
committed
Refactor tests
Signed-off-by: Sebastian Ziebell <[email protected]>
1 parent a09eb40 commit 78894a1

File tree

1 file changed

+47
-89
lines changed

1 file changed

+47
-89
lines changed

cyclonedx-bom/src/models/organization.rs

Lines changed: 47 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ mod test {
9090

9191
use crate::{
9292
models::organization::{OrganizationalContact, OrganizationalEntity},
93-
prelude::{NormalizedString, Uri, Validate, ValidationResult},
93+
prelude::{NormalizedString, Uri, Validate},
9494
validation,
9595
};
9696

@@ -136,42 +136,24 @@ mod test {
136136
};
137137
let actual = contact.validate();
138138

139-
/*
140139
assert_eq!(
141140
actual,
142-
ValidationResult::Failed {
143-
reasons: vec![
144-
FailureReason {
145-
message:
146-
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
147-
.to_string(),
148-
context: ValidationContext(vec![ValidationPathComponent::Struct {
149-
struct_name: "OrganizationalContact".to_string(),
150-
field_name: "name".to_string()
151-
}])
152-
},
153-
FailureReason {
154-
message:
155-
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
156-
.to_string(),
157-
context: ValidationContext(vec![ValidationPathComponent::Struct {
158-
struct_name: "OrganizationalContact".to_string(),
159-
field_name: "email".to_string()
160-
}])
161-
},
162-
FailureReason {
163-
message:
164-
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
165-
.to_string(),
166-
context: ValidationContext(vec![ValidationPathComponent::Struct {
167-
struct_name: "OrganizationalContact".to_string(),
168-
field_name: "phone".to_string()
169-
}])
170-
}
171-
]
172-
}
173-
)
174-
*/
141+
vec![
142+
validation::field(
143+
"name",
144+
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
145+
),
146+
validation::field(
147+
"email",
148+
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
149+
),
150+
validation::field(
151+
"phone",
152+
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
153+
)
154+
]
155+
.into()
156+
);
175157
}
176158

177159
#[test]
@@ -183,21 +165,13 @@ mod test {
183165
};
184166
let actual = entity.validate();
185167

186-
/*
187168
assert_eq!(
188169
actual,
189-
ValidationResult::Failed {
190-
reasons: vec![FailureReason {
191-
message: "NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
192-
.to_string(),
193-
context: ValidationContext(vec![ValidationPathComponent::Struct {
194-
struct_name: "OrganizationalEntity".to_string(),
195-
field_name: "name".to_string()
196-
}])
197-
}]
198-
}
199-
)
200-
*/
170+
validation::field(
171+
"name",
172+
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
173+
)
174+
);
201175
}
202176

203177
#[test]
@@ -212,49 +186,33 @@ mod test {
212186
}]),
213187
};
214188
let actual = entity.validate();
215-
/*
189+
216190
assert_eq!(
217191
actual,
218-
ValidationResult::Failed {
219-
reasons: vec![
220-
FailureReason {
221-
message:
192+
vec![
193+
validation::field(
194+
"name",
195+
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
196+
),
197+
validation::list(
198+
"url",
199+
[(
200+
0,
201+
validation::custom("", ["Uri does not conform to RFC 3986"])
202+
)]
203+
),
204+
validation::list(
205+
"contact",
206+
[(
207+
0,
208+
validation::field(
209+
"name",
222210
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
223-
.to_string(),
224-
context: ValidationContext(vec![ValidationPathComponent::Struct {
225-
struct_name: "OrganizationalEntity".to_string(),
226-
field_name: "name".to_string()
227-
}])
228-
},
229-
FailureReason {
230-
message: "Uri does not conform to RFC 3986".to_string(),
231-
context: ValidationContext(vec![
232-
ValidationPathComponent::Struct {
233-
struct_name: "OrganizationalEntity".to_string(),
234-
field_name: "url".to_string()
235-
},
236-
ValidationPathComponent::Array { index: 0 }
237-
])
238-
},
239-
FailureReason {
240-
message:
241-
"NormalizedString contains invalid characters \\r \\n \\t or \\r\\n"
242-
.to_string(),
243-
context: ValidationContext(vec![
244-
ValidationPathComponent::Struct {
245-
struct_name: "OrganizationalEntity".to_string(),
246-
field_name: "contact".to_string()
247-
},
248-
ValidationPathComponent::Array { index: 0 },
249-
ValidationPathComponent::Struct {
250-
struct_name: "OrganizationalContact".to_string(),
251-
field_name: "name".to_string()
252-
}
253-
])
254-
}
255-
]
256-
}
257-
)
258-
*/
211+
)
212+
)]
213+
)
214+
]
215+
.into()
216+
);
259217
}
260218
}

0 commit comments

Comments
 (0)