-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from launchableinc/go-test
Add Go test plugin
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
import click | ||
from . import launchable | ||
|
||
@launchable.subset | ||
def subset(client): | ||
for case in sys.stdin: | ||
# Avoid last line such as `ok github.com/launchableinc/rocket-car-gotest 0.268s` | ||
if not ' ' in case: | ||
client.test_path([{'type': 'testcase', 'name': case.rstrip('\n')}]) | ||
|
||
client.formatter = lambda x: "^{}$".format(x[0]['name']) | ||
client.separator = '|' | ||
client.run() | ||
|
||
|
||
@click.argument('source_roots', required=True, nargs=-1) | ||
@launchable.record.tests | ||
def record_tests(client, source_roots): | ||
for root in source_roots: | ||
client.scan(root, "*.xml") | ||
client.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from unittest import TestCase, mock | ||
from nose.tools import eq_, ok_ | ||
from click.testing import CliRunner | ||
from test.support import captured_stdin | ||
|
||
import os | ||
import json | ||
from pathlib import Path | ||
import gzip | ||
|
||
from launchable.__main__ import main | ||
|
||
|
||
class GoTestTest(TestCase): | ||
launchable_token = 'v1:launchableinc/mothership:auth-token-sample' | ||
session = '/intake/organizations/launchableinc/workspaces/mothership/builds/123/test_sessions/16' | ||
test_files_dir = Path(__file__).parent.joinpath( | ||
'../data/go_test/').resolve() | ||
|
||
def setUp(self): | ||
self.maxDiff = None | ||
os.environ['LAUNCHABLE_TOKEN'] = self.launchable_token | ||
|
||
@mock.patch('requests.request') | ||
def test_subset(self, mock_post): | ||
runner = CliRunner() | ||
pipe = "TestExample1\nTestExample2\nTestExample3\nTestExample4\nok github.com/launchableinc/rocket-car-gotest 0.268s" | ||
result = runner.invoke(main, [ | ||
'subset', '--target', '10%', '--session', self.session, 'go_test'], input=pipe) | ||
|
||
self.assertEqual(result.exit_code, 0) | ||
|
||
for (args, kwargs) in mock_post.call_args_list: | ||
if kwargs['data']: | ||
data = kwargs['data'] | ||
|
||
result_file_path = self.test_files_dir.joinpath('subset_result.json') | ||
with result_file_path.open() as json_file: | ||
expected = json.load(json_file) | ||
self.assertDictEqual(json.loads(data.decode()), expected) | ||
|
||
@mock.patch('requests.request') | ||
def test_record_tests(self, mock_post): | ||
runner = CliRunner() | ||
result = runner.invoke(main, ['record', 'tests', '--session', | ||
self.session, 'go_test', str(self.test_files_dir) + "/"]) | ||
self.assertEqual(result.exit_code, 0) | ||
|
||
for (args, kwargs) in mock_post.call_args_list: | ||
if kwargs['data']: | ||
data = kwargs['data'] | ||
zipped_payload = b''.join(data) | ||
payload = json.loads(gzip.decompress(zipped_payload).decode()) | ||
|
||
result_file_path = self.test_files_dir.joinpath( | ||
'record_test_result.json') | ||
with result_file_path.open() as json_file: | ||
expected = json.load(json_file) | ||
|
||
# Normalize events order that depends on shell glob implementation | ||
payload['events'] = sorted( | ||
payload['events'], key=lambda c: c['testPath'][0]['name']) | ||
expected['events'] = sorted( | ||
expected['events'], key=lambda c: c['testPath'][0]['name']) | ||
|
||
# Remove timestamp because it depends on the machine clock | ||
for c in payload['events']: | ||
del c['created_at'] | ||
for c in expected['events']: | ||
del c['created_at'] | ||
|
||
self.assertDictEqual(payload, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"events": [ | ||
{"type": "case", "testPath": [{"type": "class", "name": "rocket-car-gotest"}, {"type": "testcase", "name": "TestExample1", "_lineno": null}], "duration": 0.0, "status": 1, "stdout": "", "stderr": "", "created_at": "2021-01-12T13:12:33.410391+00:00", "data": null}, | ||
{"type": "case", "testPath": [{"type": "class", "name": "rocket-car-gotest"}, {"type": "testcase", "name": "TestExample2", "_lineno": null}], "duration": 3.0, "status": 1, "stdout": "", "stderr": "", "created_at": "2021-01-12T13:12:33.410811+00:00", "data": null}, | ||
{"type": "case", "testPath": [{"type": "class", "name": "rocket-car-gotest"}, {"type": "testcase", "name": "TestExample3", "_lineno": null}], "duration": 0.0, "status": 1, "stdout": "", "stderr": "", "created_at": "2021-01-12T13:12:33.410874+00:00", "data": null}, | ||
{"type": "case", "testPath": [{"type": "class", "name": "rocket-car-gotest"}, {"type": "testcase", "name": "TestExample4", "_lineno": null}], "duration": 2.0, "status": 1, "stdout": "", "stderr": "", "created_at": "2021-01-12T13:12:33.410917+00:00", "data": null} | ||
]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<testsuites> | ||
<testsuite tests="4" failures="0" time="5.262" name="github.com/launchableinc/rocket-car-gotest"> | ||
<properties> | ||
<property name="go.version" value="go1.15.5"></property> | ||
</properties> | ||
<testcase classname="rocket-car-gotest" name="TestExample1" time="0.000"></testcase> | ||
<testcase classname="rocket-car-gotest" name="TestExample2" time="3.000"></testcase> | ||
<testcase classname="rocket-car-gotest" name="TestExample3" time="0.000"></testcase> | ||
<testcase classname="rocket-car-gotest" name="TestExample4" time="2.000"></testcase> | ||
</testsuite> | ||
</testsuites> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{"session": {"id": "16"}, | ||
"target": 0.1, | ||
"testPaths": [[{"name": "TestExample1", "type": "testcase"}], | ||
[{"name": "TestExample2", "type": "testcase"}], | ||
[{"name": "TestExample3", "type": "testcase"}], | ||
[{"name": "TestExample4", "type": "testcase"}]]} |