Skip to content

Commit faf9c6a

Browse files
committed
chore(agent): fix golangci-lint failures under the docker build tag
gofumpt alignment in getWrappedCommand, and move the fakeGosshConn test helper into the !docker test file where its only user lives so it is not flagged as unused when building with -tags docker.
1 parent 4d5bf85 commit faf9c6a

3 files changed

Lines changed: 37 additions & 34 deletions

File tree

agent/server/modes/host/command/command_docker.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ func getWrappedCommand(nsArgs []string, uid, gid uint32, groups []uint32, home s
8585
"1",
8686
}, nsArgs...)
8787

88-
nsenterCmd = append(nsenterCmd,
88+
nsenterCmd = append(
89+
nsenterCmd,
8990
[]string{
9091
"-S",
9192
strconv.Itoa(int(uid)),

agent/server/modes/host/sessioner_native_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package host
44

55
import (
6+
"errors"
7+
"net"
68
"os/exec"
79
"sync/atomic"
810
"testing"
@@ -15,6 +17,36 @@ import (
1517
gossh "golang.org/x/crypto/ssh"
1618
)
1719

20+
// fakeGosshConn is a minimal implementation of gossh.Conn that can be embedded
21+
// in a gossh.ServerConn so tests can inject a ServerConn into the session context
22+
// without needing a real SSH network connection.
23+
type fakeGosshConn struct{}
24+
25+
func (f *fakeGosshConn) User() string { return "root" }
26+
func (f *fakeGosshConn) SessionID() []byte { return nil }
27+
func (f *fakeGosshConn) ClientVersion() []byte { return nil }
28+
func (f *fakeGosshConn) ServerVersion() []byte { return nil }
29+
func (f *fakeGosshConn) RemoteAddr() net.Addr { return &net.TCPAddr{} }
30+
func (f *fakeGosshConn) LocalAddr() net.Addr { return &net.TCPAddr{} }
31+
func (f *fakeGosshConn) SendRequest(_ string, _ bool, _ []byte) (bool, []byte, error) {
32+
return false, nil, nil
33+
}
34+
35+
func (f *fakeGosshConn) OpenChannel(_ string, _ []byte) (gossh.Channel, <-chan *gossh.Request, error) {
36+
return nil, nil, errors.New("not implemented")
37+
}
38+
39+
func (f *fakeGosshConn) Close() error { return nil }
40+
41+
// Wait blocks until the returned channel is closed — used by tests to
42+
// control when the "kill on disconnect" goroutine unblocks.
43+
func (f *fakeGosshConn) Wait() error {
44+
// Block until the test is done (goroutine is abandoned when the test
45+
// function returns; the Go runtime cleans it up). This is acceptable
46+
// because the caller only needs Wait to not panic.
47+
select {}
48+
}
49+
1850
// TestExec_NonPty_SucceedingCommand is a regression guard for the non-PTY path of
1951
// Exec(). It verifies that:
2052
// - a real command starts and completes

agent/server/modes/host/sessioner_test.go

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func newFakeSession(sessionID, user string) *fakeSession {
120120
}
121121
}
122122

123+
// Ensure gossh.Channel is satisfied (compile-time check via assignment).
124+
var _ gossh.Channel = (*fakeSession)(nil)
125+
123126
// TestFakeSessionCompiles is a compile-time check that fakeSession fully
124127
// implements gliderssh.Session. The test body is intentionally empty — a build
125128
// failure means the interface is incomplete.
@@ -140,39 +143,6 @@ func TestFakeSessionCompiles(t *testing.T) {
140143
}
141144
}
142145

143-
// Ensure gossh.Channel is satisfied (compile-time check via assignment).
144-
var _ gossh.Channel = (*fakeSession)(nil)
145-
146-
// fakeGosshConn is a minimal implementation of gossh.Conn that can be embedded
147-
// in a gossh.ServerConn so tests can inject a ServerConn into the session context
148-
// without needing a real SSH network connection.
149-
type fakeGosshConn struct{}
150-
151-
func (f *fakeGosshConn) User() string { return "root" }
152-
func (f *fakeGosshConn) SessionID() []byte { return nil }
153-
func (f *fakeGosshConn) ClientVersion() []byte { return nil }
154-
func (f *fakeGosshConn) ServerVersion() []byte { return nil }
155-
func (f *fakeGosshConn) RemoteAddr() net.Addr { return &net.TCPAddr{} }
156-
func (f *fakeGosshConn) LocalAddr() net.Addr { return &net.TCPAddr{} }
157-
func (f *fakeGosshConn) SendRequest(_ string, _ bool, _ []byte) (bool, []byte, error) {
158-
return false, nil, nil
159-
}
160-
161-
func (f *fakeGosshConn) OpenChannel(_ string, _ []byte) (gossh.Channel, <-chan *gossh.Request, error) {
162-
return nil, nil, errors.New("not implemented")
163-
}
164-
165-
func (f *fakeGosshConn) Close() error { return nil }
166-
167-
// Wait blocks until the returned channel is closed — used by tests to
168-
// control when the "kill on disconnect" goroutine unblocks.
169-
func (f *fakeGosshConn) Wait() error {
170-
// Block until the test is done (goroutine is abandoned when the test
171-
// function returns; the Go runtime cleans it up). This is acceptable
172-
// because the caller only needs Wait to not panic.
173-
select {}
174-
}
175-
176146
// TestShell_StartPtyError verifies that Shell() returns an error and does NOT
177147
// panic when startPtyFn fails (e.g. "ptmx: inappropriate ioctl for device").
178148
// Before the fix the nil *os.File returned by the stub was dereferenced, causing

0 commit comments

Comments
 (0)