buffet: PropType::CreateValue() should do constraint validation
Make PropType::CreateValue(v,...) validate the value against type
contraints which eliminates additional ValidateConstraints() call
and ensure the produced values conforms to the type schema specified.
Also parameter-less PropType::CreateValue() should use the default
value specified in PropType when constructing the value.
BUG=brillo:107
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I3712b8e0a14515c153c987078863b2904c89cafd
Reviewed-on: https://chromium-review.googlesource.com/262205
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/states/state_package.cc b/buffet/states/state_package.cc
index a023c14..1292339 100644
--- a/buffet/states/state_package.cc
+++ b/buffet/states/state_package.cc
@@ -39,11 +39,7 @@
for (const auto& pair : schema.GetProps()) {
types_.AddProp(pair.first, pair.second->Clone());
// Create default value for this state property.
- if (pair.second->GetDefaultValue()) {
- values_.emplace(pair.first, pair.second->GetDefaultValue()->Clone());
- } else {
- values_.emplace(pair.first, pair.second->CreateValue());
- }
+ values_.emplace(pair.first, pair.second->CreateValue());
}
return true;