• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pantsbuild / pants / 18822648545

26 Oct 2025 07:24PM UTC coverage: 79.831% (-0.4%) from 80.28%
18822648545

Pull #22809

github

web-flow
Merge 9401c4830 into 170094e99
Pull Request #22809: golang: fix Go SDK version check for coverage experiment

0 of 1 new or added line in 1 file covered. (0.0%)

439 existing lines in 25 files now uncovered.

77436 of 97000 relevant lines covered (79.83%)

3.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.18
/src/python/pants/backend/go/util_rules/third_party_pkg_test.py
1
# Copyright 2021 Pants project contributors (see CONTRIBUTORS.md).
2
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3

4
from __future__ import annotations
1✔
5

6
import os.path
1✔
7
import re
1✔
8
from textwrap import dedent
1✔
9

10
import pytest
1✔
11

12
from pants.backend.go import target_type_rules
1✔
13
from pants.backend.go.go_sources import load_go_binary
1✔
14
from pants.backend.go.target_types import GoModTarget
1✔
15
from pants.backend.go.util_rules import (
1✔
16
    assembly,
17
    build_pkg,
18
    first_party_pkg,
19
    go_mod,
20
    import_analysis,
21
    link,
22
    sdk,
23
    third_party_pkg,
24
)
25
from pants.backend.go.util_rules.build_opts import GoBuildOptions
1✔
26
from pants.backend.go.util_rules.third_party_pkg import (
1✔
27
    AllThirdPartyPackages,
28
    AllThirdPartyPackagesRequest,
29
    ModuleDescriptors,
30
    ModuleDescriptorsRequest,
31
    ThirdPartyPkgAnalysis,
32
    ThirdPartyPkgAnalysisRequest,
33
)
34
from pants.build_graph.address import Address
1✔
35
from pants.engine.fs import Digest, Snapshot
1✔
36
from pants.engine.internals.scheduler import ExecutionError
1✔
37
from pants.engine.process import ProcessExecutionFailure
1✔
38
from pants.engine.rules import QueryRule
1✔
39
from pants.testutil.rule_runner import RuleRunner, engine_error
1✔
40

41

42
@pytest.fixture
1✔
43
def rule_runner() -> RuleRunner:
1✔
44
    rule_runner = RuleRunner(
1✔
45
        rules=[
46
            *sdk.rules(),
47
            *third_party_pkg.rules(),
48
            *first_party_pkg.rules(),
49
            *load_go_binary.rules(),
50
            *build_pkg.rules(),
51
            *import_analysis.rules(),
52
            *link.rules(),
53
            *assembly.rules(),
54
            *target_type_rules.rules(),
55
            *go_mod.rules(),
56
            QueryRule(AllThirdPartyPackages, [AllThirdPartyPackagesRequest]),
57
            QueryRule(ThirdPartyPkgAnalysis, [ThirdPartyPkgAnalysisRequest]),
58
            QueryRule(ThirdPartyPkgAnalysis, [ThirdPartyPkgAnalysisRequest]),
59
            QueryRule(ModuleDescriptors, [ModuleDescriptorsRequest]),
60
        ],
61
        target_types=[GoModTarget],
62
    )
63
    rule_runner.set_options(["--golang-cgo-enabled"], env_inherit={"PATH"})
1✔
64
    return rule_runner
1✔
65

66

67
GO_MOD = dedent(
1✔
68
    """\
69
    module example.com/third-party-module
70
    go 1.16
71

72
    require github.com/google/uuid v1.3.0
73
    require (
74
        rsc.io/quote v1.5.2
75
        golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
76
        rsc.io/sampler v1.3.0 // indirect
77
    )
78
    """
79
)
80

81
GO_SUM = dedent(
1✔
82
    """\
83
    github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
84
    github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
85
    golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:qgOY6WgZOaTkIIMiVjBQcw93ERBE4m30iBm00nkL0i8=
86
    golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
87
    rsc.io/quote v1.5.2 h1:w5fcysjrx7yqtD/aO+QwRjYZOKnaM9Uh2b40tElTs3Y=
88
    rsc.io/quote v1.5.2/go.mod h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe+TKr0=
89
    rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
90
    rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
91
    """
92
)
93

