Skip to content

Commit 8124792

Browse files
authored
chore(integration_runner): change package version extraction to ignore after spaces (#1033)
1 parent c8a539a commit 8124792

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

daemon/internal/newrelic/integration/php_packages.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,20 @@ func (pkgs *PhpPackagesCollection) OverrideVersionsFile() string {
290290
//
291291
// Returns:
292292
// - []PhpPackage with extracted package info, sorted by package name
293+
// - []string notes to be added to the test
293294
// - nil upon error processing JSON
294295
//
295296
// Notes: Currently only supports an application created with composer
296-
func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, error) {
297+
func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, []string, error) {
297298

298299
var err error
299300

300301
if nil == pkgs {
301-
return nil, fmt.Errorf("GatherInstallPackages(): pkgs is nil")
302+
return nil, nil, fmt.Errorf("GatherInstallPackages(): pkgs is nil")
302303
}
303304

304305
var supported []string
306+
var notes []string
305307

306308
// get list of packages we expected the agent to detect
307309
// this can be one of 3 scenarios:
@@ -331,12 +333,12 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
331333
if 0 < len(pkgs.config.supportedListFile) {
332334
supported, err = LoadSupportedPackagesList(pkgs.config.path, pkgs.config.supportedListFile)
333335
if nil != err {
334-
return nil, err
336+
return nil, nil, err
335337
}
336338
} else if 0 < len(pkgs.config.expectedPackages) {
337339
supported = pkgs.config.expectedPackages
338340
} else if !pkgs.config.expectAllDetected {
339-
return nil, fmt.Errorf("Error determining expected packages - supported_packages and expected_packages are both empty " +
341+
return nil, nil, fmt.Errorf("Error determining expected packages - supported_packages and expected_packages are both empty " +
340342
"and expect_all is false")
341343
}
342344

@@ -366,6 +368,16 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
366368
} else {
367369
version = v.Version
368370
}
371+
372+
// Remove any additional information extracted (hashes, etc).
373+
// The composer versioning standard is to not include any spaces
374+
// yet sometimes this standard is broken
375+
version_splits := strings.Split(version, " ")
376+
if len(version_splits) > 1 {
377+
notes = append(notes, fmt.Sprintf("Used shortened package version from composer. Originally was \"%s\"", version))
378+
version = version_splits[0]
379+
}
380+
369381
pkgs.packages = append(pkgs.packages, PhpPackage{v.Name, version})
370382
//fmt.Printf(" -> %s in supported!\n", v.Name)
371383
} else {
@@ -402,15 +414,15 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
402414
}
403415
}
404416
} else {
405-
return nil, fmt.Errorf("ERROR - unknown method '%s'\n", splitCmd[0])
417+
return nil, nil, fmt.Errorf("ERROR - unknown method '%s'\n", splitCmd[0])
406418
}
407419

408420
// sort by package name to aid comparision later
409421
sort.Slice(pkgs.packages, func(i, j int) bool {
410422
return pkgs.packages[i].Name < pkgs.packages[j].Name
411423
})
412424

413-
return pkgs.packages, nil
425+
return pkgs.packages, notes, nil
414426
}
415427

416428
// convert PhpPackage to collector JSON representation

daemon/internal/newrelic/integration/test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ func (t *Test) comparePhpPackages(harvest *newrelic.Harvest) {
641641

642642
if nil != t.phpPackagesConfig {
643643
var err error
644+
var notes []string
644645

645646
expectNullPkgs = "null" == string(t.phpPackagesConfig)
646647
if expectNullPkgs {
@@ -652,11 +653,16 @@ func (t *Test) comparePhpPackages(harvest *newrelic.Harvest) {
652653
return
653654
}
654655

655-
expectedPackages, err = expectedPkgsCollection.GatherInstalledPackages()
656+
expectedPackages, notes, err = expectedPkgsCollection.GatherInstalledPackages()
656657
if nil != err {
657658
t.Fatal(err)
658659
return
659660
}
661+
if nil != notes {
662+
for _, note := range notes {
663+
t.AddNote(note)
664+
}
665+
}
660666

661667
// Determine if we expect an exact match between expected and actual packages
662668
// when using the composer API in the agent to detect packages it is possible

0 commit comments

Comments
 (0)