diff --git a/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageConfig.test.ts b/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageConfig.test.ts new file mode 100644 index 00000000000..4a085a34f85 --- /dev/null +++ b/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageConfig.test.ts @@ -0,0 +1,26 @@ +/* + * Copyright Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { validateThresholdNumberIntervals } from '@red-hat-developer-hub/backstage-plugin-scorecard-node'; +import { PERCENTAGE_THRESHOLDS } from './CodeCoverageMetricProvider'; + +describe('CodeCoverageMetricProvider thresholds', () => { + it('PERCENTAGE_THRESHOLDS has valid number intervals', () => { + expect(() => + validateThresholdNumberIntervals(PERCENTAGE_THRESHOLDS.rules, 'number'), + ).not.toThrow(); + }); +}); diff --git a/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageMetricProvider.ts b/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageMetricProvider.ts index 977643140bb..ef3bd9ed6d6 100644 --- a/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageMetricProvider.ts +++ b/workspaces/scorecard/plugins/scorecard-backend-module-code-coverage/src/metricProviders/CodeCoverageMetricProvider.ts @@ -105,7 +105,7 @@ export const CODE_COVERAGE_AGGREGATE_KEYS: Record< branchMissed: { section: 'branch', field: 'missed' }, }; -const PERCENTAGE_THRESHOLDS: ThresholdConfig = { +export const PERCENTAGE_THRESHOLDS: ThresholdConfig = { rules: [ { key: 'success', expression: '>80' }, { key: 'warning', expression: '50-80' }, diff --git a/workspaces/scorecard/plugins/scorecard-backend-module-dependabot/src/metricProviders/DependabotConfig.test.ts b/workspaces/scorecard/plugins/scorecard-backend-module-dependabot/src/metricProviders/DependabotConfig.test.ts new file mode 100644 index 00000000000..21c9519b615 --- /dev/null +++ b/workspaces/scorecard/plugins/scorecard-backend-module-dependabot/src/metricProviders/DependabotConfig.test.ts @@ -0,0 +1,26 @@ +/* + * Copyright Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { validateThresholdNumberIntervals } from '@red-hat-developer-hub/backstage-plugin-scorecard-node'; +import { DEPENDABOT_THRESHOLDS } from './DependabotConfig'; + +describe('DependabotConfig thresholds', () => { + it('DEPENDABOT_THRESHOLDS has valid number intervals', () => { + expect(() => + validateThresholdNumberIntervals(DEPENDABOT_THRESHOLDS.rules, 'number'), + ).not.toThrow(); + }); +}); diff --git a/workspaces/scorecard/plugins/scorecard-backend-module-openssf/src/metricProviders/OpenSSFConfig.test.ts b/workspaces/scorecard/plugins/scorecard-backend-module-openssf/src/metricProviders/OpenSSFConfig.test.ts new file mode 100644 index 00000000000..ef0c8c9264c --- /dev/null +++ b/workspaces/scorecard/plugins/scorecard-backend-module-openssf/src/metricProviders/OpenSSFConfig.test.ts @@ -0,0 +1,26 @@ +/* + * Copyright Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { validateThresholdNumberIntervals } from '@red-hat-developer-hub/backstage-plugin-scorecard-node'; +import { OPENSSF_THRESHOLDS } from './OpenSSFConfig'; + +describe('OpenSSFConfig thresholds', () => { + it('OPENSSF_THRESHOLDS has valid number intervals', () => { + expect(() => + validateThresholdNumberIntervals(OPENSSF_THRESHOLDS.rules, 'number'), + ).not.toThrow(); + }); +}); diff --git a/workspaces/scorecard/plugins/scorecard-backend-module-sonarqube/src/metricProviders/SonarQubeConfig.test.ts b/workspaces/scorecard/plugins/scorecard-backend-module-sonarqube/src/metricProviders/SonarQubeConfig.test.ts index eb2aa79de94..4f36c2cae75 100644 --- a/workspaces/scorecard/plugins/scorecard-backend-module-sonarqube/src/metricProviders/SonarQubeConfig.test.ts +++ b/workspaces/scorecard/plugins/scorecard-backend-module-sonarqube/src/metricProviders/SonarQubeConfig.test.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { validateThresholdNumberIntervals } from '@red-hat-developer-hub/backstage-plugin-scorecard-node'; import { sonarqubeEntity } from '../../__fixtures__/sonarqubeEntity'; import { parseProjectKeyAnnotation, @@ -74,4 +75,16 @@ describe('SONARQUBE_NUMBER_THRESHOLDS', () => { ).toBeGreaterThan(0); }, ); + + it.each(SONARQUBE_NUMBER_METRICS)( + '%s thresholds have valid number intervals', + metricId => { + expect(() => + validateThresholdNumberIntervals( + SONARQUBE_NUMBER_THRESHOLDS[metricId].rules, + 'number', + ), + ).not.toThrow(); + }, + ); }); diff --git a/workspaces/scorecard/plugins/scorecard-node/src/utils/thresholds/intervals/validateThresholdNumberIntervals.test.ts b/workspaces/scorecard/plugins/scorecard-node/src/utils/thresholds/intervals/validateThresholdNumberIntervals.test.ts index 0ca481ef9f1..86b3c52c874 100644 --- a/workspaces/scorecard/plugins/scorecard-node/src/utils/thresholds/intervals/validateThresholdNumberIntervals.test.ts +++ b/workspaces/scorecard/plugins/scorecard-node/src/utils/thresholds/intervals/validateThresholdNumberIntervals.test.ts @@ -15,6 +15,7 @@ */ import type { ThresholdRule } from '@red-hat-developer-hub/backstage-plugin-scorecard-common'; +import { DEFAULT_NUMBER_THRESHOLDS } from '@red-hat-developer-hub/backstage-plugin-scorecard-common'; import { ThresholdConfigFormatError } from '../../../errors'; import { validateThresholdNumberIntervals } from './validateThresholdNumberIntervals'; @@ -166,6 +167,17 @@ describe('validateThresholdNumberIntervals', () => { }); }); + describe('built-in threshold constants', () => { + it('DEFAULT_NUMBER_THRESHOLDS has valid number intervals', () => { + expect(() => + validateThresholdNumberIntervals( + DEFAULT_NUMBER_THRESHOLDS.rules, + 'number', + ), + ).not.toThrow(); + }); + }); + describe('skips coverage check when applicable', () => { it('should not throw when there is only one number rule', () => { const rules: ThresholdRule[] = [{ key: 'success', expression: '<10' }];