Skip to content

Commit

Permalink
remove dep to azure lib
Browse files Browse the repository at this point in the history
  • Loading branch information
medyagh committed Jun 29, 2021
1 parent 47dbbac commit 861d81b
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 7 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 2 additions & 4 deletions test/integration/driver_install_or_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
113 changes: 113 additions & 0 deletions test/integration/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -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
}

0 comments on commit 861d81b

Please sign in to comment.