Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 07bc1cf

Browse files
committed
examples: shouldi: golangci-lint: Use cached_download_unpack_archive
Signed-off-by: John Andersen <[email protected]>
1 parent 87a2a62 commit 07bc1cf

File tree

3 files changed

+63
-6
lines changed

3 files changed

+63
-6
lines changed

examples/shouldi/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ wheelhouse/
1818
*.modeldir
1919
*.db
2020
htmlcov/
21+
tests/golangci-lint-download/
22+
tests/golang-download/
23+
tests/cri-resource-manager-download/

examples/shouldi/shouldi/golangci_lint.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
)
1212

1313

14+
class GoLangCILintError(Exception):
15+
"""
16+
Raised when golangci-lint fails
17+
"""
18+
19+
1420
@op(inputs={"pkg": package_src_dir}, outputs={"report": golangci_lint_output})
1521
async def run_golangci_lint(pkg: str) -> Dict[str, Any]:
1622
"""
@@ -21,13 +27,14 @@ async def run_golangci_lint(pkg: str) -> Dict[str, Any]:
2127
"run",
2228
"--out-format",
2329
"json",
24-
pkg,
30+
"./...",
31+
cwd=pkg,
2532
stdout=asyncio.subprocess.PIPE,
2633
stderr=asyncio.subprocess.PIPE,
2734
)
28-
stdout, _stderr = await proc.communicate()
35+
stdout, stderr = await proc.communicate()
2936
if len(stdout) == 0:
30-
raise Exception(_stderr)
37+
raise GoLangCILintError(stderr)
3138

3239
golangci_lint_op = stdout.decode()
3340
issues = json.loads(golangci_lint_op)
Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,58 @@
11
import os
2+
import copy
3+
import pathlib
24

5+
from dffml.util.os import prepend_to_path
6+
from dffml.util.net import cached_download_unpack_archive
37
from dffml.util.asynctestcase import AsyncTestCase
48

59
from shouldi.golangci_lint import run_golangci_lint
610

711

812
class TestRunGolangci_lintOp(AsyncTestCase):
9-
async def test_run(self):
10-
results = await run_golangci_lint(os.getcwd())
11-
self.assertEqual(type(results["issues"]), int)
13+
async def setUp(self):
14+
# We'll be adding golang specific environment variables, so let's be
15+
# sure to save and restore
16+
self.old_environ = copy.deepcopy(os.environ)
17+
18+
async def tearDown(self):
19+
# Remove keys that we're there before
20+
for k in os.environ:
21+
if not k in self.old_environ:
22+
del os.environ[k]
23+
# Reset the rest
24+
os.environ.update(self.old_environ)
25+
26+
@cached_download_unpack_archive(
27+
"https://dl.google.com/go/go1.14.linux-amd64.tar.gz",
28+
pathlib.Path(__file__).parent / "golang.tar.gz",
29+
pathlib.Path(__file__).parent / "golang-download",
30+
"5dcc7b2e9049d80ceee9d3a7a4b76b578f42de64eaadabd039f080a9f329f2ad448da710626ed8fb4b070b4555b50e6f",
31+
)
32+
@cached_download_unpack_archive(
33+
"https://github.com/golangci/golangci-lint/releases/download/v1.23.7/golangci-lint-1.23.7-linux-amd64.tar.gz",
34+
pathlib.Path(__file__).parent / "golangci-lint.tar.gz",
35+
pathlib.Path(__file__).parent / "golangci-lint-download",
36+
"088a65ae7aa45c8a5695f40cc90672d00dece7f08ce307567fddc8b2d03858cb5baf9d162193922d36c57c504cc52999",
37+
)
38+
@cached_download_unpack_archive(
39+
"https://github.com/intel/cri-resource-manager/archive/c5e6091c79830cf7d076bbdec59c4a253b369d6a.tar.gz",
40+
pathlib.Path(__file__).parent / "cri-resource-manager.tar.gz",
41+
pathlib.Path(__file__).parent / "cri-resource-manager-download",
42+
"bdcbc8dadf9c6ee2f7571d10cb54459fe54773036982ad7485f007606efae96d7aaec7da18e2fea806fb6f68eb1722a8",
43+
)
44+
async def test_run(self, golang, golangci_lint, cri_resource_manager):
45+
os.environ["GOROOT"] = str(golang / "go")
46+
os.environ["GOPATH"] = str(cri_resource_manager / ".gopath")
47+
os.environ["GOBIN"] = str(cri_resource_manager / ".gopath" / "bin")
48+
with prepend_to_path(
49+
golang / "go" / "bin",
50+
golangci_lint / "golangci-lint-1.23.7-linux-amd64",
51+
):
52+
results = await run_golangci_lint(
53+
str(
54+
cri_resource_manager
55+
/ "cri-resource-manager-c5e6091c79830cf7d076bbdec59c4a253b369d6a"
56+
)
57+
)
58+
self.assertEqual(results["issues"], 99)

0 commit comments

Comments
 (0)