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

Function TestWorkspaceAgent_Metadata

coderd/workspaceagents_test.go:2287–2453  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2285}
2286
2287func TestWorkspaceAgent_Metadata(t *testing.T) {
2288 t.Parallel()
2289
2290 client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
2291 MetadataBatcherOptions: []metadatabatcher.Option{
2292 metadatabatcher.WithInterval(100 * time.Millisecond),
2293 },
2294 })
2295 user := coderdtest.CreateFirstUser(t, client)
2296 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
2297 OrganizationID: user.OrganizationID,
2298 OwnerID: user.UserID,
2299 }).WithAgent(func(agents []*proto.Agent) []*proto.Agent {
2300 agents[0].Metadata = []*proto.Agent_Metadata{
2301 {
2302 DisplayName: "First Meta",
2303 Key: "foo1",
2304 Script: "echo hi",
2305 Interval: 10,
2306 Timeout: 3,
2307 },
2308 {
2309 DisplayName: "Second Meta",
2310 Key: "foo2",
2311 Script: "echo howdy",
2312 Interval: 10,
2313 Timeout: 3,
2314 },
2315 {
2316 DisplayName: "TooLong",
2317 Key: "foo3",
2318 Script: "echo howdy",
2319 Interval: 10,
2320 Timeout: 3,
2321 },
2322 }
2323 return agents
2324 }).Do()
2325
2326 workspace, err := client.Workspace(context.Background(), r.Workspace.ID)
2327 require.NoError(t, err)
2328 for _, res := range workspace.LatestBuild.Resources {
2329 for _, a := range res.Agents {
2330 require.Equal(t, codersdk.WorkspaceAgentLifecycleCreated, a.LifecycleState)
2331 }
2332 }
2333
2334 agentClient := agentsdk.New(client.URL, agentsdk.WithFixedToken(r.AgentToken))
2335
2336 ctx := testutil.Context(t, testutil.WaitMedium)
2337 conn, err := agentClient.ConnectRPC(ctx)
2338 require.NoError(t, err)
2339 defer func() {
2340 cErr := conn.Close()
2341 require.NoError(t, cErr)
2342 }()
2343 aAPI := agentproto.NewDRPCAgentClient(conn)
2344

Callers

nothing calls this directly

Calls 15

BatchUpdateMetadataMethod · 0.95
NewWithDatabaseFunction · 0.92
WithIntervalFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
WithFixedTokenFunction · 0.92
ContextFunction · 0.92
ProtoFromMetadataResultFunction · 0.92
requireGetManifestFunction · 0.85
WithAgentMethod · 0.80
WorkspaceMethod · 0.80

Tested by

no test coverage detected