Skip to content

Commit

Permalink
fix(tests): Reverts use of slices.Contains (#831)
Browse files Browse the repository at this point in the history
To retain ability to build on older golang compilers.
  • Loading branch information
mfulb authored and hahuja2 committed Feb 8, 2024
1 parent cce89bf commit 2cd020e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/newrelic/integration/php_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"sort"
"strings"
)
Expand Down Expand Up @@ -282,7 +281,7 @@ func (pkgs *PhpPackagesCollection) GatherInstalledPackages() ([]PhpPackage, erro
json.Unmarshal([]byte(out), &detected)
for _, v := range detected.Installed {
//fmt.Printf("composer detected %s %s\n", v.Name, v.Version)
if slices.Contains(supported, v.Name) {
if StringSliceContains(supported, v.Name) {
var version string

// remove any 'v' from front of version string
Expand Down
13 changes: 13 additions & 0 deletions src/newrelic/integration/string_slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package integration

// check if string is contained in an array of strings
// for legacy Go as it would be preferable to use the slices
func StringSliceContains(slice []string, text string) bool {
for _, val := range slice {
if text == val {
return true
}
}

return false
}
3 changes: 1 addition & 2 deletions src/newrelic/integration/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"os"
"path/filepath"
"regexp"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -572,7 +571,7 @@ func (t *Test) comparePhpPackages(harvest *newrelic.Harvest) {
if expectedPackages[i].Name == actualPackages[i].Name {
testPackageNameOnly := false
if nil != expectedPkgsCollection.config.packageNameOnly {
testPackageNameOnly = slices.Contains(expectedPkgsCollection.config.packageNameOnly, actualPackages[i].Name)
testPackageNameOnly = StringSliceContains(expectedPkgsCollection.config.packageNameOnly, actualPackages[i].Name)
if testPackageNameOnly {
t.AddNote(fmt.Sprintf("Tested package name only for packages: %+v", expectedPkgsCollection.config.packageNameOnly))
}
Expand Down

0 comments on commit 2cd020e

Please sign in to comment.