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

buildcop: handle a test suite with no tests #266

Merged
merged 2 commits into from
Feb 5, 2020
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
4 changes: 4 additions & 0 deletions packages/buildcop/src/buildcop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ buildcop.findTestResults = (xml: string): TestResults => {
for (const suite of testsuites) {
const testsuiteName = suite['_attributes'].name;
let testcases = suite['testcase'];
// If there were no tests in the package, continue.
if (testcases === undefined) {
continue;
}
// If there is only one test case, put it into an array to make it iterable.
if (!Array.isArray(testcases)) {
testcases = [testcases];
Expand Down
26 changes: 26 additions & 0 deletions packages/buildcop/test/buildcop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ describe('buildcop', () => {

requests.done();
});

it('opens an issue [Python]', async () => {
const input = fs.readFileSync(
resolve(fixturesPath, 'testdata', 'python_one_failed.xml'),
Expand Down Expand Up @@ -358,6 +359,31 @@ describe('buildcop', () => {
requests.done();
});

it('handles a testsuite with no test cases', async () => {
const input = fs.readFileSync(
resolve(fixturesPath, 'testdata', 'no_tests.xml'),
'utf8'
);
const payload = formatPayload({
repo: 'tbpg/golang-samples',
organization: { login: 'tbpg' },
repository: { name: 'golang-samples' },
buildID: '123',
buildURL: 'http://example.com',
xunitXML: input,
});

const requests = nock('https://api.github.com')
.get(
'/repos/tbpg/golang-samples/issues?per_page=32&labels=buildcop%3Aissue&state=all'
)
.reply(200, []);

await probot.receive({ name: 'pubsub.message', payload, id: 'abc123' });

requests.done();
});

it('reopens issue for failing test', async () => {
const input = fs.readFileSync(
resolve(fixturesPath, 'testdata', 'one_failed.xml'),
Expand Down
8 changes: 8 additions & 0 deletions packages/buildcop/test/fixtures/testdata/no_tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite tests="0" failures="0" time="266.555" name="github.com/tbpg/golang-samples/dataproc">
<properties>
<property name="go.version" value="go1.11.13"></property>
</properties>
</testsuite>
</testsuites>