|
1 | 1 | import os |
| 2 | +import copy |
| 3 | +import pathlib |
2 | 4 |
|
| 5 | +from dffml.util.os import prepend_to_path |
| 6 | +from dffml.util.net import cached_download_unpack_archive |
3 | 7 | from dffml.util.asynctestcase import AsyncTestCase |
4 | 8 |
|
5 | 9 | from shouldi.golangci_lint import run_golangci_lint |
6 | 10 |
|
7 | 11 |
|
8 | 12 | 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