From 861d81b33575cee42c8d7fda677ee3bce68d9a55 Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Tue, 29 Jun 2021 16:07:37 -0400 Subject: [PATCH] remove dep to azure lib --- go.mod | 1 - go.sum | 2 - .../driver_install_or_update_test.go | 6 +- test/integration/helpers_test.go | 113 ++++++++++++++++++ 4 files changed, 115 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b6fdbb9ebe46..9159b9425553 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.16 require ( cloud.google.com/go/storage v1.15.0 contrib.go.opencensus.io/exporter/stackdriver v0.12.1 - github.com/Azure/azure-sdk-for-go v43.3.0+incompatible github.com/Delta456/box-cli-maker/v2 v2.2.1 github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v0.16.0 github.com/Microsoft/hcsshim v0.8.17 // indirect diff --git a/go.sum b/go.sum index 2108c2a16f11..7dfc4df2224d 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7 gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go v43.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v43.3.0+incompatible h1:o0G4JAsOzeVJEwU0Ud9bh+lUHPUc0GkFENJ02dk51Uo= -github.com/Azure/azure-sdk-for-go v43.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v10.8.1+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= diff --git a/test/integration/driver_install_or_update_test.go b/test/integration/driver_install_or_update_test.go index 4742b0537198..24d16623489c 100644 --- a/test/integration/driver_install_or_update_test.go +++ b/test/integration/driver_install_or_update_test.go @@ -25,7 +25,6 @@ import ( "runtime" "testing" - "github.com/Azure/azure-sdk-for-go/tools/apidiff/ioext" "github.com/blang/semver/v4" "k8s.io/minikube/pkg/minikube/driver/auxdriver" @@ -290,13 +289,12 @@ func prepareTempMinikubeDirWithHyperkitDriver(name, driver string) (string, stri } // copy driver to temp bin testDriverPath := filepath.Join(mkBinDir, "docker-machine-driver-hyperkit") - - if err = ioext.CopyFile(testDataDriverPath, testDriverPath, false); err != nil { + if err = CopyFile(testDataDriverPath, testDriverPath, false); err != nil { return "", "", fmt.Errorf("failed to setup current hyperkit driver: %v", err) } // try to copy cached files to the temp minikube folder to avoid downloading of iso and preloads - _ = ioext.CopyDir(filepath.Join(localpath.MakeMiniPath("cache")), filepath.Join(mkDir, "cache")) + _ = CopyDir(filepath.Join(localpath.MakeMiniPath("cache")), filepath.Join(mkDir, "cache")) // change permission to allow driver to be executable if err = os.Chmod(testDriverPath, 0755); err != nil { diff --git a/test/integration/helpers_test.go b/test/integration/helpers_test.go index da436f79cbfb..5e1fa1fc9e0b 100644 --- a/test/integration/helpers_test.go +++ b/test/integration/helpers_test.go @@ -26,8 +26,11 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" + "io" "io/ioutil" + "os" "os/exec" "path/filepath" "strconv" @@ -557,3 +560,113 @@ func testCpCmd(ctx context.Context, t *testing.T, profile string, node string) { t.Errorf("/testdata/cp-test.txt content mismatch (-want +got):\n%s", diff) } } + +// CopyFile copies the specified source file to the specified destination file. +// Specify true for overwrite to overwrite the destination file if it already exits. +func CopyFile(src, dst string, overwrite bool) error { + srcFile, err := os.Open(src) + if err != nil { + return err + } + defer srcFile.Close() + + if !overwrite { + // check if the file exists, if it does then return an error + _, err := os.Stat(dst) + if err != nil && !os.IsNotExist(err) { + return errors.New("won't overwrite destination file") + } + } + + dstFile, err := os.Create(dst) + if err != nil { + return err + } + defer dstFile.Close() + + _, err = io.Copy(dstFile, srcFile) + if err != nil { + return err + } + + // flush the buffer + err = dstFile.Sync() + if err != nil { + return err + } + + // copy file permissions + srcInfo, err := os.Stat(src) + if err != nil { + return err + } + + err = os.Chmod(dst, srcInfo.Mode()) + if err != nil { + return err + } + + return nil +} + +// CopyDir recursively copies the specified source directory tree to the +// specified destination. The destination directory must not exist. Any +// symlinks under src are ignored. +func CopyDir(src, dst string) error { + src = filepath.Clean(src) + dst = filepath.Clean(dst) + + // verify that src is a directory + srcInfo, err := os.Stat(src) + if err != nil { + return err + } + if !srcInfo.IsDir() { + return fmt.Errorf("source is not a directory") + } + + // now verify that dst doesn't exist + _, err = os.Stat(dst) + if err != nil && !os.IsNotExist(err) { + return err + } + if err == nil { + return fmt.Errorf("destination directory already exists") + } + + err = os.MkdirAll(dst, srcInfo.Mode()) + if err != nil { + return err + } + + // get the collection of directory entries under src. + // for each entry build its corresponding path under dst. + entries, err := ioutil.ReadDir(src) + if err != nil { + return err + } + + for _, entry := range entries { + // skip symlinks + if entry.Mode()&os.ModeSymlink != 0 { + continue + } + + srcPath := filepath.Join(src, entry.Name()) + dstPath := filepath.Join(dst, entry.Name()) + + if entry.IsDir() { + err = CopyDir(srcPath, dstPath) + if err != nil { + return err + } + } else { + err = CopyFile(srcPath, dstPath, true) + if err != nil { + return err + } + } + } + + return nil +}