■ ■ ■ ■ ■ ■ ■
syft/pkg/cataloger/golang/parse_go_binary_test.go
| skipped 346 lines |
347 | 347 | | }, |
348 | 348 | | }, |
349 | 349 | | { |
350 | | - | name: "parse main mod and replace devel version with one from ldflags", |
| 350 | + | name: "parse main mod and replace devel version with one from ldflags with vcs. build settings", |
351 | 351 | | arch: archDetails, |
352 | 352 | | mod: &debug.BuildInfo{ |
353 | 353 | | GoVersion: goCompiledVersion, |
| skipped 33 lines |
387 | 387 | | "vcs.revision": "41bc6bb410352845f22766e27dd48ba93aa825a4", |
388 | 388 | | "vcs.time": "2022-10-14T19:54:57Z", |
389 | 389 | | "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`, |
| 390 | + | }, |
| 391 | + | MainModule: "github.com/anchore/syft", |
| 392 | + | }, |
| 393 | + | }, |
| 394 | + | }, |
| 395 | + | }, |
| 396 | + | { |
| 397 | + | name: "parse main mod and replace devel version with one from ldflags without any vcs. build settings", |
| 398 | + | arch: archDetails, |
| 399 | + | mod: &debug.BuildInfo{ |
| 400 | + | GoVersion: goCompiledVersion, |
| 401 | + | Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, |
| 402 | + | Settings: []debug.BuildSetting{ |
| 403 | + | {Key: "GOARCH", Value: archDetails}, |
| 404 | + | {Key: "GOOS", Value: "darwin"}, |
| 405 | + | {Key: "GOAMD64", Value: "v1"}, |
| 406 | + | {Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`}, |
| 407 | + | }, |
| 408 | + | }, |
| 409 | + | expected: []pkg.Package{ |
| 410 | + | { |
| 411 | + | Name: "github.com/anchore/syft", |
| 412 | + | Language: pkg.Go, |
| 413 | + | Type: pkg.GoModulePkg, |
| 414 | + | Version: "v0.79.0", |
| 415 | + | PURL: "pkg:golang/github.com/anchore/[email protected]", |
| 416 | + | Locations: file.NewLocationSet( |
| 417 | + | file.NewLocationFromCoordinates( |
| 418 | + | file.Coordinates{ |
| 419 | + | RealPath: "/a-path", |
| 420 | + | FileSystemID: "layer-id", |
| 421 | + | }, |
| 422 | + | ).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), |
| 423 | + | ), |
| 424 | + | MetadataType: pkg.GolangBinMetadataType, |
| 425 | + | Metadata: pkg.GolangBinMetadata{ |
| 426 | + | GoCompiledVersion: goCompiledVersion, |
| 427 | + | Architecture: archDetails, |
| 428 | + | BuildSettings: map[string]string{ |
| 429 | + | "GOARCH": archDetails, |
| 430 | + | "GOOS": "darwin", |
| 431 | + | "GOAMD64": "v1", |
| 432 | + | "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X github.com/anchore/syft/internal/version.version=0.79.0`, |
| 433 | + | }, |
| 434 | + | MainModule: "github.com/anchore/syft", |
| 435 | + | }, |
| 436 | + | }, |
| 437 | + | }, |
| 438 | + | }, |
| 439 | + | { |
| 440 | + | name: "parse main mod and replace devel version with one from ldflags main.version without any vcs. build settings", |
| 441 | + | arch: archDetails, |
| 442 | + | mod: &debug.BuildInfo{ |
| 443 | + | GoVersion: goCompiledVersion, |
| 444 | + | Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, |
| 445 | + | Settings: []debug.BuildSetting{ |
| 446 | + | {Key: "GOARCH", Value: archDetails}, |
| 447 | + | {Key: "GOOS", Value: "darwin"}, |
| 448 | + | {Key: "GOAMD64", Value: "v1"}, |
| 449 | + | {Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`}, |
| 450 | + | }, |
| 451 | + | }, |
| 452 | + | expected: []pkg.Package{ |
| 453 | + | { |
| 454 | + | Name: "github.com/anchore/syft", |
| 455 | + | Language: pkg.Go, |
| 456 | + | Type: pkg.GoModulePkg, |
| 457 | + | Version: "v0.79.0", |
| 458 | + | PURL: "pkg:golang/github.com/anchore/[email protected]", |
| 459 | + | Locations: file.NewLocationSet( |
| 460 | + | file.NewLocationFromCoordinates( |
| 461 | + | file.Coordinates{ |
| 462 | + | RealPath: "/a-path", |
| 463 | + | FileSystemID: "layer-id", |
| 464 | + | }, |
| 465 | + | ).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), |
| 466 | + | ), |
| 467 | + | MetadataType: pkg.GolangBinMetadataType, |
| 468 | + | Metadata: pkg.GolangBinMetadata{ |
| 469 | + | GoCompiledVersion: goCompiledVersion, |
| 470 | + | Architecture: archDetails, |
| 471 | + | BuildSettings: map[string]string{ |
| 472 | + | "GOARCH": archDetails, |
| 473 | + | "GOOS": "darwin", |
| 474 | + | "GOAMD64": "v1", |
| 475 | + | "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.version=0.79.0`, |
| 476 | + | }, |
| 477 | + | MainModule: "github.com/anchore/syft", |
| 478 | + | }, |
| 479 | + | }, |
| 480 | + | }, |
| 481 | + | }, |
| 482 | + | { |
| 483 | + | name: "parse main mod and replace devel version with one from ldflags main.Version without any vcs. build settings", |
| 484 | + | arch: archDetails, |
| 485 | + | mod: &debug.BuildInfo{ |
| 486 | + | GoVersion: goCompiledVersion, |
| 487 | + | Main: debug.Module{Path: "github.com/anchore/syft", Version: "(devel)"}, |
| 488 | + | Settings: []debug.BuildSetting{ |
| 489 | + | {Key: "GOARCH", Value: archDetails}, |
| 490 | + | {Key: "GOOS", Value: "darwin"}, |
| 491 | + | {Key: "GOAMD64", Value: "v1"}, |
| 492 | + | {Key: "-ldflags", Value: `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`}, |
| 493 | + | }, |
| 494 | + | }, |
| 495 | + | expected: []pkg.Package{ |
| 496 | + | { |
| 497 | + | Name: "github.com/anchore/syft", |
| 498 | + | Language: pkg.Go, |
| 499 | + | Type: pkg.GoModulePkg, |
| 500 | + | Version: "v0.79.0", |
| 501 | + | PURL: "pkg:golang/github.com/anchore/[email protected]", |
| 502 | + | Locations: file.NewLocationSet( |
| 503 | + | file.NewLocationFromCoordinates( |
| 504 | + | file.Coordinates{ |
| 505 | + | RealPath: "/a-path", |
| 506 | + | FileSystemID: "layer-id", |
| 507 | + | }, |
| 508 | + | ).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), |
| 509 | + | ), |
| 510 | + | MetadataType: pkg.GolangBinMetadataType, |
| 511 | + | Metadata: pkg.GolangBinMetadata{ |
| 512 | + | GoCompiledVersion: goCompiledVersion, |
| 513 | + | Architecture: archDetails, |
| 514 | + | BuildSettings: map[string]string{ |
| 515 | + | "GOARCH": archDetails, |
| 516 | + | "GOOS": "darwin", |
| 517 | + | "GOAMD64": "v1", |
| 518 | + | "-ldflags": `build -ldflags="-w -s -extldflags '-static' -X main.Version=0.79.0`, |
390 | 519 | | }, |
391 | 520 | | MainModule: "github.com/anchore/syft", |
392 | 521 | | }, |
| skipped 376 lines |