Skip to content

Commit

Permalink
test: enhance SCP plugin with folder ignore and error handling (#192)
Browse files Browse the repository at this point in the history
- Add `TestIgnoreFolder` function to test ignoring specific folders during SCP
- Initialize and terminate `ssh-agent` if `SSH_AUTH_SOCK` is set
- Lookup user `drone-scp` and handle potential errors
- Configure `Plugin` with specific settings for SCP operation
- Execute `plugin.Exec()` and assert no errors
- Verify that certain files do not exist in the target directory after SCP operation

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored Jun 1, 2024
1 parent fe4a745 commit 87c7223
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,3 +945,42 @@ func TestPlugin_hostPort(t *testing.T) {
})
}
}

func TestIgnoreFolder(t *testing.T) {
if os.Getenv("SSH_AUTH_SOCK") != "" {
if err := exec.Command("eval", "`ssh-agent -k`").Run(); err != nil {
t.Fatalf("exec: %v", err)
}
}

u, err := user.Lookup("drone-scp")
if err != nil {
t.Fatalf("Lookup: %v", err)
}

plugin := Plugin{
Config: Config{
Host: []string{"localhost"},
Username: "drone-scp",
Protocol: easyssh.PROTOCOL_TCP4,
Port: 22,
KeyPath: "tests/.ssh/id_rsa",
Source: []string{"tests/*", "!tests/global"},
Target: []string{filepath.Join(u.HomeDir, "test_ignore")},
CommandTimeout: 60 * time.Second,
TarExec: "tar",
},
}

err = plugin.Exec()
assert.Nil(t, err)

// check file exist
if _, err := os.Stat(filepath.Join(u.HomeDir, "test_ignore", "global", "c.txt")); !os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}

if _, err := os.Stat(filepath.Join(u.HomeDir, "test_ignore", "global", "d.txt")); !os.IsNotExist(err) {
t.Fatalf("SCP-error: %v", err)
}
}

0 comments on commit 87c7223

Please sign in to comment.