|
1 | 1 | package coderd_test
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| -"bufio" |
5 | 4 | "context"
|
6 |
| -"encoding/json" |
7 | 5 | "fmt"
|
8 | 6 | "net"
|
9 | 7 | "net/http"
|
@@ -446,88 +444,6 @@ func TestWorkspaceAgentTailnet(t *testing.T) {
|
446 | 444 | require.Equal(t,"test",strings.TrimSpace(string(output)))
|
447 | 445 | }
|
448 | 446 |
|
449 |
| -funcTestWorkspaceAgentPTY(t*testing.T) { |
450 |
| -t.Parallel() |
451 |
| -ifruntime.GOOS=="windows" { |
452 |
| -// This might be our implementation, or ConPTY itself. |
453 |
| -// It's difficult to find extensive tests for it, so |
454 |
| -// it seems like it could be either. |
455 |
| -t.Skip("ConPTY appears to be inconsistent on Windows.") |
456 |
| -} |
457 |
| -client:=coderdtest.New(t,&coderdtest.Options{ |
458 |
| -IncludeProvisionerDaemon:true, |
459 |
| -}) |
460 |
| -user:=coderdtest.CreateFirstUser(t,client) |
461 |
| -authToken:=uuid.NewString() |
462 |
| -version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{ |
463 |
| -Parse:echo.ParseComplete, |
464 |
| -ProvisionPlan:echo.ProvisionComplete, |
465 |
| -ProvisionApply:echo.ProvisionApplyWithAgent(authToken), |
466 |
| -}) |
467 |
| -template:=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID) |
468 |
| -coderdtest.AwaitTemplateVersionJob(t,client,version.ID) |
469 |
| -workspace:=coderdtest.CreateWorkspace(t,client,user.OrganizationID,template.ID) |
470 |
| -coderdtest.AwaitWorkspaceBuildJob(t,client,workspace.LatestBuild.ID) |
471 |
| - |
472 |
| -agentClient:=agentsdk.New(client.URL) |
473 |
| -agentClient.SetSessionToken(authToken) |
474 |
| -agentCloser:=agent.New(agent.Options{ |
475 |
| -Client:agentClient, |
476 |
| -Logger:slogtest.Make(t,nil).Named("agent").Leveled(slog.LevelDebug), |
477 |
| -}) |
478 |
| -deferfunc() { |
479 |
| -_=agentCloser.Close() |
480 |
| -}() |
481 |
| -resources:=coderdtest.AwaitWorkspaceAgents(t,client,workspace.ID) |
482 |
| -ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong) |
483 |
| -defercancel() |
484 |
| - |
485 |
| -conn,err:=client.WorkspaceAgentReconnectingPTY(ctx,resources[0].Agents[0].ID,uuid.New(),80,80,"/bin/bash") |
486 |
| -require.NoError(t,err) |
487 |
| -deferconn.Close() |
488 |
| - |
489 |
| -// First attempt to resize the TTY. |
490 |
| -// The websocket will close if it fails! |
491 |
| -data,err:=json.Marshal(codersdk.ReconnectingPTYRequest{ |
492 |
| -Height:250, |
493 |
| -Width:250, |
494 |
| -}) |
495 |
| -require.NoError(t,err) |
496 |
| -_,err=conn.Write(data) |
497 |
| -require.NoError(t,err) |
498 |
| -bufRead:=bufio.NewReader(conn) |
499 |
| - |
500 |
| -// Brief pause to reduce the likelihood that we send keystrokes while |
501 |
| -// the shell is simultaneously sending a prompt. |
502 |
| -time.Sleep(100*time.Millisecond) |
503 |
| - |
504 |
| -data,err=json.Marshal(codersdk.ReconnectingPTYRequest{ |
505 |
| -Data:"echo test\r\n", |
506 |
| -}) |
507 |
| -require.NoError(t,err) |
508 |
| -_,err=conn.Write(data) |
509 |
| -require.NoError(t,err) |
510 |
| - |
511 |
| -expectLine:=func(matcherfunc(string)bool) { |
512 |
| -for { |
513 |
| -line,err:=bufRead.ReadString('\n') |
514 |
| -require.NoError(t,err) |
515 |
| -ifmatcher(line) { |
516 |
| -break |
517 |
| -} |
518 |
| -} |
519 |
| -} |
520 |
| -matchEchoCommand:=func(linestring)bool { |
521 |
| -returnstrings.Contains(line,"echo test") |
522 |
| -} |
523 |
| -matchEchoOutput:=func(linestring)bool { |
524 |
| -returnstrings.Contains(line,"test")&&!strings.Contains(line,"echo") |
525 |
| -} |
526 |
| - |
527 |
| -expectLine(matchEchoCommand) |
528 |
| -expectLine(matchEchoOutput) |
529 |
| -} |
530 |
| - |
531 | 447 | funcTestWorkspaceAgentListeningPorts(t*testing.T) {
|
532 | 448 | t.Parallel()
|
533 | 449 |
|
|