94

95
def set_up_go_mod(rule_runner: RuleRunner, go_mod: str, go_sum: str) -> Digest:
1✔
96
    return rule_runner.make_snapshot({"go.mod": go_mod, "go.sum": go_sum}).digest
1✔
97

98

99
def test_download_and_analyze_all_packages(rule_runner: RuleRunner) -> None:
1✔
100
    input_digest = rule_runner.make_snapshot({"go.mod": GO_MOD, "go.sum": GO_SUM}).digest
1✔
101
    all_packages = rule_runner.request(
1✔
102
        AllThirdPartyPackages,
103
        [
104
            AllThirdPartyPackagesRequest(
105
                Address("fake_addr_for_test", target_name="mod"),
106
                input_digest,
107
                "go.mod",
108
                build_opts=GoBuildOptions(),
109
            )
110
        ],
111
    )
UNCOV
112
    assert set(all_packages.import_paths_to_pkg_info.keys()) == {
×
113
        "golang.org/x/text/encoding/japanese",
114
        "golang.org/x/text/message/catalog",
115
        "golang.org/x/text/internal/testtext",
116
        "golang.org/x/text/encoding/ianaindex",
117
        "golang.org/x/text/cmd/gotext",
118
        "golang.org/x/text/width",
119
        "golang.org/x/text/internal/format",
120
        "rsc.io/sampler",
121
        "golang.org/x/text/internal/tag",
122
        "golang.org/x/text/unicode/norm",
123
        "golang.org/x/text/number",
124
        "golang.org/x/text/transform",
125
        "golang.org/x/text/internal",
126
        "golang.org/x/text/internal/utf8internal",
127
        "golang.org/x/text/language/display",
128
        "golang.org/x/text/internal/stringset",
129
        "golang.org/x/text/encoding/korean",
130
        "golang.org/x/text/internal/triegen",
131
        "golang.org/x/text/secure/bidirule",
132
        "golang.org/x/text/secure/precis",
133
        "golang.org/x/text/language",
134
        "golang.org/x/text/encoding/unicode/utf32",
135
        "golang.org/x/text/internal/colltab",
136
        "golang.org/x/text/unicode/rangetable",
137
        "golang.org/x/text/encoding/htmlindex",
138
        "golang.org/x/text/internal/export/idna",
139
        "golang.org/x/text/encoding/charmap",
140
        "golang.org/x/text/unicode/cldr",
141
        "golang.org/x/text/secure",
142
        "golang.org/x/text/internal/ucd",
143
        "golang.org/x/text/feature/plural",
144
        "golang.org/x/text/unicode",
145
        "golang.org/x/text/encoding/traditionalchinese",
146
        "golang.org/x/text/runes",
147
        "golang.org/x/text/internal/catmsg",
148
        "rsc.io/quote/buggy",
149
        "golang.org/x/text/encoding/simplifiedchinese",
150
        "golang.org/x/text/cases",
151
        "golang.org/x/text/encoding/internal",
152
        "github.com/google/uuid",
153
        "golang.org/x/text/encoding/internal/enctest",
154
        "golang.org/x/text/collate/build",
155
        "golang.org/x/text",
156
        "golang.org/x/text/unicode/bidi",
157
        "golang.org/x/text/search",
158
        "golang.org/x/text/unicode/runenames",
159
        "golang.org/x/text/message",
160
        "golang.org/x/text/encoding",
161
        "golang.org/x/text/encoding/unicode",
162
        "rsc.io/quote",
163
        "golang.org/x/text/currency",
164
        "golang.org/x/text/internal/number",
165
        "golang.org/x/text/collate/tools/colcmp",
166
        "golang.org/x/text/encoding/internal/identifier",
167
        "golang.org/x/text/collate",
168
        "golang.org/x/text/internal/gen",
169
    }
170

UNCOV
171
    def assert_pkg_info(
×
172
        import_path: str,
173
        dir_path: str,
174
        imports: tuple[str, ...],
175
        go_files: tuple[str, ...],
176
        extra_files: tuple[str, ...],
177
        minimum_go_version: str | None,
178
    ) -> None:
