Skip to content

Commit

Permalink
Replace customerrors with go-multierror (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
urohit011 authored Jan 22, 2021
1 parent 8801c83 commit d000797
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 49 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/google/go-containerregistry v0.0.0-20200110202235-f4fb41bf00a3
github.com/google/uuid v1.1.1
github.com/gruntwork-io/gruntwork-cli v0.7.0
github.com/hashicorp/go-multierror v1.1.0
github.com/imdario/mergo v0.3.7 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
github.com/jstemmer/go-junit-report v0.9.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/gruntwork-io/gruntwork-cli v0.7.0 h1:YgSAmfCj9c61H+zuvHwKfYUwlMhu5arnQQLM4RH+CYs=
github.com/gruntwork-io/gruntwork-cli v0.7.0/go.mod h1:jp6Z7NcLF2avpY8v71fBx6hds9eOFPELSuD/VPv7w00=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
Expand Down
10 changes: 5 additions & 5 deletions modules/aws/ec2-files.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"os"
"path/filepath"

"github.com/gruntwork-io/terratest/modules/customerrors"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/ssh"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/hashicorp/go-multierror"
)

// RemoteFileSpecification describes which files you want to copy from your instances
Expand Down Expand Up @@ -212,24 +212,24 @@ func FetchFilesFromAsgs(t testing.TestingT, awsRegion string, spec RemoteFileSpe
// remoteDirectory (using sudo if useSudo is true), and stores the files locally at
// localDirectory/<publicip>/<remoteFolderName>
func FetchFilesFromAsgsE(t testing.TestingT, awsRegion string, spec RemoteFileSpecification) error {
errorsOccurred := []error{}
var errorsOccurred = new(multierror.Error)

for _, curAsg := range spec.AsgNames {
for curRemoteDir, fileFilters := range spec.RemotePathToFileFilter {

instanceIDs, err := GetInstanceIdsForAsgE(t, curAsg, awsRegion)
if err != nil {
errorsOccurred = append(errorsOccurred, err)
errorsOccurred = multierror.Append(errorsOccurred, err)
} else {
for _, instanceID := range instanceIDs {
err = FetchFilesFromInstanceE(t, awsRegion, spec.SshUser, spec.KeyPair, instanceID, spec.UseSudo, curRemoteDir, spec.LocalDestinationDir, fileFilters)

if err != nil {
errorsOccurred = append(errorsOccurred, err)
errorsOccurred = multierror.Append(errorsOccurred, err)
}
}
}
}
}
return customerrors.NewMultiError(errorsOccurred...)
return errorsOccurred.ErrorOrNil()
}
36 changes: 0 additions & 36 deletions modules/customerrors/multierror.go

This file was deleted.

8 changes: 4 additions & 4 deletions modules/packer/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"time"

"github.com/gruntwork-io/terratest/modules/retry"
"github.com/hashicorp/go-multierror"

"github.com/gruntwork-io/terratest/modules/customerrors"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/gruntwork-io/terratest/modules/testing"
Expand Down Expand Up @@ -55,7 +55,7 @@ func BuildArtifactsE(t testing.TestingT, artifactNameToOptions map[string]*Optio
waitForArtifacts.Add(len(artifactNameToOptions))

var artifactNameToArtifactId = map[string]string{}
errorsOccurred := []error{}
var errorsOccurred = new(multierror.Error)

for artifactName, curOptions := range artifactNameToOptions {
// The following is necessary to make sure artifactName and curOptions don't
Expand All @@ -67,7 +67,7 @@ func BuildArtifactsE(t testing.TestingT, artifactNameToOptions map[string]*Optio
artifactId, err := BuildArtifactE(t, curOptions)

if err != nil {
errorsOccurred = append(errorsOccurred, err)
errorsOccurred = multierror.Append(errorsOccurred, err)
} else {
artifactNameToArtifactId[artifactName] = artifactId
}
Expand All @@ -76,7 +76,7 @@ func BuildArtifactsE(t testing.TestingT, artifactNameToOptions map[string]*Optio

waitForArtifacts.Wait()

return artifactNameToArtifactId, customerrors.NewMultiError(errorsOccurred...)
return artifactNameToArtifactId, errorsOccurred.ErrorOrNil()
}

// BuildArtifact builds the given Packer template and return the generated Artifact ID.
Expand Down
8 changes: 4 additions & 4 deletions modules/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"strings"
"time"

"github.com/gruntwork-io/terratest/modules/customerrors"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/hashicorp/go-multierror"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
)
Expand Down Expand Up @@ -164,7 +164,7 @@ func ScpDirFromE(t testing.TestingT, options ScpDownloadOptions, useSudo bool) e
}
}

errorsOccurred := []error{}
var errorsOccurred = new(multierror.Error)

for _, fullRemoteFilePath := range filesInDir {
fileName := filepath.Base(fullRemoteFilePath)
Expand All @@ -179,10 +179,10 @@ func ScpDirFromE(t testing.TestingT, options ScpDownloadOptions, useSudo bool) e
logger.Logf(t, "Copying remote file: %s to local path %s", fullRemoteFilePath, localFilePath)

err = copyFileFromRemote(t, sshSession, localFile, fullRemoteFilePath, useSudo)
errorsOccurred = append(errorsOccurred, err)
errorsOccurred = multierror.Append(errorsOccurred, err)
}

return customerrors.NewMultiError(errorsOccurred...)
return errorsOccurred.ErrorOrNil()
}

// CheckSshConnection checks that you can connect via SSH to the given host and fail the test if the connection fails.
Expand Down

0 comments on commit d000797

Please sign in to comment.