fix: resolve TestAPI/Error/DuringInjection flake (#19407)

Resolves https://github.com/coder/internal/issues/905
This commit is contained in:
Danielle Maywood
2025-08-19 12:23:37 +01:00
committed by GitHub
parent c7cfa65961
commit e8795269e4
+4 -7
View File
@@ -2096,9 +2096,6 @@ func TestAPI(t *testing.T) {
}
)
coderBin, err := os.Executable()
require.NoError(t, err)
// Mock the `List` function to always return the test container.
mCCLI.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentContainer{testContainer},
@@ -2139,7 +2136,7 @@ func TestAPI(t *testing.T) {
require.Equal(t, http.StatusOK, rec.Code)
var response codersdk.WorkspaceAgentListContainersResponse
err = json.NewDecoder(rec.Body).Decode(&response)
err := json.NewDecoder(rec.Body).Decode(&response)
require.NoError(t, err)
// Then: We expect that there will be an error associated with the devcontainer.
@@ -2149,7 +2146,7 @@ func TestAPI(t *testing.T) {
gomock.InOrder(
mCCLI.EXPECT().DetectArchitecture(gomock.Any(), testContainer.ID).Return(runtime.GOARCH, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "mkdir", "-p", "/.coder-agent").Return(nil, nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, coderBin, "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().Copy(gomock.Any(), testContainer.ID, gomock.Any(), "/.coder-agent/coder").Return(nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "chmod", "0755", "/.coder-agent", "/.coder-agent/coder").Return(nil, nil),
mCCLI.EXPECT().ExecAs(gomock.Any(), testContainer.ID, "root", "/bin/sh", "-c", "chown $(id -u):$(id -g) /.coder-agent/coder").Return(nil, nil),
)
@@ -2157,8 +2154,8 @@ func TestAPI(t *testing.T) {
// Given: We allow creation to succeed.
testutil.RequireSend(ctx, t, fSAC.createErrC, nil)
_, aw := mClock.AdvanceNext()
aw.MustWait(ctx)
err = api.RefreshContainers(ctx)
require.NoError(t, err)
req = httptest.NewRequest(http.MethodGet, "/", nil)
rec = httptest.NewRecorder()