mirror of https://github.com/coder/coder.git
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/coder/coder/cli/clitest"
|
|
"github.com/coder/coder/coderd/coderdtest"
|
|
"github.com/coder/coder/provisioner/echo"
|
|
"github.com/coder/coder/pty/ptytest"
|
|
)
|
|
|
|
func TestShow(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("Exists", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
|
|
user := coderdtest.CreateFirstUser(t, client)
|
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
|
|
Parse: echo.ParseComplete,
|
|
ProvisionApply: provisionCompleteWithAgent,
|
|
ProvisionPlan: provisionCompleteWithAgent,
|
|
})
|
|
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
|
|
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
|
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
|
|
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
|
|
|
|
args := []string{
|
|
"show",
|
|
workspace.Name,
|
|
}
|
|
inv, root := clitest.New(t, args...)
|
|
clitest.SetupConfig(t, client, root)
|
|
doneChan := make(chan struct{})
|
|
pty := ptytest.New(t).Attach(inv)
|
|
go func() {
|
|
defer close(doneChan)
|
|
err := inv.Run()
|
|
assert.NoError(t, err)
|
|
}()
|
|
matches := []struct {
|
|
match string
|
|
write string
|
|
}{
|
|
{match: "compute.main"},
|
|
{match: "smith (linux, i386)"},
|
|
{match: "coder ssh " + workspace.Name},
|
|
}
|
|
for _, m := range matches {
|
|
pty.ExpectMatch(m.match)
|
|
if len(m.write) > 0 {
|
|
pty.WriteLine(m.write)
|
|
}
|
|
}
|
|
<-doneChan
|
|
})
|
|
}
|