Skip to content

chore: convert workspaceagent HTTP API to agentapi #11280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'main' into dean/agent-api-http
  • Loading branch information
deansheather committed Jan 26, 2024
commit 7c926a38deffabcd6703dae68189f7b8af960788
32 changes: 17 additions & 15 deletions coderd/agentapi/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

Expand All @@ -20,8 +21,7 @@ func TestBatchUpdateAppHealths(t *testing.T) {
t.Parallel()

var (
workspaceID = uuid.New()
agent = database.WorkspaceAgent{
agent = database.WorkspaceAgent{
ID: uuid.New(),
}
app1 = database.WorkspaceApp{
Expand Down Expand Up @@ -57,6 +57,7 @@ func TestBatchUpdateAppHealths(t *testing.T) {
}).Return(nil)

publishCalled := false
workspaceID := uuid.New()
api := &agentapi.AppsAPI{
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
Expand All @@ -66,8 +67,9 @@ func TestBatchUpdateAppHealths(t *testing.T) {
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, id uuid.UUID) {
publishCalled = true
assert.Equal(t, workspaceID, id)
},
}

Expand Down Expand Up @@ -101,12 +103,12 @@ func TestBatchUpdateAppHealths(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishCalled = true
},
}
Expand Down Expand Up @@ -142,12 +144,12 @@ func TestBatchUpdateAppHealths(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishCalled = true
},
}
Expand Down Expand Up @@ -179,8 +181,8 @@ func TestBatchUpdateAppHealths(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
Expand Down Expand Up @@ -211,8 +213,8 @@ func TestBatchUpdateAppHealths(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
Expand Down Expand Up @@ -244,8 +246,8 @@ func TestBatchUpdateAppHealths(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
Expand Down
8 changes: 4 additions & 4 deletions coderd/agentapi/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestUpdateLifecycle(t *testing.T) {
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishCalled = true
},
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestUpdateLifecycle(t *testing.T) {
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishCalled = true
},
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestUpdateLifecycle(t *testing.T) {
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
atomic.AddInt64(&publishCalled, 1)
},
}
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestUpdateLifecycle(t *testing.T) {
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishCalled = true
},
}
Expand Down
43 changes: 22 additions & 21 deletions coderd/agentapi/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func TestBatchCreateLogs(t *testing.T) {
t.Parallel()

var (
workspaceID = uuid.New()
agent = database.WorkspaceAgent{
agent = database.WorkspaceAgent{
ID: uuid.New(),
}
logSource = database.WorkspaceAgentLogSource{
Expand All @@ -45,17 +44,19 @@ func TestBatchCreateLogs(t *testing.T) {
publishWorkspaceUpdateCalled := false
publishWorkspaceAgentLogsUpdateCalled := false
now := dbtime.Now()
workspaceID := uuid.New()
api := &agentapi.LogsAPI{
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, id uuid.UUID) {
publishWorkspaceUpdateCalled = true
assert.Equal(t, workspaceID, id)
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
publishWorkspaceAgentLogsUpdateCalled = true
Expand Down Expand Up @@ -155,12 +156,12 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agentWithLogs, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishWorkspaceUpdateCalled = true
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
Expand Down Expand Up @@ -205,12 +206,12 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return overflowedAgent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishWorkspaceUpdateCalled = true
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
Expand Down Expand Up @@ -238,8 +239,8 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
Expand Down Expand Up @@ -303,12 +304,12 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishWorkspaceUpdateCalled = true
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
Expand Down Expand Up @@ -349,12 +350,12 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishWorkspaceUpdateCalled = true
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
Expand Down Expand Up @@ -398,12 +399,12 @@ func TestBatchCreateLogs(t *testing.T) {
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
return agent, nil
},
WorkspaceIDFn: func(context.Context, *database.WorkspaceAgent) (uuid.UUID, error) {
return workspaceID, nil
WorkspaceIDFn: func(ctx context.Context, wa *database.WorkspaceAgent) (uuid.UUID, error) {
return uuid.New(), nil
},
Database: dbM,
Log: slogtest.Make(t, nil),
PublishWorkspaceUpdateFn: func(context.Context, uuid.UUID) {
PublishWorkspaceUpdateFn: func(_ context.Context, _ uuid.UUID) {
publishWorkspaceUpdateCalled = true
},
PublishWorkspaceAgentLogsUpdateFn: func(ctx context.Context, workspaceAgentID uuid.UUID, msg agentsdk.LogsNotifyMessage) {
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.