-
Notifications
You must be signed in to change notification settings - Fork 1
/
import_test.go
56 lines (44 loc) · 1.43 KB
/
import_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"path/filepath"
"testing"
"os"
"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/fileutil"
asrt "github.com/stretchr/testify/assert"
)
// TestImportTilde tests passing paths to import-files that use ~ to represent home dir.
func TestImportTilde(t *testing.T) {
assert := asrt.New(t)
site := TestSites[0]
homedir, err := os.UserHomeDir()
assert.NoError(err)
cwd, _ := os.Getwd()
testFile := filepath.Join(homedir, "testfile.tar.gz")
err = fileutil.CopyFile(filepath.Join(cwd, "testdata", "testfile.tar.gz"), testFile)
assert.NoError(err)
cleanup := site.Chdir()
defer rmFile(testFile)
// this ~ should be expanded by shell
args := []string{"import-files", "--src", "~/testfile.tar.gz"}
out, err := exec.RunCommand(DdevBin, args)
if err != nil {
t.Log("Error Output from ddev import-files:", out, site)
}
assert.NoError(err)
assert.Contains(string(out), "Successfully imported files")
// this ~ is not expanded by shell, ddev should convert it to a valid path
args = []string{"import-files", "--src=~/testfile.tar.gz"}
out, err = exec.RunCommand(DdevBin, args)
if err != nil {
t.Log("Error Output from ddev import-files:", out, site)
}
assert.NoError(err)
assert.Contains(string(out), "Successfully imported files")
cleanup()
assert.NoError(nil)
}
// rmFile simply allows us to defer os.Remove while ignoring the error return.
func rmFile(fullPath string) {
_ = os.Remove(fullPath)
}