Skip to content

Commit ca23abc

Browse files
authored
chore(cli): fix test flake in TestSSH_Container/NotFound (#16771)
If you hit the list containers endpoint with no containers running, the response is different. This uses a mock lister to ensure a consistent response from the agent endpoint.
1 parent 04c3396 commit ca23abc

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

cli/ssh_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ import (
2929
"github.com/spf13/afero"
3030
"github.com/stretchr/testify/assert"
3131
"github.com/stretchr/testify/require"
32+
"go.uber.org/mock/gomock"
3233
"golang.org/x/crypto/ssh"
3334
gosshagent "golang.org/x/crypto/ssh/agent"
3435
"golang.org/x/sync/errgroup"
3536
"golang.org/x/xerrors"
3637

3738
"github.com/coder/coder/v2/agent"
3839
"github.com/coder/coder/v2/agent/agentcontainers"
40+
"github.com/coder/coder/v2/agent/agentcontainers/acmock"
3941
"github.com/coder/coder/v2/agent/agentssh"
4042
"github.com/coder/coder/v2/agent/agenttest"
4143
agentproto "github.com/coder/coder/v2/agent/proto"
@@ -1986,13 +1988,26 @@ func TestSSH_Container(t *testing.T) {
19861988

19871989
ctx := testutil.Context(t, testutil.WaitShort)
19881990
client, workspace, agentToken := setupWorkspaceForAgent(t)
1991+
ctrl := gomock.NewController(t)
1992+
mLister := acmock.NewMockLister(ctrl)
19891993
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
19901994
o.ExperimentalDevcontainersEnabled = true
1991-
o.ContainerLister = agentcontainers.NewDocker(o.Execer)
1995+
o.ContainerLister = mLister
19921996
})
19931997
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
19941998

1995-
inv, root := clitest.New(t, "ssh", workspace.Name, "-c", uuid.NewString())
1999+
mLister.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
2000+
Containers: []codersdk.WorkspaceAgentDevcontainer{
2001+
{
2002+
ID: uuid.NewString(),
2003+
FriendlyName: "something_completely_different",
2004+
},
2005+
},
2006+
Warnings: nil,
2007+
}, nil)
2008+
2009+
cID := uuid.NewString()
2010+
inv, root := clitest.New(t, "ssh", workspace.Name, "-c", cID)
19962011
clitest.SetupConfig(t, client, root)
19972012
ptty := ptytest.New(t).Attach(inv)
19982013

@@ -2001,7 +2016,8 @@ func TestSSH_Container(t *testing.T) {
20012016
assert.NoError(t, err)
20022017
})
20032018

2004-
ptty.ExpectMatch("Container not found:")
2019+
ptty.ExpectMatch(fmt.Sprintf("Container not found: %q", cID))
2020+
ptty.ExpectMatch("Available containers: [something_completely_different]")
20052021
<-cmdDone
20062022
})
20072023

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy