Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9da96c

Browse files
authored
fix: Add test for SCP (coder#2692)
* fix: Elongate agent disconnect timeout in tests This will fix the flake seen here: https://github.com/coder/coder/runs/7071719863?check_suite_focus=true * fix: Add test for SCP This was hanging due to the stdin pipe never being closed. A test has been added to make sure it works!
1 parent a805565 commit d9da96c

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

agent/agent.go

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error {
467467
}
468468
go func() {
469469
_, _ = io.Copy(stdinPipe, session)
470+
_ = stdinPipe.Close()
470471
}()
471472
err = cmd.Start()
472473
if err != nil {

agent/agent_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19+
scp "github.com/bramvdbogaerde/go-scp"
1920
"github.com/google/uuid"
2021
"github.com/pion/udp"
2122
"github.com/pion/webrtc/v3"
@@ -149,6 +150,20 @@ func TestAgent(t *testing.T) {
149150
require.NoError(t, err)
150151
})
151152

153+
t.Run("SCP", func(t *testing.T) {
154+
t.Parallel()
155+
sshClient, err := setupAgent(t, agent.Metadata{}, 0).SSHClient()
156+
require.NoError(t, err)
157+
scpClient, err := scp.NewClientBySSH(sshClient)
158+
require.NoError(t, err)
159+
tempFile := filepath.Join(t.TempDir(), "scp")
160+
content := "hello world"
161+
err = scpClient.CopyFile(context.Background(), strings.NewReader(content), tempFile, "0755")
162+
require.NoError(t, err)
163+
_, err = os.Stat(tempFile)
164+
require.NoError(t, err)
165+
})
166+
152167
t.Run("EnvironmentVariables", func(t *testing.T) {
153168
t.Parallel()
154169
key := "EXAMPLE"

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
5050
github.com/awalterschulze/gographviz v2.0.3+incompatible
5151
github.com/bgentry/speakeasy v0.1.0
52+
github.com/bramvdbogaerde/go-scp v1.2.0
5253
github.com/briandowns/spinner v1.18.1
5354
github.com/charmbracelet/charm v0.12.1
5455
github.com/charmbracelet/lipgloss v0.5.0

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
270270
github.com/bombsimon/wsl/v3 v3.3.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc=
271271
github.com/bool64/shared v0.1.4 h1:zwtb1dl2QzDa9TJOq2jzDTdb5IPf9XlxTGKN8cySWT0=
272272
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
273+
github.com/bramvdbogaerde/go-scp v1.2.0 h1:mNF1lCXQ6jQcxCBBuc2g/CQwVy/4QONaoD5Aqg9r+Zg=
274+
github.com/bramvdbogaerde/go-scp v1.2.0/go.mod h1:s4ZldBoRAOgUg8IrRP2Urmq5qqd2yPXQTPshACY8vQ0=
273275
github.com/breml/bidichk v0.1.1/go.mod h1:zbfeitpevDUGI7V91Uzzuwrn4Vls8MoBMrwtt78jmso=
274276
github.com/bshuster-repo/logrus-logstash-hook v0.4.1/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=
275277
github.com/bshuster-repo/logrus-logstash-hook v1.0.0/go.mod h1:zsTqEiSzDgAa/8GZR7E1qaXrhYNDKBYy5/dWPTIflbk=

0 commit comments

Comments
 (0)