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