Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail CI with unused test files. #705

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading