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

Function TestWorkspaceAgent

cli/agent_test.go:26–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestWorkspaceAgent(t *testing.T) {
27 t.Parallel()
28
29 t.Run("LogDirectory", func(t *testing.T) {
30 t.Parallel()
31
32 client, db := coderdtest.NewWithDatabase(t, nil)
33 user := coderdtest.CreateFirstUser(t, client)
34 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
35 OrganizationID: user.OrganizationID,
36 OwnerID: user.UserID,
37 }).
38 WithAgent().
39 Do()
40 logDir := t.TempDir()
41 inv, _ := clitest.New(t,
42 "agent",
43 "--auth", "token",
44 "--agent-token", r.AgentToken,
45 "--agent-url", client.URL.String(),
46 "--log-dir", logDir,
47 "--socket-path", testutil.AgentSocketPath(t),
48 )
49
50 clitest.Start(t, inv)
51
52 coderdtest.AwaitWorkspaceAgents(t, client, r.Workspace.ID)
53
54 require.Eventually(t, func() bool {
55 info, err := os.Stat(filepath.Join(logDir, "coder-agent.log"))
56 if err != nil {
57 return false
58 }
59 return info.Size() > 0
60 }, testutil.WaitLong, testutil.IntervalMedium)
61 })
62
63 t.Run("PostStartup", func(t *testing.T) {
64 t.Parallel()
65
66 client, db := coderdtest.NewWithDatabase(t, nil)
67 user := coderdtest.CreateFirstUser(t, client)
68 r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{
69 OrganizationID: user.OrganizationID,
70 OwnerID: user.UserID,
71 }).WithAgent().Do()
72
73 logDir := t.TempDir()
74 inv, _ := clitest.New(t,
75 "agent",
76 "--auth", "token",
77 "--agent-token", r.AgentToken,
78 "--agent-url", client.URL.String(),
79 "--log-dir", logDir,
80 "--socket-path", testutil.AgentSocketPath(t),
81 )
82 // Set the subsystems for the agent.
83 inv.Environ.Set(agent.EnvAgentSubsystem, fmt.Sprintf("%s,%s", codersdk.AgentSubsystemExectrace, codersdk.AgentSubsystemEnvbox))

Callers

nothing calls this directly

Calls 15

NewWithDatabaseFunction · 0.92
CreateFirstUserFunction · 0.92
WorkspaceBuildFunction · 0.92
NewFunction · 0.92
AgentSocketPathFunction · 0.92
StartFunction · 0.92
AwaitWorkspaceAgentsFunction · 0.92
NewWorkspaceAgentWaiterFunction · 0.92
DeploymentValuesFunction · 0.92
NewOptionsFunction · 0.92
NewFunction · 0.92
NewProvisionerDaemonFunction · 0.92

Tested by

no test coverage detected