CockpitTestVariableDeclaration constructor
CockpitTestVariableDeclaration({
- required CockpitTestVariableSource source,
- required CockpitTestValueType valueType,
- Object? value = _absentVariableValue,
- Object? defaultValue = _absentVariableValue,
- bool required = true,
- String? secretReference,
Creates a CockpitTestVariableDeclaration.
Implementation
CockpitTestVariableDeclaration({
required this.source,
required this.valueType,
Object? value = _absentVariableValue,
Object? defaultValue = _absentVariableValue,
this.required = true,
this.secretReference,
}) : hasValue = !identical(value, _absentVariableValue),
value = identical(value, _absentVariableValue)
? null
: _typedVariableValue(value, valueType, r'$.value'),
hasDefaultValue = !identical(defaultValue, _absentVariableValue),
defaultValue = identical(defaultValue, _absentVariableValue)
? null
: _typedVariableValue(defaultValue, valueType, r'$.default') {
switch (source) {
case CockpitTestVariableSource.constant:
if (!hasValue || hasDefaultValue || secretReference != null) {
throw const FormatException(
'A constant variable requires value and forbids default/reference.',
);
}
case CockpitTestVariableSource.input:
if (hasValue || secretReference != null) {
throw const FormatException(
'An input variable forbids value and secret reference.',
);
}
case CockpitTestVariableSource.secret:
if (valueType != CockpitTestValueType.string ||
hasValue ||
hasDefaultValue ||
secretReference == null ||
secretReference!.trim().isEmpty) {
throw const FormatException(
'A secret variable must be a string reference without a value.',
);
}
}
}