MCPcopy Index your code
hub / github.com/coder/coder / TestSSH_Container

Function TestSSH_Container

cli/ssh_test.go:2037–2149  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2035}
2036
2037func TestSSH_Container(t *testing.T) {
2038 t.Parallel()
2039 if runtime.GOOS != "linux" {
2040 t.Skip("Skipping test on non-Linux platform")
2041 }
2042
2043 t.Run("OK", func(t *testing.T) {
2044 t.Parallel()
2045
2046 client, workspace, agentToken := setupWorkspaceForAgent(t)
2047 pool, err := dockertest.NewPool("")
2048 require.NoError(t, err, "Could not connect to docker")
2049 ct, err := pool.RunWithOptions(&dockertest.RunOptions{
2050 Repository: "busybox",
2051 Tag: "latest",
2052 Cmd: []string{"sleep", "infnity"},
2053 }, func(config *docker.HostConfig) {
2054 config.AutoRemove = true
2055 config.RestartPolicy = docker.RestartPolicy{Name: "no"}
2056 })
2057 require.NoError(t, err, "Could not start container")
2058 // Wait for container to start
2059 require.Eventually(t, func() bool {
2060 ct, ok := pool.ContainerByName(ct.Container.Name)
2061 return ok && ct.Container.State.Running
2062 }, testutil.WaitShort, testutil.IntervalSlow, "Container did not start in time")
2063 t.Cleanup(func() {
2064 err := pool.Purge(ct)
2065 require.NoError(t, err, "Could not stop container")
2066 })
2067
2068 _ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
2069 o.Devcontainers = true
2070 o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
2071 agentcontainers.WithProjectDiscovery(false),
2072 agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
2073 )
2074 })
2075 _ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
2076
2077 inv, root := clitest.New(t, "ssh", workspace.Name, "-c", ct.Container.ID)
2078 clitest.SetupConfig(t, client, root)
2079 ptty := ptytest.New(t).Attach(inv)
2080
2081 ctx := testutil.Context(t, testutil.WaitLong)
2082 cmdDone := tGo(t, func() {
2083 err := inv.WithContext(ctx).Run()
2084 assert.NoError(t, err)
2085 })
2086
2087 ptty.ExpectMatchContext(ctx, " #")
2088 ptty.WriteLine("hostname")
2089 ptty.ExpectMatchContext(ctx, ct.Container.Config.Hostname)
2090 ptty.WriteLine("exit")
2091 <-cmdDone
2092 })
2093
2094 t.Run("NotFound", func(t *testing.T) {

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
NewFunction · 0.92
WithProjectDiscoveryFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
NewFunction · 0.92
SetupConfigFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
NewMockContainerCLIFunction · 0.92
WithContainerCLIFunction · 0.92
tGoFunction · 0.85

Tested by

no test coverage detected