UNCOV
179
        assert import_path in all_packages.import_paths_to_pkg_info
×
UNCOV
180
        pkg_info = all_packages.import_paths_to_pkg_info[import_path]
×
UNCOV
181
        assert pkg_info.import_path == import_path
×
UNCOV
182
        assert pkg_info.dir_path == dir_path
×
UNCOV
183
        assert pkg_info.imports == imports
×
UNCOV
184
        assert pkg_info.go_files == go_files
×
UNCOV
185
        assert not pkg_info.s_files
×
UNCOV
186
        snapshot = rule_runner.request(Snapshot, [pkg_info.digest])
×
UNCOV
187
        expected_files = {
×
188
            os.path.join(dir_path, file_name) for file_name in (*go_files, *extra_files)
189
        }
UNCOV
190
        assert expected_files.issubset(snapshot.files)
×
UNCOV
191
        assert pkg_info.minimum_go_version == minimum_go_version
×
192

UNCOV
193
    assert_pkg_info(
×
194
        import_path="github.com/google/uuid",
195
        dir_path="gopath/pkg/mod/github.com/google/uuid@v1.3.0",
196
        imports=(
197
            "bytes",
198
            "crypto/md5",
199
            "crypto/rand",
200
            "crypto/sha1",
201
            "database/sql/driver",
202
            "encoding/binary",
203
            "encoding/hex",
204
            "encoding/json",
205
            "errors",
206
            "fmt",
207
            "hash",
208
            "io",
209
            "net",
210
            "os",
211
            "strings",
212
            "sync",
213
            "time",
214
        ),
215
        go_files=(
216
            "dce.go",
217
            "doc.go",
218
            "hash.go",
219
            "marshal.go",
220
            "node.go",
221
            "node_net.go",
222
            "null.go",
223
            "sql.go",
224
            "time.go",
225
            "util.go",
226
            "uuid.go",
227
            "version1.go",
228
            "version4.go",
229
        ),
230
        extra_files=(
231
            ".travis.yml",
232
            "CONTRIBUTING.md",
233
            "CONTRIBUTORS",
234
            "LICENSE",
235
            "README.md",
236
            "go.mod",
237
            "json_test.go",
238
            "node_js.go",
239
            "null_test.go",
240
            "seq_test.go",
241
            "sql_test.go",
242
            "uuid_test.go",
243
        ),
244
        minimum_go_version=None,
245
    )
UNCOV
246
    assert_pkg_info(
×
247
        import_path="golang.org/x/text/unicode/bidi",
248
        dir_path="gopath/pkg/mod/golang.org/x/text@v0.0.0-20170915032832-14c0d48ead0c/unicode/bidi",
249
        imports=("container/list", "fmt", "log", "sort", "unicode/utf8"),
250
        go_files=("bidi.go", "bracket.go", "core.go", "prop.go", "tables.go", "trieval.go"),
251
        extra_files=(
252
            "core_test.go",
253
            "gen.go",
254
            "gen_ranges.go",
255
            "gen_trieval.go",
256
            "ranges_test.go",
257
            "tables_test.go",
258
        ),
259
        minimum_go_version=None,
260
    )
261

262

263
def test_invalid_go_sum(rule_runner: RuleRunner) -> None:
1✔
264
    digest = set_up_go_mod(
1✔
265
        rule_runner,
266
        dedent(
267
            """\
268
            module example.com/third-party-module
269
            go 1.17
270
            require github.com/google/uuid v1.3.0
271
            """
272
        ),
273
        dedent(
274
            """\
275
            github.com/google/uuid v1.3.0 h1:00000gmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
276
            github.com/google/uuid v1.3.0/go.mod h1:00000e4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
277
            """
278
        ),
279
    )
280
    with engine_error(ProcessExecutionFailure, contains="SECURITY ERROR"):
1✔
281
        rule_runner.request(
1✔
282
            AllThirdPartyPackages,
283
            [
284
                AllThirdPartyPackagesRequest(
285
                    Address("fake_addr_for_test", target_name="mod"),
286
                    digest,
287
                    "go.mod",
288
                    build_opts=GoBuildOptions(),
289
                )
290
            ],
291
        )
292

