Skip to content

Commit 28c0646

Browse files
committed
Fix linting
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 2cf357a commit 28c0646

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

agent/agentssh/agentssh.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,10 @@ func (s *Server) sessionStart(session ssh.Session) error {
235235
if isPty {
236236
return s.startPTYSession(session, cmd, sshPty, windowSize)
237237
}
238-
239-
return s.startNonPTYSession(session, cmd)
238+
return startNonPTYSession(session, cmd)
240239
}
241240

242-
func (s *Server) startNonPTYSession(session ssh.Session, cmd *exec.Cmd) error {
241+
func startNonPTYSession(session ssh.Session, cmd *exec.Cmd) error {
243242
cmd.Stdout = session
244243
cmd.Stderr = session.Stderr()
245244
// This blocks forever until stdin is received if we don't
@@ -330,7 +329,7 @@ func (s *Server) startPTYSession(session ptySession, cmd *exec.Cmd, sshPty ssh.P
330329
n, err := io.Copy(session, ptty.OutputReader())
331330
s.logger.Debug(ctx, "copy output done", slog.F("bytes", n), slog.Error(err))
332331
if err != nil {
333-
return xerrors.Errorf("copy error: %w", err, err, err)
332+
return xerrors.Errorf("copy error: %w", err)
334333
}
335334
// We've gotten all the output, but we need to wait for the process to
336335
// complete so that we can get the exit code. This returns
@@ -348,11 +347,6 @@ func (s *Server) startPTYSession(session ptySession, cmd *exec.Cmd, sshPty ssh.P
348347
return nil
349348
}
350349

351-
type readNopCloser struct{ io.Reader }
352-
353-
// Close implements io.Closer.
354-
func (readNopCloser) Close() error { return nil }
355-
356350
func (s *Server) sftpHandler(session ssh.Session) {
357351
ctx := session.Context()
358352

agent/agentssh/agentssh_internal_test.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import (
77
"net"
88
"os/exec"
99
"testing"
10-
"time"
1110

12-
"cdr.dev/slog/sloggers/slogtest"
1311
gliderssh "github.com/gliderlabs/ssh"
1412
"github.com/stretchr/testify/assert"
1513
"github.com/stretchr/testify/require"
14+
15+
"github.com/coder/coder/testutil"
16+
17+
"cdr.dev/slog/sloggers/slogtest"
1618
)
1719

1820
const longScript = `
@@ -28,7 +30,7 @@ echo "done"
2830
func Test_sessionStart_orphan(t *testing.T) {
2931
t.Parallel()
3032

31-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
33+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
3234
defer cancel()
3335
logger := slogtest.Make(t, nil)
3436
s, err := NewServer(ctx, logger, 0)
@@ -62,12 +64,12 @@ func Test_sessionStart_orphan(t *testing.T) {
6264
go func() {
6365
defer close(readDone)
6466
s := bufio.NewScanner(toClient)
65-
require.True(t, s.Scan())
67+
assert.True(t, s.Scan())
6668
txt := s.Text()
6769
assert.Equal(t, "started", txt, "output corrupted")
6870
}()
6971

70-
waitForChan(t, readDone, ctx, "read timeout")
72+
waitForChan(ctx, t, readDone, "read timeout")
7173
// process is started, and should be sleeping for ~30 seconds
7274

7375
sessionCancel()
@@ -77,13 +79,13 @@ func Test_sessionStart_orphan(t *testing.T) {
7779
// that the server isn't properly shutting down sessions when they are
7880
// disconnected client side, which could lead to processes hanging around
7981
// indefinitely.
80-
waitForChan(t, done, ctx, "handler timeout")
82+
waitForChan(ctx, t, done, "handler timeout")
8183

8284
err = fromClient.Close()
8385
require.NoError(t, err)
8486
}
8587

86-
func waitForChan(t *testing.T, c <-chan struct{}, ctx context.Context, msg string) {
88+
func waitForChan(ctx context.Context, t *testing.T, c <-chan struct{}, msg string) {
8789
t.Helper()
8890
select {
8991
case <-c:
@@ -121,12 +123,12 @@ func (s *testSession) Context() gliderssh.Context {
121123
return s.ctx
122124
}
123125

124-
func (s *testSession) DisablePTYEmulation() {}
126+
func (*testSession) DisablePTYEmulation() {}
125127

126128
// RawCommand returns "quiet logon" so that the PTY handler doesn't attempt to
127129
// write the message of the day, which will interfere with our tests. It writes
128130
// the message of the day if it's a shell login (zero length RawCommand()).
129-
func (s *testSession) RawCommand() string { return "quiet logon" }
131+
func (*testSession) RawCommand() string { return "quiet logon" }
130132

131133
func (s *testSession) Read(p []byte) (n int, err error) {
132134
return s.toPty.Read(p)
@@ -136,49 +138,49 @@ func (s *testSession) Write(p []byte) (n int, err error) {
136138
return s.fromPty.Write(p)
137139
}
138140

139-
func (c testSSHContext) Lock() {
141+
func (testSSHContext) Lock() {
140142
panic("not implemented")
141143
}
142-
func (c testSSHContext) Unlock() {
144+
func (testSSHContext) Unlock() {
143145
panic("not implemented")
144146
}
145147

146148
// User returns the username used when establishing the SSH connection.
147-
func (c testSSHContext) User() string {
149+
func (testSSHContext) User() string {
148150
panic("not implemented")
149151
}
150152

151153
// SessionID returns the session hash.
152-
func (c testSSHContext) SessionID() string {
154+
func (testSSHContext) SessionID() string {
153155
panic("not implemented")
154156
}
155157

156158
// ClientVersion returns the version reported by the client.
157-
func (c testSSHContext) ClientVersion() string {
159+
func (testSSHContext) ClientVersion() string {
158160
panic("not implemented")
159161
}
160162

161163
// ServerVersion returns the version reported by the server.
162-
func (c testSSHContext) ServerVersion() string {
164+
func (testSSHContext) ServerVersion() string {
163165
panic("not implemented")
164166
}
165167

166168
// RemoteAddr returns the remote address for this connection.
167-
func (c testSSHContext) RemoteAddr() net.Addr {
169+
func (testSSHContext) RemoteAddr() net.Addr {
168170
panic("not implemented")
169171
}
170172

171173
// LocalAddr returns the local address for this connection.
172-
func (c testSSHContext) LocalAddr() net.Addr {
174+
func (testSSHContext) LocalAddr() net.Addr {
173175
panic("not implemented")
174176
}
175177

176178
// Permissions returns the Permissions object used for this connection.
177-
func (c testSSHContext) Permissions() *gliderssh.Permissions {
179+
func (testSSHContext) Permissions() *gliderssh.Permissions {
178180
panic("not implemented")
179181
}
180182

181183
// SetValue allows you to easily write new values into the underlying context.
182-
func (c testSSHContext) SetValue(key, value interface{}) {
184+
func (testSSHContext) SetValue(_, _ interface{}) {
183185
panic("not implemented")
184186
}

agent/agentssh/agentssh_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ import (
1010
"sync"
1111
"testing"
1212

13-
"cdr.dev/slog/sloggers/slogtest"
1413
"github.com/stretchr/testify/assert"
1514
"github.com/stretchr/testify/require"
1615
"go.uber.org/atomic"
1716
"go.uber.org/goleak"
1817
"golang.org/x/crypto/ssh"
1918

19+
"cdr.dev/slog/sloggers/slogtest"
20+
2021
"github.com/coder/coder/agent/agentssh"
2122
"github.com/coder/coder/codersdk/agentsdk"
2223
"github.com/coder/coder/pty/ptytest"

pty/pty.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var ErrClosed = xerrors.New("pty: closed")
1313

1414
// PTYCmd is an interface for interacting with a pseudo-TTY where we control
1515
// only one end, and the other end has been passed to a running os.Process.
16+
// nolint:revive
1617
type PTYCmd interface {
1718
io.Closer
1819

0 commit comments

Comments
 (0)