diff --git a/.gitignore b/.gitignore index 6c13a672db..4cfc1dd431 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,6 @@ integration/migration_data/ man/*.xml man/*.1 man/*.1.gz + +# test outputs +/test-results.xml diff --git a/build.py b/build.py index 46933199d6..8501831f44 100755 --- a/build.py +++ b/build.py @@ -187,7 +187,7 @@ def go_get(branch, update=False, no_uncommitted=False): run("{}/bin/gdm restore -v".format(os.environ.get("GOPATH"))) return True -def run_tests(race, parallel, timeout, no_vet): +def run_tests(race, parallel, timeout, no_vet, junit=False): """Run the Go test suite on binary output. """ logging.info("Starting tests...") @@ -219,9 +219,33 @@ def run_tests(race, parallel, timeout, no_vet): if timeout is not None: test_command += " -timeout {}".format(timeout) test_command += " ./..." - logging.info("Running tests...") - output = run(test_command) - logging.debug("Test output:\n{}".format(output.encode('ascii', 'ignore'))) + if junit: + logging.info("Retrieving go-junit-report...") + run("go get github.com/jstemmer/go-junit-report") + + # Retrieve the output from this command. + logging.info("Running tests...") + logging.debug("{}".format(test_command)) + proc = subprocess.Popen(test_command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + output, unused_err = proc.communicate() + output = output.decode('utf-8').strip() + + # Process the output through go-junit-report. + with open('test-results.xml', 'w') as f: + logging.debug("{}".format("go-junit-report")) + junit_proc = subprocess.Popen(["go-junit-report"], stdin=subprocess.PIPE, stdout=f, stderr=subprocess.PIPE) + unused_output, err = junit_proc.communicate(output.encode('ascii', 'ignore')) + if junit_proc.returncode != 0: + logging.error("Command '{}' failed with error: {}".format("go-junit-report", err)) + sys.exit(1) + + if proc.returncode != 0: + logging.error("Command '{}' failed with error: {}".format(test_command, output.encode('ascii', 'ignore'))) + sys.exit(1) + else: + logging.info("Running tests...") + output = run(test_command) + logging.debug("Test output:\n{}".format(out.encode('ascii', 'ignore'))) return True ################ @@ -784,7 +808,7 @@ def main(args): return 1 if args.test: - if not run_tests(args.race, args.parallel, args.timeout, args.no_vet): + if not run_tests(args.race, args.parallel, args.timeout, args.no_vet, args.junit_report): return 1 platforms = [] @@ -968,6 +992,9 @@ if __name__ == '__main__': parser.add_argument('--test', action='store_true', help='Run tests (does not produce build output)') + parser.add_argument('--junit-report', + action='store_true', + help='Output tests in the JUnit XML format') parser.add_argument('--no-vet', action='store_true', help='Do not run "go vet" when running tests') diff --git a/circle-test.sh b/circle-test.sh index 6b34043b18..105b44185c 100755 --- a/circle-test.sh +++ b/circle-test.sh @@ -33,3 +33,7 @@ do ./test.sh $i fi done + +# Copy the JUnit test XML to the test reports folder. +mkdir -p $CIRCLE_TEST_REPORTS/reports +cp test-results.xml $CIRCLE_TEST_REPORTS/reports/test-results.xml diff --git a/test.sh b/test.sh index 15524a16f4..c6bbe8b7ee 100755 --- a/test.sh +++ b/test.sh @@ -74,8 +74,8 @@ function run_test_docker { -e "INFLUXDB_DATA_ENGINE=$INFLUXDB_DATA_ENGINE" \ -e "GORACE=$GORACE" \ -e "GO_CHECKOUT=$GO_CHECKOUT" \ - -e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" \ - -e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" \ + -e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" \ + -e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" \ "$imagename" \ "--parallel=$PARALLELISM" \ "--timeout=$TIMEOUT" \ @@ -131,18 +131,18 @@ fi case $ENVIRONMENT_INDEX in 0) # 64 bit tests - run_test_docker Dockerfile_build_ubuntu64 test_64bit --generate --test + run_test_docker Dockerfile_build_ubuntu64 test_64bit --generate --test --junit-report rc=$? ;; 1) # 64 bit race tests GORACE="halt_on_error=1" - run_test_docker Dockerfile_build_ubuntu64 test_64bit_race --generate --test --race + run_test_docker Dockerfile_build_ubuntu64 test_64bit_race --generate --test --junit-report --race rc=$? ;; 2) # 32 bit tests - run_test_docker Dockerfile_build_ubuntu32 test_32bit --generate --test --arch=i386 + run_test_docker Dockerfile_build_ubuntu32 test_32bit --generate --test --junit-report --arch=i386 rc=$? ;; "save")