mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: Add vscodeipc
subcommand for VS Code Extension (#5326)
* Add extio * feat: Add `vscodeipc` subcommand for VS Code Extension This enables the VS Code extension to communicate with a Coder client. The extension will download the slim binary from `/bin/*` for the respective client architecture and OS, then execute `coder vscodeipc` for the connecting workspace. * Add authentication header, improve comments, and add tests for the CLI * Update cli/vscodeipc_test.go Co-authored-by: Mathias Fredriksson <mafredri@gmail.com> * Update cli/vscodeipc_test.go Co-authored-by: Mathias Fredriksson <mafredri@gmail.com> * Update cli/vscodeipc/vscodeipc_test.go Co-authored-by: Mathias Fredriksson <mafredri@gmail.com> * Fix requested changes * Fix IPC tests * Fix shell execution * Fix nix flake * Silence usage Co-authored-by: Mathias Fredriksson <mafredri@gmail.com>
This commit is contained in:
44
cli/vscodeipc_test.go
Normal file
44
cli/vscodeipc_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/cli/clitest"
|
||||
"github.com/coder/coder/testutil"
|
||||
)
|
||||
|
||||
func TestVSCodeIPC(t *testing.T) {
|
||||
t.Parallel()
|
||||
// Ensures the vscodeipc command outputs it's running port!
|
||||
// This signifies to the caller that it's ready to accept requests.
|
||||
t.Run("PortOutputs", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client, workspace, _ := setupWorkspaceForAgent(t, nil)
|
||||
cmd, _ := clitest.New(t, "vscodeipc", workspace.LatestBuild.Resources[0].Agents[0].ID.String(),
|
||||
"--token", client.SessionToken(), "--url", client.URL.String())
|
||||
rdr, wtr := io.Pipe()
|
||||
cmd.SetOut(wtr)
|
||||
ctx, cancelFunc := testutil.Context(t)
|
||||
defer cancelFunc()
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
err := cmd.ExecuteContext(ctx)
|
||||
done <- err
|
||||
}()
|
||||
|
||||
buf := make([]byte, 64)
|
||||
require.Eventually(t, func() bool {
|
||||
t.Log("Looking for address!")
|
||||
var err error
|
||||
_, err = rdr.Read(buf)
|
||||
return err == nil
|
||||
}, testutil.WaitMedium, testutil.IntervalFast)
|
||||
t.Logf("Address: %s\n", buf)
|
||||
|
||||
cancelFunc()
|
||||
<-done
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user