|
|
|
@ -46,13 +46,9 @@ var (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestRenameWithFallback(t *testing.T) {
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
if err = RenameWithFallback(filepath.Join(dir, "does_not_exists"), filepath.Join(dir, "dst")); err == nil {
|
|
|
|
|
if err := RenameWithFallback(filepath.Join(dir, "does_not_exists"), filepath.Join(dir, "dst")); err == nil {
|
|
|
|
|
t.Fatal("expected an error for non existing file, but got nil")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -64,31 +60,27 @@ func TestRenameWithFallback(t *testing.T) {
|
|
|
|
|
srcf.Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err = RenameWithFallback(srcpath, filepath.Join(dir, "dst")); err != nil {
|
|
|
|
|
if err := RenameWithFallback(srcpath, filepath.Join(dir, "dst")); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srcpath = filepath.Join(dir, "a")
|
|
|
|
|
if err = os.MkdirAll(srcpath, 0777); err != nil {
|
|
|
|
|
if err := os.MkdirAll(srcpath, 0777); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dstpath := filepath.Join(dir, "b")
|
|
|
|
|
if err = os.MkdirAll(dstpath, 0777); err != nil {
|
|
|
|
|
if err := os.MkdirAll(dstpath, 0777); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err = RenameWithFallback(srcpath, dstpath); err == nil {
|
|
|
|
|
if err := RenameWithFallback(srcpath, dstpath); err == nil {
|
|
|
|
|
t.Fatal("expected an error if dst is an existing directory, but got nil")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCopyDir(t *testing.T) {
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcdir := filepath.Join(dir, "src")
|
|
|
|
|
if err := os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
@ -108,7 +100,7 @@ func TestCopyDir(t *testing.T) {
|
|
|
|
|
for i, file := range files {
|
|
|
|
|
fn := filepath.Join(srcdir, file.path)
|
|
|
|
|
dn := filepath.Dir(fn)
|
|
|
|
|
if err = os.MkdirAll(dn, 0755); err != nil {
|
|
|
|
|
if err := os.MkdirAll(dn, 0755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -189,14 +181,10 @@ func TestCopyDirFail_SrcInaccessible(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
dstdir = filepath.Join(dir, "dst")
|
|
|
|
|
if err = CopyDir(srcdir, dstdir); err == nil {
|
|
|
|
|
if err := CopyDir(srcdir, dstdir); err == nil {
|
|
|
|
|
t.Fatalf("expected error for CopyDir(%s, %s), got none", srcdir, dstdir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -218,14 +206,10 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
var srcdir, dstdir string
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcdir = filepath.Join(dir, "src")
|
|
|
|
|
if err = os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
|
if err := os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -242,12 +226,9 @@ func TestCopyDirFail_DstInaccessible(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestCopyDirFail_SrcIsNotDir(t *testing.T) {
|
|
|
|
|
var srcdir, dstdir string
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcdir = filepath.Join(dir, "src")
|
|
|
|
|
if _, err = os.Create(srcdir); err != nil {
|
|
|
|
@ -268,12 +249,9 @@ func TestCopyDirFail_SrcIsNotDir(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
func TestCopyDirFail_DstExists(t *testing.T) {
|
|
|
|
|
var srcdir, dstdir string
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcdir = filepath.Join(dir, "src")
|
|
|
|
|
if err = os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
@ -314,14 +292,10 @@ func TestCopyDirFailOpen(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
var srcdir, dstdir string
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcdir = filepath.Join(dir, "src")
|
|
|
|
|
if err = os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
|
if err := os.MkdirAll(srcdir, 0755); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -345,11 +319,7 @@ func TestCopyDirFailOpen(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCopyFile(t *testing.T) {
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcf, err := os.Create(filepath.Join(dir, "srcfile"))
|
|
|
|
|
if err != nil {
|
|
|
|
@ -405,13 +375,7 @@ func cleanUpDir(dir string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCopyFileSymlink(t *testing.T) {
|
|
|
|
|
var tempdir, err = ioutil.TempDir("", "gotest")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to create directory: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer cleanUpDir(tempdir)
|
|
|
|
|
tempdir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
testcases := map[string]string{
|
|
|
|
|
filepath.Join("./testdata/symlinks/file-symlink"): filepath.Join(tempdir, "dst-file"),
|
|
|
|
@ -477,11 +441,7 @@ func TestCopyFileFail(t *testing.T) {
|
|
|
|
|
t.Skip("Skipping for root user")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
srcf, err := os.Create(filepath.Join(dir, "srcfile"))
|
|
|
|
|
if err != nil {
|
|
|
|
@ -517,11 +477,7 @@ func TestCopyFileFail(t *testing.T) {
|
|
|
|
|
// files this function creates. It is the caller's responsibility to call
|
|
|
|
|
// this function before the test is done running, whether there's an error or not.
|
|
|
|
|
func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
return nil // keep compiler happy
|
|
|
|
|
}
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
subdir := filepath.Join(dir, "dir")
|
|
|
|
|
|
|
|
|
@ -529,9 +485,6 @@ func setupInaccessibleDir(t *testing.T, op func(dir string) error) func() {
|
|
|
|
|
if err := os.Chmod(subdir, 0777); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
|
|
|
t.Error(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := os.Mkdir(subdir, 0777); err != nil {
|
|
|
|
@ -617,14 +570,10 @@ func TestIsSymlink(t *testing.T) {
|
|
|
|
|
t.Skip("Skipping for root user")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "helm-tmp")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
|
dir := t.TempDir()
|
|
|
|
|
|
|
|
|
|
dirPath := filepath.Join(dir, "directory")
|
|
|
|
|
if err = os.MkdirAll(dirPath, 0777); err != nil {
|
|
|
|
|
if err := os.MkdirAll(dirPath, 0777); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|