From 91efbbfe396c8294e2d129813a99415e8e085660 Mon Sep 17 00:00:00 2001 From: Louis Thibault Date: Sun, 15 Sep 2024 17:43:20 -0400 Subject: [PATCH] Add tests for system.PipeReader/Writer. --- auth/auth.go | 1 - system/socket_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/auth/auth.go b/auth/auth.go index bb54f4b..d0c73f6 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -5,7 +5,6 @@ import ( ) var _ Policy = (*Terminal_login_Results)(nil) -var _ Terminal_Server = (*TerminalConfig)(nil) type Policy interface { NewStdio() (Socket, error) diff --git a/system/socket_test.go b/system/socket_test.go index 4910974..245cf18 100644 --- a/system/socket_test.go +++ b/system/socket_test.go @@ -12,6 +12,30 @@ import ( "github.com/wetware/go/system" ) +func TestPipeReader(t *testing.T) { + t.Parallel() + + buf := strings.NewReader("test") + pipe := system.NewReadPipe(buf) + r := system.Socket{}.Connect(context.TODO(), pipe) + b, err := io.ReadAll(r) + require.NoError(t, err) + require.Equal(t, "test", string(b)) +} + +func TestPipeWriter(t *testing.T) { + t.Parallel() + + buf := new(bytes.Buffer) + pipe := system.NewWritePipe(nopCloser{Writer: buf}) + wc := system.Socket{}.Bind(context.TODO(), pipe) + n, err := io.Copy(wc, strings.NewReader("test")) + require.NoError(t, err) + require.Equal(t, int64(len("test")), n) + require.Equal(t, "test", buf.String()) + require.NoError(t, wc.Close()) +} + func TestReadPipe(t *testing.T) { t.Parallel()