293

294
@pytest.mark.skip(reason="TODO(#15824)")
1✔
295
@pytest.mark.no_error_if_skipped
1✔
296
def test_missing_go_sum(rule_runner: RuleRunner) -> None:
1✔
297
    digest = set_up_go_mod(
×
298
        rule_runner,
299
        dedent(
300
            """\
301
            module example.com/third-party-module
302
            go 1.17
303
            require github.com/google/uuid v1.3.0
304
            """
305
        ),
306
        # `go.sum` is for a different module.
307
        dedent(
308
            """\
309
            cloud.google.com/go v0.26.0 h1:e0WKqKTd5BnrG8aKH3J3h+QvEIQtSUcf2n5UZ5ZgLtQ=
310
            cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
311
            """
312
        ),
313
    )
314
    with engine_error(contains="github.com/google/uuid@v1.3.0: missing go.sum entry"):
×
315
        rule_runner.request(
×
316
            AllThirdPartyPackages,
317
            [
318
                AllThirdPartyPackagesRequest(
319
                    Address("fake_addr_for_test", target_name="mod"),
320
                    digest,
321
                    "go.mod",
322
                    build_opts=GoBuildOptions(),
323
                )
324
            ],
325
        )
326

327

328
@pytest.mark.skip(reason="TODO(#15824)")
1✔
329
@pytest.mark.no_error_if_skipped
1✔
330
def test_stale_go_mod(rule_runner: RuleRunner) -> None:
1✔
331
    digest = set_up_go_mod(
×
332
        rule_runner,
333
        # Go 1.17+ expects indirect dependencies to be included in the `go.mod`, i.e.
334
        # `golang.org/x/xerrors `.
335
        dedent(
336
            """\
337
            module example.com/third-party-module
338
            go 1.17
339
            require github.com/google/go-cmp v0.5.6
340
            """
341
        ),
342
        dedent(
343
            """\
344
            github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
345
            github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
346
            golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
347
            golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
348
            """
349
        ),
350
    )
351
    with engine_error(ProcessExecutionFailure, contains="updates to go.mod needed"):
×
352
        rule_runner.request(
×
353
            AllThirdPartyPackages,
354
            [
355
                AllThirdPartyPackagesRequest(
356
                    Address("fake_addr_for_test", target_name="mod"),
357
                    digest,
358
                    "go.mod",
359
                    build_opts=GoBuildOptions(),
360
                )
361
            ],
362
        )
363

364

365
def test_pkg_missing(rule_runner: RuleRunner) -> None:
1✔
366
    digest = set_up_go_mod(rule_runner, GO_MOD, GO_SUM)
1✔
367
    with engine_error(
1✔
368
        AssertionError, contains="The package `another_project.org/foo` was not downloaded"
369
    ):
370
        rule_runner.request(
1✔
371
            ThirdPartyPkgAnalysis,
372
            [
373
                ThirdPartyPkgAnalysisRequest(
374
                    "another_project.org/foo",
375
                    Address("fake_addr_for_test", target_name="mod"),
376
                    digest,
377
                    "go.mod",
378
                    build_opts=GoBuildOptions(),
379
                )
380
            ],
381
        )
382

383

384
def test_module_with_no_packages(rule_runner) -> None:
1✔
385
    digest = set_up_go_mod(
1✔
386
        rule_runner,
387
        dedent(
388
            """\
389
            module example.com/third-party-module
390
            go 1.17
391
            require github.com/Azure/go-autorest v13.3.2+incompatible
392
            """
393
        ),
394
        dedent(
395
            """\
396
            github.com/Azure/go-autorest v13.3.2+incompatible h1:VxzPyuhtnlBOzc4IWCZHqpyH2d+QMLQEuy3wREyY4oc=
397
            github.com/Azure/go-autorest v13.3.2+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
398
            """
399
        ),
400
    )
401
    all_packages = rule_runner.request(
1✔
402
        AllThirdPartyPackages,
403
        [
404
            AllThirdPartyPackagesRequest(
405
                Address("fake_addr_for_test", target_name="mod"),
406
                digest,
407
                "go.mod",
408
                build_opts=GoBuildOptions(),
409
            )
410
        ],
411
    )
