From c6b82bddd6e55e79946f25404f78a5b67cb08ff7 Mon Sep 17 00:00:00 2001 From: ishangupta-ds Date: Mon, 13 Sep 2021 13:02:59 +0530 Subject: [PATCH] removing usage of github.com/pkg/errors from test/conformance/image/go-runner/ directory Signed-off-by: ishangupta-ds formatted using gofmt script Signed-off-by: ishangupta-ds adding nil check for error Signed-off-by: ishangupta-ds adding nil check for errors Signed-off-by: ishangupta-ds formatted Signed-off-by: ishangupta-ds --- test/conformance/image/go-runner/main.go | 29 ++++++++++++-------- test/conformance/image/go-runner/tar.go | 19 +++++++------ test/conformance/image/go-runner/tar_test.go | 4 +-- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/test/conformance/image/go-runner/main.go b/test/conformance/image/go-runner/main.go index f96bd7aa540..a7e47c7c042 100644 --- a/test/conformance/image/go-runner/main.go +++ b/test/conformance/image/go-runner/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "fmt" "io" "io/ioutil" "log" @@ -24,8 +25,6 @@ import ( "os/signal" "path/filepath" "strings" - - "github.com/pkg/errors" ) func main() { @@ -62,7 +61,7 @@ func configureAndRunWithEnv(env Getenver) error { logFilePath := filepath.Join(resultsDir, logFileName) logFile, err := os.Create(logFilePath) if err != nil { - return errors.Wrapf(err, "failed to create log file %v", logFilePath) + return fmt.Errorf("failed to create log file %v: %w", logFilePath, err) } mw := io.MultiWriter(os.Stdout, logFile) cmd := getCmd(env, mw) @@ -70,12 +69,18 @@ func configureAndRunWithEnv(env Getenver) error { log.Printf("Running command:\n%v\n", cmdInfo(cmd)) err = cmd.Start() if err != nil { - return errors.Wrap(err, "starting command") + return fmt.Errorf("starting command: %w", err) } // Handle signals and shutdown process gracefully. go setupSigHandler(cmd.Process.Pid) - return errors.Wrap(cmd.Wait(), "running command") + + err = cmd.Wait() + if err != nil { + return fmt.Errorf("running command: %w", err) + } + + return nil } // setupSigHandler will kill the process identified by the given PID if it @@ -107,7 +112,7 @@ func saveResults(resultsDir string) error { err := tarDir(resultsDir, filepath.Join(resultsDir, resultsTarballName)) if err != nil { - return errors.Wrapf(err, "tar directory %v", resultsDir) + return fmt.Errorf("tar directory %v: %w", resultsDir, err) } doneFile := filepath.Join(resultsDir, doneFileName) @@ -115,11 +120,13 @@ func saveResults(resultsDir string) error { resultsTarball := filepath.Join(resultsDir, resultsTarballName) resultsTarball, err = filepath.Abs(resultsTarball) if err != nil { - return errors.Wrapf(err, "failed to find absolute path for %v", resultsTarball) + return fmt.Errorf("failed to find absolute path for %v: %w", resultsTarball, err) } - return errors.Wrap( - ioutil.WriteFile(doneFile, []byte(resultsTarball), os.FileMode(0777)), - "writing donefile", - ) + err = ioutil.WriteFile(doneFile, []byte(resultsTarball), os.FileMode(0777)) + if err != nil { + return fmt.Errorf("writing donefile: %w", err) + } + + return nil } diff --git a/test/conformance/image/go-runner/tar.go b/test/conformance/image/go-runner/tar.go index 2309387bfec..85097070e4b 100644 --- a/test/conformance/image/go-runner/tar.go +++ b/test/conformance/image/go-runner/tar.go @@ -19,12 +19,11 @@ package main import ( "archive/tar" "compress/gzip" + "fmt" "io" "os" "path/filepath" "strings" - - "github.com/pkg/errors" ) // tarDir takes a source and variable writers and walks 'source' writing each file @@ -32,12 +31,12 @@ import ( func tarDir(dir, outpath string) error { // ensure the src actually exists before trying to tar it if _, err := os.Stat(dir); err != nil { - return errors.Wrapf(err, "tar unable to stat directory %v", dir) + return fmt.Errorf("tar unable to stat directory %v: %w", dir, err) } outfile, err := os.Create(outpath) if err != nil { - return errors.Wrapf(err, "creating tarball %v", outpath) + return fmt.Errorf("creating tarball %v: %w", outpath, err) } defer outfile.Close() @@ -61,23 +60,27 @@ func tarDir(dir, outpath string) error { // Create a new dir/file header. header, err := tar.FileInfoHeader(fi, fi.Name()) if err != nil { - return errors.Wrapf(err, "creating file info header %v", fi.Name()) + return fmt.Errorf("creating file info header %v: %w", fi.Name(), err) } // Update the name to correctly reflect the desired destination when untaring. header.Name = strings.TrimPrefix(strings.Replace(file, dir, "", -1), string(filepath.Separator)) if err := tw.WriteHeader(header); err != nil { - return errors.Wrapf(err, "writing header for tarball %v", header.Name) + return fmt.Errorf("writing header for tarball %v: %w", header.Name, err) } // Open files, copy into tarfile, and close. f, err := os.Open(file) if err != nil { - return errors.Wrapf(err, "opening file %v for writing into tarball", file) + return fmt.Errorf("opening file %v for writing into tarball: %w", file, err) } defer f.Close() _, err = io.Copy(tw, f) - return errors.Wrapf(err, "creating file %v contents into tarball", file) + if err != nil { + return fmt.Errorf("creating file %v contents into tarball: %w", file, err) + } + + return nil }) } diff --git a/test/conformance/image/go-runner/tar_test.go b/test/conformance/image/go-runner/tar_test.go index 98a22740d14..dcf012cba82 100644 --- a/test/conformance/image/go-runner/tar_test.go +++ b/test/conformance/image/go-runner/tar_test.go @@ -27,8 +27,6 @@ import ( "reflect" "strings" "testing" - - "github.com/pkg/errors" ) func TestTar(t *testing.T) { @@ -123,7 +121,7 @@ func readAllTar(tarPath string) (map[string]string, error) { gzStream, err := gzip.NewReader(fileReader) if err != nil { - return nil, errors.Wrap(err, "couldn't uncompress reader") + return nil, fmt.Errorf("couldn't uncompress reader: %w", err) } defer gzStream.Close()