Skip to content

Commit

Permalink
Fail CI with unused test files. (#705)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Dec 3, 2024
1 parent d3c8d65 commit 3981d33
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/test-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,22 @@ jobs:
with:
path: coverage

- name: Display Missing Test Paths
- name: Collect Test File Names
run: |
find tests/. -name "*.yaml" | xargs realpath | jq -Rn '{ files: [inputs | "\(.)"] }' > test-files.json
- name: Display Unused Test Files
run: |
jq -r -sc '
(map(.stories) | add | unique) as $stories |
(map(.files) | add | unique) as $all |
$all-$stories |
.[]
' $(find ./ -name "test-spec-coverage-*.json") test-files.json > ./coverage/files.txt
cat ./coverage/files.txt | sed -e 's/^/::error::/'
test ! -s ./coverage/files.txt || { echo "::error::Unused test files detected."; exit 1; }
- name: Collect and Display Missing Test Paths
run: |
jq -r -sc '
(map(.operations) | add | unique) as $all |
Expand Down
12 changes: 11 additions & 1 deletion tools/src/tester/TestResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class TestResults {
protected _evaluated_operations?: Operation[]
protected _unevaluated_operations?: Operation[]
protected _operations?: Operation[]
protected _stories?: string[]

constructor(spec: MergedOpenApiSpec, evaluations: StoryEvaluations) {
this._spec = spec
Expand Down Expand Up @@ -59,6 +60,14 @@ export default class TestResults {
return this._operations
}

stories(): string[] {
if (this._stories !== undefined) return this._stories
this._stories = _.uniqWith(_.compact(_.flatMap(this._evaluations.evaluations, (evaluation) =>
evaluation.full_path
)), isEqual)
return this._stories
}

test_coverage(): SpecTestCoverage {
return {
summary: {
Expand All @@ -69,7 +78,8 @@ export default class TestResults {
) / 100 : 0
},
operations: this.operations(),
evaluated_operations: this.evaluated_operations()
evaluated_operations: this.evaluated_operations(),
stories: this.stories()
}
}

Expand Down
1 change: 1 addition & 0 deletions tools/src/tester/types/test.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export interface SpecTestCoverage {
},
operations: Operation[]
evaluated_operations: Operation[]
stories: string[]
}
3 changes: 3 additions & 0 deletions tools/tests/tester/TestResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ describe('TestResults', () => {
{ method: 'POST', path: '/cluster_manager' },
{ method: 'GET', path: '/index' },
{ method: 'GET', path: '/nodes' }
],
stories: [
'full_path'
]
})
fs.unlinkSync(filename)
Expand Down

0 comments on commit 3981d33

Please sign in to comment.