UNCOV
412
    assert not all_packages.import_paths_to_pkg_info
×
413

414

415
def test_determine_pkg_info_module_with_replace_directive(rule_runner: RuleRunner) -> None:
1✔
416
    """Regression test for https://github.com/pantsbuild/pants/issues/13138."""
417
    digest = set_up_go_mod(
1✔
418
        rule_runner,
419
        dedent(
420
            """\
421
            module example.com/third-party-module
422
            go 1.16
423
            require github.com/hashicorp/consul/api v1.3.0
424
            """
425
        ),
426
        dedent(
427
            """\
428
            github.com/Azure/go-autorest v13.3.2+incompatible h1:VxzPyuhtnlBOzc4IWCZHqpyH2d+QMLQEuy3wREyY4oc=
429
            github.com/Azure/go-autorest v13.3.2+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
430
            github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
431
            github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
432
            github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
433
            github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
434
            github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
435
            github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
436
            github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
437
            github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
438
            github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
439
            github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
440
            github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
441
            github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
442
            github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
443
            github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw=
444
            github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
445
            github.com/hashicorp/consul/api v1.3.0 h1:HXNYlRkkM/t+Y/Yhxtwcy02dlYwIaoxzvxPnS+cqy78=
446
            github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
447
            github.com/hashicorp/consul/sdk v0.3.0 h1:UOxjlb4xVNF93jak1mzzoBatyFju9nrkxpVwIp/QqxQ=
448
            github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
449
            github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
450
            github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
451
            github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
452
            github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
453
            github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
454
            github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
455
            github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4=
456
            github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
457
            github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
458
            github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
459
            github.com/hashicorp/go-rootcerts v1.0.0 h1:Rqb66Oo1X/eSV1x66xbDccZjhJigjg0+e82kpwzSwCI=
460
            github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
461
            github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs=
462
            github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
463
            github.com/hashicorp/go-syslog v1.0.0 h1:KaodqZuhUoZereWVIYmpUgZysurB1kBLX2j0MwMrUAE=
464
            github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
465
            github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
466
            github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
467
            github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
468
            github.com/hashicorp/go.net v0.0.1 h1:sNCoNyDEvN1xa+X0baata4RdcpKwcMS6DH+xwfqPgjw=
469
            github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
470
            github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
471
            github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
472
            github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
473
            github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
474
            github.com/hashicorp/mdns v1.0.0 h1:WhIgCr5a7AaVH6jPUwjtRuuE7/RDufnUvzIr48smyxs=
475
            github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
476
            github.com/hashicorp/memberlist v0.1.3 h1:EmmoJme1matNzb+hMpDuR/0sbJSUisxyqBGG676r31M=
477
            github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
478
            github.com/hashicorp/serf v0.8.2 h1:YZ7UKsJv+hKjqGVUUbtE3HNj79Eln2oQ75tniF6iPt0=
479
            github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
480
            github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
481
            github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
482
            github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
483
            github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
484
            github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA=
485
            github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
486
            github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y=
487
            github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
488
            github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
489
            github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
490
            github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0=
491
            github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
492
            github.com/mitchellh/gox v0.4.0 h1:lfGJxY7ToLJQjHHwi0EX6uYBdK78egf954SQl13PQJc=
493
            github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
494
            github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
495
            github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
496
            github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
497
            github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
498
            github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
499
            github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c h1:Lgl0gzECD8GnQ5QCWA8o6BtfL6mDH5rQgM4/fX3avOs=
500
            github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
501
            github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
502
            github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
503
            github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
504
            github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
505
            github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w=
506
            github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
507
            github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f h1:UFr9zpz4xgTnIE5yIMtWAMngCdZ9p/+q6lTbgelo80M=
508
            github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
509
            github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
510
            github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
511
            github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
512
            github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
513
            github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
514
            github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
515
            github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
516
            golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3 h1:KYQXGkl6vs02hK7pK4eIbw0NpNPedieTSTEiJ//bwGs=
517
            golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
518
            golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
519
            golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0=
520
            golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
521
            golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
522
            golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
523
            golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
524
            golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5 h1:x6r4Jo0KNzOOzYd8lbcRsqjuqEASK6ob3auvWYM4/8U=
525
            golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
526
            """
527
        ),
528
    )
