CockpitTestVariableDeclaration constructor

CockpitTestVariableDeclaration({
  1. required CockpitTestVariableSource source,
  2. required CockpitTestValueType valueType,
  3. Object? value = _absentVariableValue,
  4. Object? defaultValue = _absentVariableValue,
  5. bool required = true,
  6. 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.',
        );
      }
  }
}