fix missing exclude files (#88)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2019-01-18 16:40:50 +08:00
committed by GitHub
parent 699675c8fa
commit 75d2ee1e10
3 changed files with 13 additions and 6 deletions
+4 -2
View File
@@ -116,8 +116,10 @@ func globList(paths []string) fileList {
func buildArgs(tar string, files fileList) []string {
args := []string{}
if len(files.Ignore) > 0 {
args = append(args, "--exclude")
args = append(args, files.Ignore...)
for _, v := range files.Ignore {
args = append(args, "--exclude")
args = append(args, v)
}
}
args = append(args, "-cf")
args = append(args, getRealPath(tar))
+9 -4
View File
@@ -261,7 +261,7 @@ func TestIgnoreList(t *testing.T) {
Username: "drone-scp",
Port: "22",
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/global/*", "!tests/global/c.txt"},
Source: []string{"tests/global/*", "!tests/global/c.txt", "!tests/global/e.txt"},
StripComponents: 2,
Target: []string{filepath.Join(u.HomeDir, "ignore")},
CommandTimeout: 60,
@@ -277,6 +277,11 @@ func TestIgnoreList(t *testing.T) {
t.Fatal("c.txt file exist")
}
// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/e.txt")); err == nil {
t.Fatal("c.txt file exist")
}
if _, err := os.Stat(filepath.Join(u.HomeDir, "ignore/d.txt")); os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
@@ -407,12 +412,12 @@ func TestGlobList(t *testing.T) {
func TestBuildArgs(t *testing.T) {
list := fileList{
Source: []string{"tests/a.txt", "tests/b.txt"},
Ignore: []string{"tests/a.txt"},
Source: []string{"tests/a.txt", "tests/b.txt", "tests/c.txt"},
Ignore: []string{"tests/a.txt", "tests/b.txt"},
}
result := buildArgs("test.tar.gz", list)
expects := []string{"--exclude", "tests/a.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt"}
expects := []string{"--exclude", "tests/a.txt", "--exclude", "tests/b.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt", "tests/c.txt"}
assert.Equal(t, expects, result)
list = fileList{
View File