Skip to content

Commit

Permalink
buildcop: handle a test suite with no tests (#266)
Browse files Browse the repository at this point in the history
This came up in a Go log and caused the log to fail to parse.

Co-authored-by: Benjamin E. Coe <[email protected]>
  • Loading branch information
tbpg and bcoe authored Feb 5, 2020
1 parent 26d54de commit 5b451b4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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>

0 comments on commit 5b451b4

Please sign in to comment.