Skip to content

Commit

Permalink
remove read test
Browse files Browse the repository at this point in the history
Signed-off-by: nitishfy <[email protected]>
  • Loading branch information
nitishfy committed Dec 18, 2024
1 parent 1315a48 commit 89eb664
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 54 deletions.
4 changes: 2 additions & 2 deletions server/application/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (t *terminalSession) performValidationsAndReconnect(p []byte) (int, error)
return 0, nil
}

// Read called in a loop from remotecommand as long as the process is running
// Read called in a loop from remote command as long as the process is running
func (t *terminalSession) Read(p []byte) (int, error) {
code, err := t.performValidationsAndReconnect(p)
if err != nil {
Expand Down Expand Up @@ -223,7 +223,7 @@ func (t *terminalSession) Ping() error {
return err
}

// Write called from remotecommand whenever there is any output
// Write called from remote command whenever there is any output
func (t *terminalSession) Write(p []byte) (int, error) {
msg, err := json.Marshal(TerminalMessage{
Operation: "stdout",
Expand Down
52 changes: 0 additions & 52 deletions server/application/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,55 +212,3 @@ func TestTerminalSession_Write(t *testing.T) {

assert.Equal(t, expectedMessage, receivedMessage)
}

func TestTerminalSession_Read(t *testing.T) {
validate := func(w http.ResponseWriter, r *http.Request) {
ts := newTestTerminalSession(w, r)
ts.terminalOpts = &TerminalOptions{DisableAuth: true}
code, err := ts.performValidationsAndReconnect([]byte{})
assert.Equal(t, 0, code)
require.NoError(t, err)

testMessages := []TerminalMessage{
{
Operation: "stdin",
Data: "test input",
},
{
Operation: "resize",
Cols: 80,
Rows: 24,
},
{
Operation: "unknown",
},
}

for _, msg := range testMessages {
bytes, _ := json.Marshal(msg)
err := ts.wsConn.WriteMessage(websocket.TextMessage, bytes)
require.NoError(t, err)

p := make([]byte, 1024)
n, err := ts.Read(p)
require.NoError(t, err)

switch msg.Operation {
case "stdin":
assert.Equal(t, msg.Data, string(p[:n]))
case "resize":
select {
case size := <-ts.sizeChan:
assert.Equal(t, int(msg.Cols), size.Width)
assert.Equal(t, int(msg.Rows), size.Height)
default:
t.Error("expected size channel output but got none")
}
case "unknown":
assert.Equal(t, string(EndOfTransmission), string(p[:n]))
}
}
}

testServerConnection(t, validate, false)
}

0 comments on commit 89eb664

Please sign in to comment.