Skip to content

Commit

Permalink
Add tests for system.PipeReader/Writer.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Sep 15, 2024
1 parent 2113a67 commit 91efbbf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

var _ Policy = (*Terminal_login_Results)(nil)
var _ Terminal_Server = (*TerminalConfig)(nil)

type Policy interface {
NewStdio() (Socket, error)
Expand Down
24 changes: 24 additions & 0 deletions system/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 91efbbf

Please sign in to comment.