func validateDashboardTab()

in config/config.go [423:475]


func validateDashboardTab(dt *configpb.DashboardTab) error {
	var mErr error
	if dt == nil {
		return multierror.Append(mErr, errors.New("got an empty DashboardTab"))
	}

	// Check that required fields are a non-zero-value.
	if dt.GetTestGroupName() == "" {
		mErr = multierror.Append(mErr, errors.New("test_group_name can't be empty"))
	}

	// A Dashboard Tab can't be named the same as the default 'Summary' tab.
	if dt.GetName() == "Summary" {
		mErr = multierror.Append(mErr, errors.New("tab can't be named 'Summary'"))
	}

	// TabularNamesRegex should be valid and have capture groups defined.
	if dt.GetTabularNamesRegex() != "" {
		regex, err := regexp.Compile(dt.GetTabularNamesRegex())
		if err != nil {
			mErr = multierror.Append(
				mErr,
				fmt.Errorf("invalid regex %s: %v", dt.GetTabularNamesRegex(), err))
		} else {
			var names []string
			for _, subexpName := range regex.SubexpNames() {
				if subexpName != "" {
					names = append(names, subexpName)
				}
			}
			if regex.NumSubexp() != len(names) {
				mErr = multierror.Append(mErr, errors.New("all tabular_name_regex capture groups must be named"))
			}
			if len(names) < 1 {
				mErr = multierror.Append(mErr, errors.New("tabular_name_regex requires at least one capture group"))
			}
		}
	}

	// Email address for alerts should be valid.
	if dt.GetAlertOptions().GetAlertMailToAddresses() != "" {
		if err := validateEmails(dt.GetAlertOptions().GetAlertMailToAddresses()); err != nil {
			mErr = multierror.Append(mErr, err)
		}
	}

	// Max acceptable flakiness parameter should be valid (between 0.0 and 100.0 - both inclusive).
	if maxAcceptableFlakiness := dt.GetStatusCustomizationOptions().GetMaxAcceptableFlakiness(); maxAcceptableFlakiness < 0 || maxAcceptableFlakiness > 100 {
		mErr = multierror.Append(mErr, errors.New("invalid value provided for max_acceptable_flakiness (should be between 0.0 and 100.0)"))
	}

	return mErr
}