Skip to content

Commit

Permalink
[NR-172032]: Replace Windows Powershells for bash scripts in integrat…
Browse files Browse the repository at this point in the history
…ion tests (#1747)

* fix: use bash for windows integration tests

* fix: remove script extension based on os

* feat: replace backslashes

* chore: bump golangci version

* fix: remove Powershell integration tests

* chore: bump go-agent dependency
  • Loading branch information
rogercoll authored Oct 23, 2023
1 parent 46ecab6 commit 23316d0
Show file tree
Hide file tree
Showing 16 changed files with 17 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Makefile.Common
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ALL_SRC := $(shell find . -name '*.go' -not -path '*/vendor/*' -type f)

GOTOOLS ?=
GOTOOLS += " github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.1"
GOTOOLS += " github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.0"
GOTOOLS += " go.elastic.co/[email protected]"
GOTOOLS += " github.com/google/addlicense@04bfe4ee9ca5764577b029acc6a1957fd1997153"

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/kardianos/service v1.2.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b
github.com/newrelic/go-agent/v3 v3.26.0
github.com/newrelic/go-agent/v3 v3.27.0
github.com/newrelic/infra-identity-client-go v1.0.2
github.com/newrelic/newrelic-telemetry-sdk-go v0.8.1
github.com/opencontainers/go-digest v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0=
github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/newrelic/go-agent/v3 v3.26.0 h1:xJkqiQgLtC3ys5zoBxD91ITm7sVHZNEF+7/mqmFjnl0=
github.com/newrelic/go-agent/v3 v3.26.0/go.mod h1:sE2WdlLF3B/xI5HUuIHTa7Aht1gpcIY65pzaUoN1pJs=
github.com/newrelic/go-agent/v3 v3.27.0 h1:Z3XB49d8FKjRcGzCyViCO9itBxiLPSpwjY1HlMvgamQ=
github.com/newrelic/go-agent/v3 v3.27.0/go.mod h1:TUzePinDc0BMH4Sui66rl4SBe6yOKJ5X/bRJekwuAtM=
github.com/newrelic/infra-identity-client-go v1.0.2 h1:RxkHAFOqeiBkW/fXvzkp3uORPl6crFt4I/zf4dCUFKM=
github.com/newrelic/infra-identity-client-go v1.0.2/go.mod h1:lrG2ompP2Mr6D8WW615/h2AYNs9B9pw2zLuc38LNb4E=
github.com/newrelic/newrelic-telemetry-sdk-go v0.8.1 h1:6OX5VXMuj2salqNBc41eXKz6K+nV6OB/hhlGnAKCbwU=
Expand Down
11 changes: 0 additions & 11 deletions internal/integrations/v4/fixtures/basic cmd.ps1

This file was deleted.

11 changes: 0 additions & 11 deletions internal/integrations/v4/fixtures/basic_cmd.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions internal/integrations/v4/fixtures/blocked_cmd.ps1

This file was deleted.

4 changes: 0 additions & 4 deletions internal/integrations/v4/fixtures/error_cmd.ps1

This file was deleted.

8 changes: 0 additions & 8 deletions internal/integrations/v4/fixtures/filecontents_witharg.ps1

This file was deleted.

4 changes: 0 additions & 4 deletions internal/integrations/v4/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package fixtures
import (
"github.com/newrelic/infrastructure-agent/internal/integrations/v4/testhelp"
"path"
"runtime"
)

var (
Expand All @@ -16,8 +15,5 @@ var (
)

func getExtension() string {
if runtime.GOOS == "windows" {
return ".ps1"
}
return ".sh"
}
16 changes: 8 additions & 8 deletions internal/integrations/v4/fixtures/fixtures_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
)

var (
IntegrationScript = testhelp.Script("..\\fixtures\\integration.ps1")
IntegrationVerboseScript = testhelp.Script("..\\fixtures\\integration_verbose.ps1")
IntegrationPrintsErr = testhelp.Script("..\\fixtures\\integration_err.ps1")
BasicCmd = testhelp.Script("..\\fixtures\\basic_cmd.ps1")
ErrorCmd = testhelp.Script("..\\fixtures\\error_cmd.ps1")
BlockedCmd = testhelp.Script("..\\fixtures\\blocked_cmd.ps1")
FileContentsWithArgCmd = testhelp.Script("..\\fixtures\\filecontents_witharg.ps1")
SleepCmd = testhelp.Script("..\\fixtures\\sleep.ps1")
IntegrationScript = testhelp.Script("..\\fixtures\\integration.sh")
IntegrationVerboseScript = testhelp.Script("..\\fixtures\\integration_verbose.sh")
IntegrationPrintsErr = testhelp.Script("..\\fixtures\\integration_err.sh")
BasicCmd = testhelp.Script("..\\fixtures\\basic_cmd.sh")
ErrorCmd = testhelp.Script("..\\fixtures\\error_cmd.sh")
BlockedCmd = testhelp.Script("..\\fixtures\\blocked_cmd.sh")
FileContentsWithArgCmd = testhelp.Script("..\\fixtures\\filecontents_witharg.sh")
SleepCmd = testhelp.Script("..\\fixtures\\sleep.sh")
// at the moment, unsupported, as they use env vars with Powershell. Left here to avoid compile errors
FileContentsCmd = testhelp.Script("unsupported-test-case")
FileContentsFromEnvCmd = testhelp.Script("unsupported-test-case")
Expand Down
10 changes: 0 additions & 10 deletions internal/integrations/v4/fixtures/integration.ps1

This file was deleted.

5 changes: 4 additions & 1 deletion internal/integrations/v4/fixtures/integration.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env sh

echo '{"name":"com.newrelic.test","protocol_version":"1","integration_version":"1.0.0","metrics":[{"event_type":"TestSample","value":"'$1'"}]}'
# Avoid later deserialization problems when receiving a windows path
Argument=$(echo "$1" | sed 's|\\|/|g')

echo '{"name":"com.newrelic.test","protocol_version":"1","integration_version":"1.0.0","metrics":[{"event_type":"TestSample","value":"'$Argument'"}]}'
16 changes: 0 additions & 16 deletions internal/integrations/v4/fixtures/integration_err.ps1

This file was deleted.

3 changes: 0 additions & 3 deletions internal/integrations/v4/fixtures/integration_verbose.ps1

This file was deleted.

9 changes: 0 additions & 9 deletions internal/integrations/v4/fixtures/sleep.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion internal/integrations/v4/testhelp/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func CommandSlice(script Script, args ...string) []string {

func getDefaultShlexOpt() config.ShlexOpt {
if runtime.GOOS == "windows" {
return config.ShlexOpt{"powershell.exe", "-Sta", "-File"}
return config.ShlexOpt{"bash.exe"}
}
return config.ShlexOpt{"/bin/sh"}
}

0 comments on commit 23316d0

Please sign in to comment.