529
    pkg_info = rule_runner.request(
1✔
530
        ThirdPartyPkgAnalysis,
531
        [
532
            ThirdPartyPkgAnalysisRequest(
533
                "github.com/hashicorp/consul/api",
534
                Address("fake_addr_for_test", target_name="mod"),
535
                digest,
536
                "go.mod",
537
                build_opts=GoBuildOptions(),
538
            )
539
        ],
540
    )
UNCOV
541
    assert pkg_info.dir_path == "gopath/pkg/mod/github.com/hashicorp/consul/api@v1.3.0"
×
UNCOV
542
    assert "raw.go" in pkg_info.go_files
×
543

544

545
def test_ambiguous_package(rule_runner: RuleRunner) -> None:
1✔
546
    digest = set_up_go_mod(
1✔
547
        rule_runner,
548
        dedent(
549
            """\
550
            module example.com/third-party-module
551
            go 1.16
552
            require github.com/ugorji/go v1.1.4
553
            require github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8
554
            """
555
        ),
556
        dedent(
557
            """\
558
            github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
559
            github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
560
            github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 h1:3SVOIvH7Ae1KRYyQWRjXWJEA9sS/c/pjvH++55Gr648=
561
            github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
562
            """
563
        ),
564
    )
565
    pkg_info = rule_runner.request(
1✔
566
        ThirdPartyPkgAnalysis,
567
        [
568
            ThirdPartyPkgAnalysisRequest(
569
                "github.com/ugorji/go/codec",
570
                Address("fake_addr_for_test", target_name="mod"),
571
                digest,
572
                "go.mod",
573
                build_opts=GoBuildOptions(),
574
            )
575
        ],
576
    )
UNCOV
577
    assert pkg_info.error is None
×
UNCOV
578
    assert (
×
579
        pkg_info.dir_path
580
        == "gopath/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8"
581
    )
UNCOV
582
    assert "encode.go" in pkg_info.go_files
×
583

584

585
def test_go_sum_with_missing_entries_triggers_error(rule_runner: RuleRunner) -> None:
1✔
586
    digest = set_up_go_mod(
1✔
587
        rule_runner,
588
        dedent(
589
            """\
590
            module example.com/third-party-module
591
            go 1.16
592
            require github.com/google/uuid v1.3.0
593
            """
594
        ),
595
        "",
596
    )
597
    msg = (
1✔
598
        "For `go_mod` target `fake_addr_for_test:mod`, the go.sum file is incomplete because "
599
        "it was updated while processing third-party dependency `github.com/google/uuid`."
600
    )
601
    with pytest.raises(ExecutionError, match=re.escape(msg)):
1✔
602
        _ = rule_runner.request(
1✔
603
            ThirdPartyPkgAnalysis,
604
            [
605
                ThirdPartyPkgAnalysisRequest(
606
                    "github.com/ugorji/go/codec",
607
                    Address("fake_addr_for_test", target_name="mod"),
608
                    digest,
609
                    "go.mod",
610
                    build_opts=GoBuildOptions(),
611
                )
612
            ],
613
        )
614

615

616
def test_local_path_replace_statement_is_not_considered_third_party(
1✔
617
    rule_runner: RuleRunner,
618
) -> None:
619
    """Regression test for https://github.com/pantsbuild/pants/issues/14996."""
620
    digest = set_up_go_mod(
1✔
621
        rule_runner,
622
        dedent(
623
            """\
624
            module example.com/first-party/module-a
625
            go 1.16
626
            require example.com/first-party/module-b v1.3.0
627
            replace example.com/first-party/module-b => ../module-b
628
            """
629
        ),
630
        dedent(
631
            """\
632
            """
633
        ),
634
    )
635
    module_analysis = rule_runner.request(
1✔
636
        ModuleDescriptors,
637
        [ModuleDescriptorsRequest(digest=digest, path=".")],
638
    )
639
    # The module replaced to a local path should not be considered for third party analysis.
UNCOV
640
    assert len(module_analysis.modules) == 0
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc